[OK]を私はより多くのグーグルでこれらのタグを取得する方法を見つけました。 まず、ファイルがトークン化されることを確認するために、いくつかの前処理をしなければなりません(私の場合は、pdfからtxtへの変換後に残されたものを削除することでした)。
これらのファイルは、文にトークン化され、次に各文が単語配列にトークン化され、nltkタグャーによってタグ付けされる必要があります。その字句化を行うことができ、その上にステミングを追加することができます。
from nltk.tokenize import sent_tokenize, word_tokenize
# use sent_tokenize to split text into sentences, and word_tokenize to
# to split sentences into words
from nltk.tag import pos_tag
# use this to generate array of tuples (word, tag)
# it can be then translated into wordnet tag as in
# [this response][1].
from nltk.stem.wordnet import WordNetLemmatizer
from stemming.porter2 import stem
# code from response mentioned above
def get_wordnet_pos(treebank_tag):
if treebank_tag.startswith('J'):
return wordnet.ADJ
elif treebank_tag.startswith('V'):
return wordnet.VERB
elif treebank_tag.startswith('N'):
return wordnet.NOUN
elif treebank_tag.startswith('R'):
return wordnet.ADV
else:
return ''
with open(myInput, 'r') as f:
data = f.read()
sentences = sent_tokenize(data)
ignoreTypes = ['TO', 'CD', '.', 'LS', ''] # my choice
lmtzr = WordNetLemmatizer()
for sent in sentences:
words = word_tokenize(sentence)
tags = pos_tag(words)
for (word, type) in tags:
if type in ignoreTypes:
continue
tag = get_wordnet_pos(type)
if tag == '':
continue
lema = lmtzr.lemmatize(word, tag)
stemW = stem(lema)
そして私は、私は、ファイルへの書き込み、およびドキュメントあたりTFIDFベクトルをカウントするためにこれらを使用することができます単語stemW
を食い止めます。この時点で
。