【发布时间】:2020-06-09 16:28:22
【问题描述】:
我开始学习 wordnet,但示例中的所有内容都与特定单词相关联。如何使用 wordnet 获取多个句子中每个单词的定义?
我试图做这样的事情:
from nltk.corpus import wordnet
from nltk.tokenize import word_tokenize
words = []
synt = "My friends have come too late."
words = word_tokenize(synt)
for w in words:
word = wordnet.synsets('{w}')[0]
print("Synset name : ", word.name())
# Defining the word
print("\nSynset meaning : ", word.definition())
# list of phrases that use the word in context
print("\nSynset example : ", word.examples())
但是:
Traceback (most recent call last):
File "C:/projects/WordNet/test.py", line 10, in <module>
word = wordnet.synsets('{w}')[0]
IndexError: list index out of range
Process finished with exit code 1
【问题讨论】: