3
Natural Language Toolkit(3.2.1)およびWordNetと共にPython(2.7)を使用しています。私は非常にプログラミングです。ユーザー入力文字列を正しいオブジェクト型に変換する方法
ユーザーに単語を尋ね、その単語の同義語セットを出力し、次にどの補語セットを表示するかを同義語セットに照会するプログラムを作成しようとしています。
raw_input
は文字列しか受け付けないので、ユーザー入力にメソッド.lemma_names()
を使用しようとすると、エラーAttributeError: 'str' object has no attribute 'lemma_names'
が返されます。ここで
はコードです:
from nltk.corpus import wordnet as wn
w1 = raw_input ("What is the word? ")
#This prints the synsets for w1, thus showing them what format to use in the next question.
for synset in wn.synsets(w1):
print synset
#This asks the user to choose the synset of w1 that interests them.
synset1 = raw_input ("Which sense are you looking for? [Use same format as above]")
#This prints the lemmas from the synset of interest.
for x in synset1.lemma_names():
print x
私の質問はどのように私は私が上.lemma_names()
メソッドを使用することができsynset型に文字列からユーザーの入力を変換します、ありますか?
この質問が話題にならないほど基本的であれば、私はお詫び申し上げます。もしそうなら、私に教えてください。
あなたが任意のより多くのコードを記述する前に、[PyCharm](https://www.jetbrains.com/pycharm/download/)をダウンロード。そのデバッガを使用します。 –