我对python相当陌生,请多多包涵。我正在尝试创建一个代码来识别荷兰语句子中的难词并列出它们。为此,我需要知道输入中的荷兰语单词是否有任何上位词。下载 Open Multilingual Wordnet 时,无法通过 导入from nltk.corpus import omw as omw
,不知道是什么原因。我应该使用nltk."some other module?"
吗?我尝试使用常规 Wordnet,并lang='nld'
在代码的不同部分应用,但这不起作用。也许还有其他不正确的地方?任何帮助表示赞赏。
import nltk
nltk.download('punkt')
nltk.download('wordnet')
nltk.download('omw')
from nltk.corpus import wordnet as wn
#from nltk.corpus import omw as omw
input1 = input("Input difficult text: ").lower()
words = nltk.word_tokenize(input1)
word_list = [i
for i in words
if i.isalnum()
]
#find hypernyms for words and append in list
l = []
for x in word_list:
hyper = (wn.synset(x).hypernyms(lang='nld'))
l.append(hyper[0].hypernyms() if len(hyper)> 0 else '')
colab 上的错误消息如下:(我认为这是因为我移至lang='nld'
,hypernyms()
而不是wn.synset(x, lang='nld')
,虽然。即值错误不是主要问题。)
ValueError Traceback (most recent call last)
<ipython-input-29-92fedaeb123b> in <module>()
43 l = []
44 for x in word_list:
---> 45 hyper = (wn.synset(x).hypernyms(lang='nld'))
46 l.append(hyper[0].hypernyms() if len(hyper)> 0 else '')
47
/usr/local/lib/python3.7/dist-packages/nltk/corpus/reader/wordnet.py in synset(self, name)
1288 def synset(self, name):
1289 # split name into lemma, part of speech and synset number
-> 1290 lemma, pos, synset_index_str = name.lower().rsplit('.', 2)
1291 synset_index = int(synset_index_str) - 1
1292
ValueError: not enough values to unpack (expected 3, got 1)```