Python中的阿拉伯语Word Net同义词? [英] Arabic Word Net synonyms in Python?
问题描述
我正在使用python 2.7,我正在尝试使用阿拉伯语WordNet获得阿拉伯语单词的同义词
I am using python 2.7, I am trying to get synonyms of Arabic words using Arabic WordNet
我下载了两个所需文件:
I downloaded both needed files:
基于此答案,我在AWNDatabaseManagement.py中进行了少量 >
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 wn
jan = wn.synsets('wait')[0]
print(jan) #this works fine
print(jan.lemma_names(lang='arb')) #this works fine
wn.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 wn
synsets = wn.get_synsetids_from_word(u"جَمِيل")
for s in synsets:
wn._items[s].describe()
输出将是:
itemid jamiyl_a1AR
offset 300218842
name جَمِيل
type synset
pos a
input 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同义词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!