Если вы собираетесь использовать WordNet, у вас есть
Проблема 1. Устранение неоднозначности словесного смысла (WSD), т. е. как автоматически определить, какой синсет использовать?
>>> for i in wn.synsets('good','a'):
... print i.name, i.definition
...
good.a.01 having desirable or positive qualities especially those suitable for a thing specified
full.s.06 having the normally expected amount
good.a.03 morally admirable
estimable.s.02 deserving of esteem and respect
beneficial.s.01 promoting or enhancing well-being
good.s.06 agreeable or pleasing
good.s.07 of moral excellence
adept.s.01 having or showing knowledge and skill and aptitude
good.s.09 thorough
dear.s.02 with or in a close or intimate relationship
dependable.s.04 financially sound
good.s.12 most suitable or right for a particular purpose
good.s.13 resulting favorably
effective.s.04 exerting force or influence
good.s.15 capable of pleasing
good.s.16 appealing to the mind
good.s.17 in excellent physical condition
good.s.18 tending to promote physical well-being; beneficial to health
good.s.19 not forged
good.s.20 not left to spoil
good.s.21 generally admired
>>> for i in wn.synsets('great','a'):
... print i.name, i.definition
...
great.s.01 relatively large in size or number or extent; larger than others of its kind
great.s.02 of major significance or importance
great.s.03 remarkable or out of the ordinary in degree or magnitude or effect
bang-up.s.01 very good
capital.s.03 uppercase
big.s.13 in an advanced stage of pregnancy
Допустим, вы каким-то образом уловили правильный смысл, возможно, вы пробовали что-то вроде этого (https://github.com/alvations/pywsd), и допустим, вы правильно поняли POS и synset:
товар.a.01, обладающий желательными или положительными качествами, особенно те, которые подходят для определенной вещи, большой.s.01 относительно большой по размеру, количеству или размеру; больше, чем другие в своем роде
Проблема 2. Как вы собираетесь сравнивать два синсета?
Давайте попробуем функции подобия, но вы поняли, что они не дают вам очков:
>>> good = wn.synsets('good','a')[0]
>>> great = wn.synsets('great','a')[0]
>>> print max(wn.path_similarity(good,great), wn.path_similarity(great, good))
None
>>> print max(wn.wup_similarity(good,great), wn.wup_similarity(great, good))
>>> print max(wn.res_similarity(good,great,semcor_ic), wn.res_similarity(great, good,semcor_ic))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/wordnet.py", line 1312, in res_similarity
return synset1.res_similarity(synset2, ic, verbose)
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/wordnet.py", line 738, in res_similarity
ic1, ic2, lcs_ic = _lcs_ic(self, other, ic)
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/wordnet.py", line 1643, in _lcs_ic
(synset1, synset2))
nltk.corpus.reader.wordnet.WordNetError: Computing the least common subsumer requires Synset('good.a.01') and Synset('great.s.01') to have the same part of speech.
>>> print max(wn.jcn_similarity(good,great,semcor_ic), wn.jcn_similarity(great, good,semcor_ic))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/wordnet.py", line 1316, in jcn_similarity
return synset1.jcn_similarity(synset2, ic, verbose)
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/wordnet.py", line 759, in jcn_similarity
ic1, ic2, lcs_ic = _lcs_ic(self, other, ic)
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/wordnet.py", line 1643, in _lcs_ic
(synset1, synset2))
nltk.corpus.reader.wordnet.WordNetError: Computing the least common subsumer requires Synset('good.a.01') and Synset('great.s.01') to have the same part of speech.
>>> print max(wn.lin_similarity(good,great,semcor_ic), wn.lin_similarity(great, good,semcor_ic))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/wordnet.py", line 1320, in lin_similarity
return synset1.lin_similarity(synset2, ic, verbose)
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/wordnet.py", line 789, in lin_similarity
ic1, ic2, lcs_ic = _lcs_ic(self, other, ic)
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/wordnet.py", line 1643, in _lcs_ic
(synset1, synset2))
nltk.corpus.reader.wordnet.WordNetError: Computing the least common subsumer requires Synset('good.a.01') and Synset('great.s.01') to have the same part of speech.
>>> print max(wn.lch_similarity(good,great), wn.lch_similarity(great, good))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/wordnet.py", line 1304, in lch_similarity
return synset1.lch_similarity(synset2, verbose, simulate_root)
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/wordnet.py", line 638, in lch_similarity
(self, other))
nltk.corpus.reader.wordnet.WordNetError: Computing the lch similarity requires Synset('good.a.01') and Synset('great.s.01') to have the same part of speech.
Давайте попробуем другую пару синсетов, так как у good
есть и satellite-adjective
, и adjective
, а у great
есть только satellite
, давайте пойдем с наименьшим общим знаменателем:
good.s.13 resulting favorably
great.s.01 relatively large in size or number or extent; larger than others of its kind
Вы понимаете, что до сих пор нет информации о сходстве для сравнения между satellite-adjective
:
>>> print max(wn.lin_similarity(good,great,semcor_ic), wn.lin_similarity(great, good,semcor_ic))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/wordnet.py", line 1320, in lin_similarity
return synset1.lin_similarity(synset2, ic, verbose)
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/wordnet.py", line 789, in lin_similarity
ic1, ic2, lcs_ic = _lcs_ic(self, other, ic)
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/wordnet.py", line 1645, in _lcs_ic
ic1 = information_content(synset1, ic)
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/wordnet.py", line 1666, in information_content
raise WordNetError(msg % synset.pos)
nltk.corpus.reader.wordnet.WordNetError: Information content file has no entries for part-of-speech: s
>>> print max(wn.path_similarity(good,great), wn.path_similarity(great, good))None
None
Теперь кажется, что WordNet создает больше проблем, чем решает что-либо здесь, давайте попробуем другое средство, давайте попробуем кластеризацию слов, см. http://en.wikipedia.org/wiki/Word-sense_induction
Это когда я также отказываюсь отвечать на широкий и открытый вопрос, который опубликовал ОП, потому что в кластеризации сделано МНОГО, что является автоматической магией для простых смертных, таких как я =)
person
alvas
schedule
07.01.2014
['great service', 'good product', 'great price']
, Тема 2 —['good service', 'quality product', 'good price']
. Ни один человек не назвал бы их двумя отдельными темами, и это бесполезно, когда есть другие темы, которые можно было бы рассмотреть. Иgood product
, иgreat product
описывают продукт в положительном ключе, и вы можете увидеть, насколько они больше похожи, скажем, наeasy reference
. - person user2979931   schedule 06.01.2014