简体   繁体   English

如何获得其path_similarity得分最高的同义词集

[英]How to get the synset for which path_similarity score is the highest

I understand that the following code iterates over all the synsets of syn1 with synsets of syn2 . 我了解以下代码对syn1所有同义词集和syn1的同义词集进行syn2

My question is, how to get the synset that gives the maximum score? 我的问题是,如何获得给出最高分的同义词集?

    from nltk.corpus import wordnet
    syn1 = wordnet.synsets('speed',pos='n')
    syn2 = wordnet.synsets('performance',pos='n')
    for word1 in syn1:
        best = max(word1.path_similarity(word2) for word2 in syn2)
        ps_list.append(best)

Maybe you need something like this: 也许您需要这样的东西:

import numpy as np
from nltk.corpus import wordnet

syn1 = wordnet.synsets('speed',pos='n')
syn2 = wordnet.synsets('performance',pos='n')

def getMaxPath(synset1,synset2):
    sim=[]
    a=[]
    b=[]
    for i in synset1:
        for j in synset2:
            sim.append(wordnet.path_similarity(i,j))
            a.append(i.name())   # save the names from synsets1 into list
            b.append(j.name())   # save the names from synsets2 into list

    max_sim=max(sim)
    idx=np.argmax(sim)
    s1=a[idx]        # get the name of synset1 for which path sim is max
    s2=b[idx]        # get the name of synset2 for which path sim is max
    return max_sim, s1, s2

getMaxPath(syn1, syn2)

Output: 输出:

(0.2, 'speed.n.03', 'performance.n.03')

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

相关问题 NLTK path_similarity 给出 ValueError - NLTK path_similarity is giving ValueError 如何测量相似度并找出与具有最高相似度的对应图像匹配的图像? - How to measure the similarity and find out which image matches the corresponding image that have the highest similarity? 如何使用 python 获得关键字和段落之间的相似度 (PMI) 分数? - How to get similarity (PMI) score between a keyword and paragraphs using python? 如何获得给定偏移 ID 的 WordNet 同义词集? - How to get the WordNet synset given an offset ID? 计算路径相似性得分并列出理解问题 - calculate path similarity score and list comprehension questions 如何获取NLTK中同义词集的词网感知频率? - How to get the wordnet sense frequency of a synset in NLTK? 如何获得“和”等停用词的路径相似度 - How to Get Path Similarity of Stopwords like "and" 使用python查找图中最高分数路径的函数 - Function to find the highest score path in a graph with python 如何让这个程序打印出分数最高的 state 和分数 > 500 的州? - How do I get this program to print out the state with the highest score and states with score > 500? 如何在python nltk和wordnet中获得单词/ synset的所有下位词? - How to get all the hyponyms of a word/synset in python nltk and wordnet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM