如何使用荷兰语 Wordnet?打开多语言 Wordnet 不起作用?
我对 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')< /code> ,但值错误不是主要问题。)
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)```
I'm fairly new to python, please bear with me.
I am trying to create a code that identifies the difficult words in a Dutch sentence and lists them. For this, I need to know if the Dutch words in the input have any hypernyms.
When I download Open Multilingual Wordnet, it cannot be imported through from nltk.corpus import omw as omw
, not sure why. Should I use nltk."some other module?"
?
I have tried using regular Wordnet instead, and applying lang='nld'
in different parts of the code, but this does not work.
Maybe something else is incorrect? Any help is appreciated.
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 '')
The error message is as follows on colab:
(I think this is because I moved lang='nld'
to hypernyms()
, instead of wn.synset(x, lang='nld')
, though. I.e. the value error is not the main problem.)
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)```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论