Ако ще използвате 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 притежаващ желани или положителни качества, особено тези, които са подходящи за определено нещо great.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
Това е моментът, в който също се отказвам да отговоря на широкия и отворен въпрос, който OP е публикувал, защото има МНОГО направено в клъстерирането, което е автоматична магия за обикновените смъртни като мен =)
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