12

我正在寻找一种方法来使用 wordnet 查找特定单词的所有同义词。我正在使用 JAWS。

例如:

爱(v):钦佩,崇拜,依恋,着迷,着迷,迷恋,着迷,着迷,喜欢,爱上,经典化,关心,珍惜,选择,神化,喜悦,宠爱,尊重,崇高,堕落,幻想,荣耀,追求,继续......

爱(n): 同义词:崇拜,感情,忠诚,友好,多情,爱慕,欣赏,热情,热情,依恋,案例*,珍惜,迷恋,喜悦,忠诚,奉献,情感,魅力,享受,热情,忠诚,火焰, 喜爱, 友谊, 渴望, 偶像崇拜, 倾向, 痴情, 参与

在一个相关的问题中,用户 Ram 指出了一些代码,但这还不够,因为它只是给出了截然不同的输出:

爱,激情:任何温暖的感情或奉献的对象 亲爱的,亲爱的,最亲爱的,亲爱的,爱:一个心爱的人;用作爱恋、性的爱、情色的爱:对性欲和吸引力的深切感觉 爱:网球或壁球中得分为零 性爱、做爱、做爱、爱、爱情生活:性活动(通常包括intercourse) 两个人之间的爱:非常喜爱或喜欢

那么我如何实现它并且 wordnet 是否适合我想要做的事情?

4

4 回答 4

12

仅使用 WordNet,您可以尝试使用语义相似性来确定两个单词(同义词集)是否足够相似以成为同义词。下面是一个简单的例子,它来自使用 WordNet 修改我关于语义相似性的另一个答案。

但它确实有它的问题:

  • 反义词与同义词混在一起
  • 它很!(因为它必须检查所有 ~117k 同义词集)

尽管如此,它比单独使用产生更多的同义词lemma_names,所以我把它留在这里以防它可能有用(可能与其他东西结合使用)。

>>> from nltk.corpus import wordnet as wn
>>> def syn(word, lch_threshold=2.26):
    for net1 in wn.synsets(word):
        for net2 in wn.all_synsets():
            try:
                lch = net1.lch_similarity(net2)
            except:
                continue
            # The value to compare the LCH to was found empirically.
            # (The value is very application dependent. Experiment!)
            if lch >= lch_threshold:
                yield (net1, net2, lch)


>>> for x in syn('love'):
    print x

上面的代码输出:

