Python中的阿拉伯语Word Net同义词? [英] Arabic Word Net synonyms in Python?

查看:16
本文介绍了Python中的阿拉伯语Word Net同义词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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:

  1. AWNDatabaseManagement.py
  2. upc_db.xml

基于这个答案,我在 AWNDatabaseManagement.py 中做了一些

Based on this answer, I made few edits in AWNDatabaseManagement.py:

  1. 第 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 行添加了:# -*- coding: utf-8 -*-

I added that at line 2: # -*- coding: utf-8 -*-

然后我使用:$ python AWNDatabaseManagement.py -i upc_db.xml 运行它并且没有发现错误:<open file 'upc_db.xml', mode 'r' at0x10156c270>

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.pyupc_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