Based on this answer, I made few edits in AWNDatabaseManagement.py: 第320行是 opts ['i'] ='upc_db.xml'而不是 opts ['i'] ='E:/usuaris/horacio/arabicWN/AWNdatabase/upc_db.xml'opts['i']='E:/usuaris/horacio/arabicWN/AWNdatabase/upc_db.xml'我在末尾添加了 wn.get_synsets_from_word(u"جَمِيل") 我在第2行添加了代码:#-*-编码:utf-8-*- I added that at line 2: # -*- coding: utf-8 -*-然后我使用以下命令运行它: $ python AWNDatabaseManagement.py -i upc_db.xml ,未发现错误:<打开文件'upc_db.xml',模式为'r'0x10156c270> Then I ran it using: $ python AWNDatabaseManagement.py -i upc_db.xml and no errors were found: <open file 'upc_db.xml', mode 'r' at 0x10156c270> 但是当我运行原始的py文件时:Yet when I run my original py file:from nltk.corpus import wordnet as wnjan = wn.synsets('wait')[0]print(jan) #this works fineprint(jan.lemma_names(lang='arb')) #this works finewn.get_synsets_from_word(u"جَمِيل")我明白了:`Synset('delay.n.01') [u'\u0627\u0650\u0646\u0652\u062a\u0650\u0638\u0627\u0631', u'\u062a\u0623\u062c\u0650\u064a\u0644', u'\u062a\u0623\u062e\u0650\u064a\u0631', u'\u062a\u0648\u0642\u0651\u064f\u0641'] Traceback (most recent call last): File "C:/Users/PycharmProjects20Dec.py" line 492, in <module> wn.get_synsets_from_word("جَمِيل") AttributeError: 'WordNetCorpusReader' object has no attribute 'get_synsets_from_word`我真的不知道出了什么问题.I really don't know what is the problem.推荐答案阿拉伯语Wordnet的工作独立于nltk.在具有 AWNDatabaseManagement.py 和 upc_db.xml 的文件夹中,放置脚本并将其更改为:Arabic Wordnet works independent of nltk. In the folder where you have AWNDatabaseManagement.py and upc_db.xml, put your script and change it to:from AWNDatabaseManagement import wnsynsets = wn.get_synsetids_from_word(u"جَمِيل")for s in synsets: wn._items[s].describe()输出将是:itemid jamiyl_a1ARoffset 300218842name جَمِيلtype synsetpos ainput links [[u'be_in_state', u'jamaAl_n1AR'], [u'near_antonym', u'qabiyH_a1AR']]output links [[u'near_antonym', u'qabiyH_a1AR']] 这篇关于Python中的阿拉伯语Word Net同义词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-01 22:02