1
NLTKでのトークン化を使用して簡単な言い換えをしようとしています。以下の機能行うPythonでのNLTKアプローチを使用した言い換え
:最後の行を行った後
from nltk.tokenize import word_tokenize
from nltk.tag import pos_tag
from nltk.corpus import wordnet as wn
def tag(sentence):
words = word_tokenize(sentence)
words = pos_tag(words)
return words
def paraphraseable(tag):
return tag.startswith('NN') or tag == 'VB' or tag.startswith('JJ')
def pos(tag):
if tag.startswith('NN'):
return wn.NOUN
elif tag.startswith('V'):
return wn.VERB
def synonyms(word, tag):
return set([lemma.name for lemma in sum([ss.lemmas for ss in wn.synsets(word, pos(tag))],[])])
def synonymIfExists(sentence):
for (word, t) in tag(sentence):
if paraphraseable(t):
syns = synonyms(word, t)
if syns:
if len(syns) > 1:
yield [word, list(syns)]
continue
yield [word, []]
def paraphrase(sentence):
return [x for x in synonymIfExists(sentence)]
paraphrase("The quick brown fox jumps over the lazy dog")
を(言い換え(「速い茶色のキツネは、のろまなイヌに飛びかかった」))それはちょうどそのように私にエラーを与える:
缶リストのみを連結する(メソッドではない)
この場合、どう思われますか?
エラーがトリガされた場所を示す完全なスタックトレースを含めると、質問に答えるほうがはるかに簡単です。 – alexis
同義語の存在を修正しました – HalfPintBoy