在python中导入阿拉伯语Wordnet



我需要使用python对阿拉伯单词执行函数。。我需要将阿拉伯语wordnet与python链接起来,以完成一些方法,如:

wn.synset('جميل')

我找到多语言词典:AWN-ArabicWN

http://www.talp.upc.edu/index.php/technology/resources/multilingual-lexicons-and-machine-translation-resources/multilingual-lexicons/72-awn

我试着跑:用于访问数据库的一组基本python函数

http://nlp.lsi.upc.edu/awn/AWNDatabaseManagement.py.gz

但是当运行代码(AWNDatabaseManagement.py)时出现此错误:

processing file  E:/usuaris/horacio/arabicWN/AWNdatabase/upc_db.xml
file  E:/usuaris/horacio/arabicWN/AWNdatabase/upc_db.xml  not correct
Traceback (most recent call last):
  File "/Users/s/Desktop/arab", line 403, in <module>
    wn.compute_index_w()
NameError: global name 'wn' is not defined 

知道吗?

AWNDatabaseManagement.py应由参数-i提供,该参数以阿拉伯语WordNet为值。如果未指定参数,它将使用默认路径E:/usuaris/horacio/arabicWN/AWNdatabase/upc_db.xml

为此,下载了阿拉伯语WordNet upc_db.xml的xml数据库。我建议将它与脚本AWNDatabaseManagement.py放在同一个文件夹中。然后,运行:

$ python AWNDatabaseManagement.py -i upc_db.xml

这就是我运行后得到的,没有错误:

processing file  upc_db.xml
<open file 'upc_db.xml', mode 'r' at 0xb74689c0>

您也可以更改线路320

opts['i']='E:/usuaris/horacio/arabicWN/AWNdatabase/upc_db.xml'

opts['i']='upc_db.xml'

然后在没有-i 的情况下运行脚本

你可以加载它:

>> from AWNDatabaseManagement import wn

如果失败,请检查是否将xml资源放在正确的路径中。


现在来获取类似wn.synset('جميل')的内容。阿拉伯语Wordnet有一个函数wn.get_synsets_from_word(word),但它给出了偏移量。此外,它只接受数据库中发音的单词。例如,您应该使用جَمِيل而不是جميل:

>> wn.get_synsets_from_word(u"جَمِيل")
[(u'a', u'300218842')]

300218842是جميل的同义集的偏移量。我建议改用下一种方法。单词列表依据:

 >> for word,ids  in sorted(wn.get_words(False)):
 ..     print word, ids 

你会得到这样的结果:

 جَمِيعَة [u'jamiyEap_1']
 جَمِيل [u'jamiyl_1']
 جَمِيْعَة [u'jamiyoEap_1']
 جَمَّدَ [u'jam~ada_2', u'jam~ada_1']

选择你的单词,并从其id中选择一个id。身份证是用巴克沃特罗马拼音写的。许多id表示这个词有不同的含义。通过以下方式描述所选单词:

>> wn._words["jamiyl_1"].describe()
wordid  jamiyl_1
value  جَمِيل
synsets  [u'jamiyl_a1AR']
forms  [(u'root', u'u062cu0645u0644')]

现在您有了synsets列表。有关synset的更多信息,请使用:

>> wn._items["jamiyl_a1AR"].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']]

最新更新