Arabic Word Net synonyms in Python?

2019-02-25 00:42发布

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

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

  1. line 320 is opts['i']='upc_db.xml' instead of

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

  2. I added that at the end wn.get_synsets_from_word(u"جَمِيل")

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

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>

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"جَمِيل")

I get :

`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.

1条回答
干净又极端
2楼-- · 2019-02-25 01:08

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()

Output will be:

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']]
查看更多
登录 后发表回答