2

NLTK 允许我用 消除文本歧义nltk.wsd.lesk,例如

>>> from nltk.corpus import wordnet as wn
>>> from nltk.wsd import lesk
>>> sent = "I went to the bank to deposit money"
>>> ambiguous = "deposit"
>>> lesk(sent, ambiguous, pos='v')
Synset('deposit.v.02')

PyWSD做同样的事情,但它只适用于英文文本。


NLTK 支持来自Open Multilingual WordNet的阿拉伯语 wordnet ,例如

>>> wn.synsets('deposit', pos='v')[1].lemma_names(lang='arb')
[u'\u0623\u064e\u0648\u0652\u062f\u064e\u0639\u064e']
>>> print wn.synsets('deposit', pos='v')[1].lemma_names(lang='arb')[0]
أَوْدَعَ

此外,同义词集被索引为阿拉伯语:

>>> wn.synsets(u'أَوْدَعَ', lang='arb')
[Synset('entrust.v.02'), Synset('deposit.v.02'), Synset('commit.v.03'), Synset('entrust.v.01'), Synset('consign.v.02')]

但是我怎样才能消除阿拉伯语文本的歧义并使用 nltk 从查询中提取概念?

我想知道是否可以使用 Lesk 算法通过 nltk 处理阿拉伯文本?

4

1 回答 1

2

这有点棘手,但也许这会起作用:

  1. 翻译句子和歧义词
  2. 在英文版句子上使用 lesk

尝试:

alvas@ubi:~$ wget -O translate.sh http://pastebin.com/raw.php?i=aHgFzmMU
--2015-08-05 23:32:46--  http://pastebin.com/raw.php?i=aHgFzmMU
Resolving pastebin.com (pastebin.com)... 190.93.241.15, 190.93.240.15, 141.101.112.16, ...
Connecting to pastebin.com (pastebin.com)|190.93.241.15|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/plain]
Saving to: ‘translate.sh’

    [ <=>                                                                                                                            ] 212         --.-K/s   in 0s      

2015-08-05 23:32:47 (9.99 MB/s) - ‘translate.sh’ saved [212]

alvas@ubi:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import nltk
>>> from nltk.corpus import wordnet as wn
>>> text = 'لديه يودع المال في البنك'
>>> cmd = 'echo "{}" | bash translate.sh'.format(text)
>>> translation = os.popen(cmd).read()
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   193    0    40  100   153     21     83  0:00:01  0:00:01 --:--:--    83
>>> translation
'He has deposited the money in the bank. '
>>> ambiguous = u'أَوْدَعَ'
>>> wn.synsets(ambiguous, lang='arb')
[Synset('entrust.v.02'), Synset('deposit.v.02'), Synset('commit.v.03'), Synset('entrust.v.01'), Synset('consign.v.02')]
>>> nltk.wsd.lesk(translation_stems, '', synsets=wn.synsets(ambiguous,lang='arb'))
Synset('entrust.v.02')

但是正如你所看到的,有很多限制:

  • 访问 MT 系统并不总是那么容易(上面使用 IBM API 的 bash 脚本不会永远持续下去,它来自https://github.com/Rich-Edwards/fsharpwatson/blob/master/Command%20Line%20CURL% 20个脚本
  • 机器翻译永远不会 100% 准确
  • 在 Open Multilingual WordNet 中寻找正确的词条并不像示例中所示的那么容易,词干有屈折变化和其他词素变体。
  • WordNet 永远不会完整,尤其是当它不是英语的时候。
  • WSD 并非人类预期的 100%(即使在人类之间,我们的“感官”也会有所不同,在上面的示例中,有人可能会说 WSD 是正确的,有人说它更好用Synset('deposit.v.02')
于 2015-08-05T22:01:10.710 回答