<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def extract_pdf(fpath):
 """ Extracts structured text content from a PDF at ``fpath``. Parameters fpath : str Path to the PDF. Returns ------- :class:`.StructuredFeature` A :class:`.StructuredFeature` that contains page and sentence contexts. """


    with codecs.open(fpath, 'r') as f:  # Determine the encoding of the file.
        document = slate.PDF(f)
    encoding = chardet.detect(document[0])

    tokens = []
    pages = []
    sentences = []

    tokenizer = nltk.tokenize.TextTilingTokenizer()

    i = 0
    for page in document:
        pages.append(i)

        # Decode using the correct encoding.
        page = page.decode(encoding['encoding'])
        for sentence in nltk.tokenize.sent_tokenize(page):
            sentences.append(i)

            for word in nltk.tokenize.word_tokenize(sentence):
                if len(word) > 15:
                    words = nltk.tokenize.word_tokenize(_infer_spaces(word))
                    if mean([len(w) for w in words]) > 2:
                        for w in words:
                            tokens.append(w)
                            i += 1
                        continue

                tokens.append(word)
                i += 1

    contexts = [('page', pages), ('sentence', sentences)]
    return StructuredFeature(tokens, contexts)