(Synset('love.n.01'), Synset('feeling.n.01'), 2.538973871058276)
(Synset('love.n.01'), Synset('conditioned_emotional_response.n.01'), 2.538973871058276)
(Synset('love.n.01'), Synset('emotion.n.01'), 2.9444389791664407)
(Synset('love.n.01'), Synset('worship.n.02'), 2.9444389791664407)
(Synset('love.n.01'), Synset('anger.n.01'), 2.538973871058276)
(Synset('love.n.01'), Synset('fear.n.01'), 2.538973871058276)
(Synset('love.n.01'), Synset('fear.n.03'), 2.538973871058276)
(Synset('love.n.01'), Synset('anxiety.n.02'), 2.538973871058276)
(Synset('love.n.01'), Synset('joy.n.01'), 2.538973871058276)
(Synset('love.n.01'), Synset('love.n.01'), 3.6375861597263857)
(Synset('love.n.01'), Synset('agape.n.02'), 2.9444389791664407)
(Synset('love.n.01'), Synset('agape.n.01'), 2.9444389791664407)
(Synset('love.n.01'), Synset('filial_love.n.01'), 2.9444389791664407)
(Synset('love.n.01'), Synset('ardor.n.02'), 2.9444389791664407)
(Synset('love.n.01'), Synset('amorousness.n.01'), 2.9444389791664407)
(Synset('love.n.01'), Synset('puppy_love.n.01'), 2.9444389791664407)
(Synset('love.n.01'), Synset('devotion.n.01'), 2.9444389791664407)
(Synset('love.n.01'), Synset('benevolence.n.01'), 2.9444389791664407)
(Synset('love.n.01'), Synset('beneficence.n.01'), 2.538973871058276)
(Synset('love.n.01'), Synset('heartstrings.n.01'), 2.9444389791664407)
(Synset('love.n.01'), Synset('lovingness.n.01'), 2.9444389791664407)
(Synset('love.n.01'), Synset('warmheartedness.n.01'), 2.538973871058276)
(Synset('love.n.01'), Synset('loyalty.n.02'), 2.9444389791664407)
(Synset('love.n.01'), Synset('hate.n.01'), 2.538973871058276)
(Synset('love.n.01'), Synset('emotional_state.n.01'), 2.538973871058276)
(Synset('love.n.02'), Synset('content.n.05'), 2.538973871058276)
(Synset('love.n.02'), Synset('object.n.04'), 2.9444389791664407)
(Synset('love.n.02'), Synset('antipathy.n.02'), 2.538973871058276)
(Synset('love.n.02'), Synset('bugbear.n.02'), 2.538973871058276)
(Synset('love.n.02'), Synset('execration.n.03'), 2.538973871058276)
(Synset('love.n.02'), Synset('center.n.06'), 2.538973871058276)
(Synset('love.n.02'), Synset('hallucination.n.03'), 2.538973871058276)
(Synset('love.n.02'), Synset('infatuation.n.03'), 2.538973871058276)
(Synset('love.n.02'), Synset('love.n.02'), 3.6375861597263857)
(Synset('beloved.n.01'), Synset('person.n.01'), 2.538973871058276)
(Synset('beloved.n.01'), Synset('lover.n.01'), 2.9444389791664407)
(Synset('beloved.n.01'), Synset('admirer.n.03'), 2.538973871058276)
(Synset('beloved.n.01'), Synset('beloved.n.01'), 3.6375861597263857)
(Synset('beloved.n.01'), Synset('betrothed.n.01'), 2.538973871058276)
(Synset('beloved.n.01'), Synset('boyfriend.n.01'), 2.538973871058276)
(Synset('beloved.n.01'), Synset('darling.n.01'), 2.538973871058276)
(Synset('beloved.n.01'), Synset('girlfriend.n.02'), 2.538973871058276)
(Synset('beloved.n.01'), Synset('idolizer.n.01'), 2.538973871058276)
(Synset('beloved.n.01'), Synset('inamorata.n.01'), 2.538973871058276)
(Synset('beloved.n.01'), Synset('inamorato.n.01'), 2.538973871058276)
(Synset('beloved.n.01'), Synset('kisser.n.01'), 2.538973871058276)
(Synset('beloved.n.01'), Synset('necker.n.01'), 2.538973871058276)
(Synset('beloved.n.01'), Synset('petter.n.01'), 2.538973871058276)
(Synset('beloved.n.01'), Synset('romeo.n.01'), 2.538973871058276)
(Synset('beloved.n.01'), Synset('soul_mate.n.01'), 2.538973871058276)
(Synset('beloved.n.01'), Synset('squeeze.n.04'), 2.538973871058276)
(Synset('beloved.n.01'), Synset('sweetheart.n.01'), 2.538973871058276)
(Synset('love.n.04'), Synset('desire.n.01'), 2.538973871058276)
(Synset('love.n.04'), Synset('sexual_desire.n.01'), 2.9444389791664407)
(Synset('love.n.04'), Synset('love.n.04'), 3.6375861597263857)
(Synset('love.n.04'), Synset('aphrodisia.n.01'), 2.538973871058276)
(Synset('love.n.04'), Synset('anaphrodisia.n.01'), 2.538973871058276)
(Synset('love.n.04'), Synset('passion.n.05'), 2.538973871058276)
(Synset('love.n.04'), Synset('sensuality.n.01'), 2.538973871058276)
(Synset('love.n.04'), Synset('amorousness.n.02'), 2.538973871058276)
(Synset('love.n.04'), Synset('fetish.n.01'), 2.538973871058276)
(Synset('love.n.04'), Synset('libido.n.01'), 2.538973871058276)
(Synset('love.n.04'), Synset('lecherousness.n.01'), 2.538973871058276)
(Synset('love.n.04'), Synset('nymphomania.n.01'), 2.538973871058276)
(Synset('love.n.04'), Synset('satyriasis.n.01'), 2.538973871058276)
(Synset('love.n.04'), Synset('the_hots.n.01'), 2.538973871058276)
(Synset('love.n.05'), Synset('bowling_score.n.01'), 2.538973871058276)
(Synset('love.n.05'), Synset('football_score.n.01'), 2.538973871058276)
(Synset('love.n.05'), Synset('baseball_score.n.01'), 2.538973871058276)
(Synset('love.n.05'), Synset('basketball_score.n.01'), 2.538973871058276)
(Synset('love.n.05'), Synset('number.n.02'), 2.538973871058276)
(Synset('love.n.05'), Synset('score.n.03'), 2.9444389791664407)
(Synset('love.n.05'), Synset('stroke.n.06'), 2.538973871058276)
(Synset('love.n.05'), Synset('birdie.n.01'), 2.538973871058276)
(Synset('love.n.05'), Synset('bogey.n.02'), 2.538973871058276)
(Synset('love.n.05'), Synset('deficit.n.03'), 2.538973871058276)
(Synset('love.n.05'), Synset('double-bogey.n.01'), 2.538973871058276)
(Synset('love.n.05'), Synset('duck.n.02'), 2.538973871058276)
(Synset('love.n.05'), Synset('eagle.n.02'), 2.538973871058276)
(Synset('love.n.05'), Synset('double_eagle.n.01'), 2.538973871058276)
(Synset('love.n.05'), Synset('game.n.06'), 2.538973871058276)
(Synset('love.n.05'), Synset('lead.n.07'), 2.538973871058276)
(Synset('love.n.05'), Synset('love.n.05'), 3.6375861597263857)
(Synset('love.n.05'), Synset('match.n.05'), 2.538973871058276)
(Synset('love.n.05'), Synset('par.n.01'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('bondage.n.03'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('outercourse.n.01'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('safe_sex.n.01'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('sexual_activity.n.01'), 2.9444389791664407)
(Synset('sexual_love.n.02'), Synset('conception.n.02'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('sexual_intercourse.n.01'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('pleasure.n.05'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('sexual_love.n.02'), 3.6375861597263857)
(Synset('sexual_love.n.02'), Synset('carnal_abuse.n.01'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('coupling.n.03'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('reproduction.n.05'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('foreplay.n.01'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('perversion.n.02'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('autoeroticism.n.01'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('promiscuity.n.01'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('lechery.n.01'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('homosexuality.n.01'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('bisexuality.n.02'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('heterosexuality.n.01'), 2.538973871058276)
(Synset('sexual_love.n.02'), Synset('bestiality.n.02'), 2.538973871058276)
# ...
于 2013-04-02T09:04:28.620 回答
6

首先我们要问“什么是同义词?”,“可以从表面/词根查询同义词吗?”。

在 WordNet 中,在这个术语下,您有表示相同概念的相似词,Synset而不是表面词级别。

要在示例的覆盖范围内获取同义词集的同义词,您需要的不仅仅是 wordnet,可能还需要一些语义相似性方法来提取其他词。

我不能给你一个 JAWS 解释我上面的意思,但是来自 Python 的 NLTK 接口中的 WordNet。您可以看到 WN 不足以满足您想要的覆盖范围。

from nltk.corpus import wordnet as wn
for ss in wn.synsets('love'): # Each synset represents a diff concept.
  print ss.definition
  print ss.lemma_names
  print

上面的代码输出:

a strong positive emotion of regard and affection
['love']

any object of warm affection or devotion; 
['love', 'passion']

a beloved person; used as terms of endearment
['beloved', 'dear', 'dearest', 'honey', 'love']

a deep feeling of sexual desire and attraction
['love', 'sexual_love', 'erotic_love']

a score of zero in tennis or squash
['love']

sexual activities (often including sexual intercourse) between two people
['sexual_love', 'lovemaking', 'making_love', 'love', 'love_life']

have a great affection or liking for
['love']

get pleasure from
['love', 'enjoy']

be enamored or in love with
['love']

have sexual intercourse with
['sleep_together', 'roll_in_the_hay', 'love', 'make_out', 'make_love', 'sleep_with', 'get_laid', 'have_sex', 'know', 'do_it', 'be_intimate', 'have_intercourse', 'have_it_away', 'have_it_off', 'screw', 'fuck', 'jazz', 'eff', 'hump', 'lie_with', 'bed', 'have_a_go_at_it', 'bang', 'get_it_on', 'bonk']
于 2013-04-01T07:33:26.410 回答
2

我查看了RiWordNet (RiTa) 代码(参见getAllSynonyms方法),发现它通过为您提供所有同义词、下义词相似 tos也看到坐标名称的引理来生成同义词。我没有包括坐标名称,但添加了反义词。此外,我在我的数据中添加了同义词集名称和“同义词类型”,以便我可以使用其他 Wordnet 数据,如定义和/或示例。这是我在 python 中的代码和输出:

'''Synonym generator using NLTK WordNet Interface: http://www.nltk.org/howto/wordnet.html
    'ss': synset
    'hyp': hyponym
    'sim': similar to
    'ant': antonym
    'also' also see

'''

from nltk.corpus import wordnet as wn


def get_all_synsets(word, pos=None):
    for ss in wn.synsets(word):
        for lemma in ss.lemma_names():
            yield (lemma, ss.name())


def get_all_hyponyms(word, pos=None):
    for ss in wn.synsets(word, pos=pos):
            for hyp in ss.hyponyms():
                for lemma in hyp.lemma_names():
                    yield (lemma, hyp.name())


def get_all_similar_tos(word, pos=None):
    for ss in wn.synsets(word):
            for sim in ss.similar_tos():
                for lemma in sim.lemma_names():
                    yield (lemma, sim.name())


def get_all_antonyms(word, pos=None):
    for ss in wn.synsets(word, pos=None):
        for sslema in ss.lemmas():
            for antlemma in sslema.antonyms():
                    yield (antlemma.name(), antlemma.synset().name())


def get_all_also_sees(word, pos=None):
        for ss in wn.synsets(word):
            for also in ss.also_sees():
                for lemma in also.lemma_names():
                    yield (lemma, also.name())


def get_all_synonyms(word, pos=None):
    for x in get_all_synsets(word, pos):
        yield (x[0], x[1], 'ss')
    for x in get_all_hyponyms(word, pos):
        yield (x[0], x[1], 'hyp')
    for x in get_all_similar_tos(word, pos):
        yield (x[0], x[1], 'sim')
    for x in get_all_antonyms(word, pos):
        yield (x[0], x[1], 'ant')
    for x in get_all_also_sees(word, pos):
        yield (x[0], x[1], 'also')

for x in get_all_synonyms('love'):
    print x

“爱”和“勇敢”的输出:

(u'love', u'love.n.01', 'ss')
(u'love', u'love.n.02', 'ss')
(u'passion', u'love.n.02', 'ss')
(u'beloved', u'beloved.n.01', 'ss')
(u'dear', u'beloved.n.01', 'ss')
(u'dearest', u'beloved.n.01', 'ss')
(u'honey', u'beloved.n.01', 'ss')
(u'love', u'beloved.n.01', 'ss')
(u'love', u'love.n.04', 'ss')
(u'sexual_love', u'love.n.04', 'ss')
(u'erotic_love', u'love.n.04', 'ss')
(u'love', u'love.n.05', 'ss')
(u'sexual_love', u'sexual_love.n.02', 'ss')
(u'lovemaking', u'sexual_love.n.02', 'ss')
(u'making_love', u'sexual_love.n.02', 'ss')
(u'love', u'sexual_love.n.02', 'ss')
(u'love_life', u'sexual_love.n.02', 'ss')
(u'love', u'love.v.01', 'ss')
(u'love', u'love.v.02', 'ss')
(u'enjoy', u'love.v.02', 'ss')
(u'love', u'love.v.03', 'ss')
(u'sleep_together', u'sleep_together.v.01', 'ss')
(u'roll_in_the_hay', u'sleep_together.v.01', 'ss')
(u'love', u'sleep_together.v.01', 'ss')
(u'make_out', u'sleep_together.v.01', 'ss')
(u'make_love', u'sleep_together.v.01', 'ss')
(u'sleep_with', u'sleep_together.v.01', 'ss')
(u'get_laid', u'sleep_together.v.01', 'ss')
(u'have_sex', u'sleep_together.v.01', 'ss')
(u'know', u'sleep_together.v.01', 'ss')
(u'do_it', u'sleep_together.v.01', 'ss')
(u'be_intimate', u'sleep_together.v.01', 'ss')
(u'have_intercourse', u'sleep_together.v.01', 'ss')
(u'have_it_away', u'sleep_together.v.01', 'ss')
(u'have_it_off', u'sleep_together.v.01', 'ss')
(u'screw', u'sleep_together.v.01', 'ss')
(u'fuck', u'sleep_together.v.01', 'ss')
(u'jazz', u'sleep_together.v.01', 'ss')
(u'eff', u'sleep_together.v.01', 'ss')
(u'hump', u'sleep_together.v.01', 'ss')
(u'lie_with', u'sleep_together.v.01', 'ss')
(u'bed', u'sleep_together.v.01', 'ss')
(u'have_a_go_at_it', u'sleep_together.v.01', 'ss')
(u'bang', u'sleep_together.v.01', 'ss')
(u'get_it_on', u'sleep_together.v.01', 'ss')
(u'bonk', u'sleep_together.v.01', 'ss')
(u'agape', u'agape.n.01', 'hyp')
(u'agape', u'agape.n.02', 'hyp')
(u'agape_love', u'agape.n.02', 'hyp')
(u'amorousness', u'amorousness.n.01', 'hyp')
(u'enamoredness', u'amorousness.n.01', 'hyp')
(u'ardor', u'ardor.n.02', 'hyp')
(u'ardour', u'ardor.n.02', 'hyp')
(u'benevolence', u'benevolence.n.01', 'hyp')
(u'devotion', u'devotion.n.01', 'hyp')
(u'devotedness', u'devotion.n.01', 'hyp')
(u'filial_love', u'filial_love.n.01', 'hyp')
(u'heartstrings', u'heartstrings.n.01', 'hyp')
(u'lovingness', u'lovingness.n.01', 'hyp')
(u'caring', u'lovingness.n.01', 'hyp')
(u'loyalty', u'loyalty.n.02', 'hyp')
(u'puppy_love', u'puppy_love.n.01', 'hyp')
(u'calf_love', u'puppy_love.n.01', 'hyp')
(u'crush', u'puppy_love.n.01', 'hyp')
(u'infatuation', u'puppy_love.n.01', 'hyp')
(u'worship', u'worship.n.02', 'hyp')
(u'adoration', u'worship.n.02', 'hyp')
(u'adore', u'adore.v.01', 'hyp')
(u'care_for', u'care_for.v.02', 'hyp')
(u'cherish', u'care_for.v.02', 'hyp')
(u'hold_dear', u'care_for.v.02', 'hyp')
(u'treasure', u'care_for.v.02', 'hyp')
(u'dote', u'dote.v.02', 'hyp')
(u'love', u'love.v.03', 'hyp')
(u'get_off', u'get_off.v.06', 'hyp')
(u'romance', u'romance.v.02', 'hyp')
(u'fornicate', u'fornicate.v.01', 'hyp')
(u'take', u'take.v.35', 'hyp')
(u'have', u'take.v.35', 'hyp')
(u'hate', u'hate.n.01', 'ant')
(u'hate', u'hate.v.01', 'ant')

勇敢的

(u'brave', u'brave.n.01', 'ss')
(u'brave', u'brave.n.02', 'ss')
(u'weather', u'weather.v.01', 'ss')
(u'endure', u'weather.v.01', 'ss')
(u'brave', u'weather.v.01', 'ss')
(u'brave_out', u'weather.v.01', 'ss')
(u'brave', u'brave.a.01', 'ss')
(u'courageous', u'brave.a.01', 'ss')
(u'audacious', u'audacious.s.01', 'ss')
(u'brave', u'audacious.s.01', 'ss')
(u'dauntless', u'audacious.s.01', 'ss')
(u'fearless', u'audacious.s.01', 'ss')
(u'hardy', u'audacious.s.01', 'ss')
(u'intrepid', u'audacious.s.01', 'ss')
(u'unfearing', u'audacious.s.01', 'ss')
(u'brave', u'brave.s.03', 'ss')
(u'braw', u'brave.s.03', 'ss')
(u'gay', u'brave.s.03', 'ss')
(u'desperate', u'desperate.s.04', 'sim')
(u'heroic', u'desperate.s.04', 'sim')
(u'gallant', u'gallant.s.01', 'sim')
(u'game', u'game.s.02', 'sim')
(u'gamy', u'game.s.02', 'sim')
(u'gamey', u'game.s.02', 'sim')
(u'gritty', u'game.s.02', 'sim')
(u'mettlesome', u'game.s.02', 'sim')
(u'spirited', u'game.s.02', 'sim')
(u'spunky', u'game.s.02', 'sim')
(u'lionhearted', u'lionhearted.s.01', 'sim')
(u'stalwart', u'stalwart.s.03', 'sim')
(u'stouthearted', u'stalwart.s.03', 'sim')
(u'undaunted', u'undaunted.s.02', 'sim')
(u'valiant', u'valiant.s.01', 'sim')
(u'valorous', u'valiant.s.01', 'sim')
(u'bold', u'bold.a.01', 'sim')
(u'colorful', u'colorful.a.02', 'sim')
(u'colourful', u'colorful.a.02', 'sim')
(u'timid', u'timid.n.01', 'ant')
(u'cowardly', u'cowardly.a.01', 'ant')
(u'adventurous', u'adventurous.a.01', 'also')
(u'adventuresome', u'adventurous.a.01', 'also')
(u'bold', u'bold.a.01', 'also')
(u'resolute', u'resolute.a.01', 'also')
(u'unafraid', u'unafraid.a.01', 'also')
(u'fearless', u'unafraid.a.01', 'also')
于 2015-07-07T01:12:24.603 回答
1

使用RitaWN代替JAWS怎么样?我看到它被列为http://wordnet.princeton.edu/wordnet/related-projects/#Java中的可用 API 之一, 我还看到它有getAllSynonyms()方法,他们提供了一个示例并且它有效。

看一下这个:

import java.io.IOException;
import java.util.Arrays;

import rita.*;

public class Synonyms {

public static void main(String[] args) throws IOException {

    // Would pass in a PApplet normally, but we don't need to here
    RiWordNet wordnet = new RiWordNet("C:\\Program Files (x86)\\WordNet\\2.1");

    // Get a random noun
    String word = "love";//wordnet.getRandomWord("n");
    // Get max 15 synonyms
    String[] synonyms = wordnet.getAllSynonyms(word, "v");

    System.out.println("Random noun: " + word);
    if (synonyms != null) {
        // Sort alphabetically
        Arrays.sort(synonyms);
        for (int i = 0; i < synonyms.length; i++) {
            System.out.println("Synonym " + i + ": " + synonyms[i]);
        }
    } else {
        System.out.println("No synyonyms!");
    }
}

确保从http://www.rednoise.org/rita/wordnet-old/documentation/index.htm获得最新的下载和文档

于 2014-08-18T17:39:15.433 回答