python - 如何在wordnet中获取相似词(不仅仅是同义词)?

标签 python nlp nltk wordnet

如何使用 wordnet 获取相似词,而不仅仅是使用同义词集及其词条的同义词?

例如,如果您在 wordnet 在线工具 (http://wordnetweb.princeton.edu/) 上搜索“happy”。对于第一个同义词集,只有一个同义词(happy),但如果您单击它(在 S: 链接上),您会在“see also”和“similar to”字词中获​​得其他字词,例如“cheerful”。

我如何获得这些词以及它们在 wordnet 术语中的名称?我将 python 与 nltk 一起使用,最多只能获得同义词集和引理(不包括上位词等)

最佳答案

“also_sees()”和“similar_tos()”。

>>> from nltk.corpus import wordnet as wn
>>> wn.synsets("happy")[0].also_sees() 
[Synset('cheerful.a.01'), Synset('contented.a.01'), Synset('elated.a.01'), Synset('euphoric.a.01'), Synset('felicitous.a.01'), Synset('glad.a.01'), Synset('joyful.a.01'), Synset('joyous.a.01')]
>>> wn.synsets("happy")[0].similar_tos()
[Synset('blessed.s.06'), Synset('blissful.s.01'), Synset('bright.s.09'), Synset('golden.s.02'), Synset('laughing.s.01')]

如果您想查看 WordNet 同义词集功能的完整列表,请尝试“dir()”命令。 (它会充满你可能不想要的对象,所以我去掉了下面的下划线。)

 >>> [func for func in dir(wn.synsets("happy")[0]) if func[0] != "_"]         
 ['acyclic_tree', 'also_sees', 'attributes', 'causes', 'closure', 'common_hypernyms', 'definition', 'entailments', 'examples', 'frame_ids', 'hypernym_distances', 'hypernym_paths', 'hypernyms', 'hyponyms', 'in_region_domains', 'in_topic_domains', 'in_usage_domains', 'instance_hypernyms', 'instance_hyponyms', 'jcn_similarity', 'lch_similarity', 'lemma_names', 'lemmas', 'lexname', 'lin_similarity', 'lowest_common_hypernyms', 'max_depth', 'member_holonyms', 'member_meronyms', 'min_depth', 'mst', 'name', 'offset', 'part_holonyms', 'part_meronyms', 'path_similarity', 'pos', 'region_domains', 'res_similarity', 'root_hypernyms', 'shortest_path_distance', 'similar_tos', 'substance_holonyms', 'substance_meronyms', 'topic_domains', 'tree', 'usage_domains', 'verb_groups', 'wup_similarity']

关于python - 如何在wordnet中获取相似词(不仅仅是同义词)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55005152/

相关文章:

python - 如何通过键列表导航字典?

algorithm - Q处理的QA算法

python - 具有自定义数据的 NLTK 命名实体识别

Python 决策树分类器 batch_prob_classify 函数

machine-learning - 使用 TextBlob 进行文本分类

python - collective.googleanalytics 报告中的自定义维度

python - 如何在列表中将大写字母转换为小写字母?

python - 堆积条形图更改 x 轴绘图数值

dictionary - 文本文件中有任何公开可用的单词词典吗?

r - 从 R 中的句子中提取对对象的操作