简体   繁体   English

给定两个词,找出它们是否在同一个同义词集中

[英]Given two words, find whether they are in the same synset

am fairly new to nltk. 对nltk来说还很新。 I am trying to find out a solution to the problem I am currently working on: 我正在尝试找出当前正在解决的问题的解决方案:

  • Given two words w1 and w2 is there a way to find out whether they belong to the same sysnet in the Wordnet database? 给定两个单词w1和w2,有没有一种方法可以找出它们是否在Wordnet数据库中属于相同的sysnet?
  • Also is it possible to find the list of sysnets that contain a given word? 还可以找到包含给定单词的sysnet列表吗?

Thanks. 谢谢。

Also is it possible to find the list of sysnets that contain a given word? 还可以找到包含给定单词的sysnet列表吗?

Yes : 是的

>>> from nltk.corpus import wordnet as wn
>>> auto, car = 'auto', 'car'
>>> wn.synsets(auto)
[Synset('car.n.01')]
>>> wn.synsets(car)
[Synset('car.n.01'), Synset('car.n.02'), Synset('car.n.03'), Synset('car.n.04'), Synset('cable_car.n.01')]

If we look at lemmas in every synset from wn.synsets(car) , we'll find "car" exist as one of the lemma: 如果我们从wn.synsets(car)每个同义词wn.synsets(car)查看引理,则会发现“ car”作为引理之一存在:

>>> for ss in wn.synsets(car):
...     assert 'car' in ss.lemma_names()
... 
>>> for ss in wn.synsets(car):
...     print 'car' in ss.lemma_names(), ss.lemma_names()
... 
True [u'car', u'auto', u'automobile', u'machine', u'motorcar']
True [u'car', u'railcar', u'railway_car', u'railroad_car']
True [u'car', u'gondola']
True [u'car', u'elevator_car']
True [u'cable_car', u'car']

Note: A lemma is not exactly a surface word, see Stemmers vs Lemmatizers , also, you might find this helpful https://github.com/alvations/pywsd/blob/master/pywsd/utils.py#L66 (Disclaimer: Shameless plug) 注意:引理不是完全表面的单词,另请参见Stemmers vs Lemmatizers ,您可能会发现此有用的https://github.com/alvations/pywsd/blob/master/pywsd/utils.py#L66 (免责声明:无耻插头)

Given two words w1 and w2 is there a way to find out whether they belong to the same sysnet in the Wordnet database? 给定两个单词w1和w2,有没有一种方法可以找出它们是否在Wordnet数据库中属于相同的sysnet?

Yes : 是的

>>> from nltk.corpus import wordnet as wn
>>> auto, car = 'auto', 'car'
>>> wn.synsets(auto)
[Synset('car.n.01')]
>>> wn.synsets(car)
[Synset('car.n.01'), Synset('car.n.02'), Synset('car.n.03'), Synset('car.n.04'), Synset('cable_car.n.01')]
>>> auto_ss = set(wn.synsets(auto))
>>> car_ss = set(wn.synsets(car))
>>> car_ss.intersection(auto_ss)
set([Synset('car.n.01')])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 WordNet 找出两个词是否是彼此的同义词 - Using WordNet to find out whether two words are synonyms of each other Python function 用于判断字符串中的两个单词是否以相同的字母开头 - Python function for determining whether two words in a string start with the same letter 查找一个句子是否有另一个句子的起始词或同一个句子的结束词 - Find whether a sentence has the starting words of another sentence or the ending words of the same sentence 从与给定单词相同模式的文本中查找字符串 - Find strings from text same pattern as given words 如何在wordnet层次结构中使用python nltk查找两个同义词集之间的距离? - How to find distance between two synset using python nltk in wordnet hierarchy? 给定一个单词列表,确定这些单词是否可以链接形成一个圆圈 - Given a list of words, determine whether the words can be chained to form a circle 如何获得给定偏移 ID 的 WordNet 同义词集? - How to get the WordNet synset given an offset ID? 如何使用python正则表达式判断两个单词的意思是否相同 - How to judge whether the meaning of two words is the same using python regular expression 如何找到用两种不同语言出现的所有相同单词? - How to find all words that have the same appearence in two different languages? 如何使用Python 3在两个csv文件中找到相同的单词 - how to find the same words in two csv files using Python 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM