• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python wordnet.path_similarity函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nltk.corpus.wordnet.path_similarity函数的典型用法代码示例。如果您正苦于以下问题:Python path_similarity函数的具体用法?Python path_similarity怎么用?Python path_similarity使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了path_similarity函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: checkFirstSentence_test5

def checkFirstSentence_test5(paragraphID, paragraph):
    if paragraphID in cache:
        tokens = cache[paragraphID]
    else:
        tokens = getParagraphTokenIntersectionByID(paragraphID)
        cache[paragraphID] = tokens

    for token in tokens:
        if token in paragraph[0]:
            return True

    for token in tokens:
        tokenSynset = getSynset(token, paragraphID)
        if tokenSynset:
            partOfSpeechMap = POSCache[paragraphID]
            tokenPos = partOfSpeechMap[token]
            for word in paragraph[0].split(" "):
                word = word.strip().lower()
                if word in partOfSpeechMap:
                    wordPos = partOfSpeechMap[word]
                    if wordPos == tokenPos:
                        wordSynset = getSynset(word, paragraphID)
                        if wordSynset:
                            if (
                                wn.path_similarity(tokenSynset, wordSynset)
                                and wn.path_similarity(tokenSynset, wordSynset) > 0.13
                            ):
                                return True
    return False
开发者ID:travis14,项目名称:csli-research,代码行数:29,代码来源:allStyleChecks.py


示例2: similarity_by_path

def similarity_by_path(sense1, sense2, option="path"):
  if option.lower() in ["path", "path_similarity"]: # Path similaritys
    return max(wn.path_similarity(sense1,sense2), 
               wn.path_similarity(sense1,sense2))
  elif option.lower() in ["wup", "wupa", "wu-palmer", "wu-palmer"]: # Wu-Palmer 
    return wn.wup_similarity(sense1, sense2)
  elif option.lower() in ['lch', "leacock-chordorow"]: # Leacock-Chodorow
    if sense1.pos != sense2.pos: # lch can't do diff POS
      return 0
    return wn.lch_similarity(sense1, sense2)
开发者ID:kmwenja,项目名称:ftm,代码行数:10,代码来源:similarity.py


示例3: wnsensesim

def wnsensesim(synset1, synset2, metric):
    #return wn similarity of two synsets according to metric

    #if metric == 'path_similarity':
    print "synset1:%r"%synset1
    print "synset2:%r"%synset2
    if metric == 'path_similarity':
        print wn.path_similarity(synset1, synset2)
        return wn.path_similarity(synset1, synset2)
    else:#add more similarity measures e.g., jcn
        print "Unsupported wn similarity measure requested"
开发者ID:fieryfish,项目名称:wordSubstitutionTask,代码行数:11,代码来源:predominantsense.py


示例4: similarity_by_path

def similarity_by_path(sense1, sense2, option="path"):
  """ Returns maximum path similarity between two senses. """
  if option.lower() in ["path", "path_similarity"]: # Path similaritys
    return max(wn.path_similarity(sense1,sense2), 
               wn.path_similarity(sense1,sense2))
  elif option.lower() in ["wup", "wupa", "wu-palmer", "wu-palmer"]: # Wu-Palmer 
    return wn.wup_similarity(sense1, sense2)
  elif option.lower() in ['lch', "leacock-chordorow"]: # Leacock-Chodorow
    if sense1.pos != sense2.pos: # lch can't do diff POS
      return 0
    return wn.lch_similarity(sense1, sense2)

    return wn.lin_similarity(sense1, sense2, wnic.ic('ic-bnc-add1.dat'))
开发者ID:alee101,项目名称:wsd,代码行数:13,代码来源:semanticsim.py


示例5: get_relation

def get_relation(syn1,syn2,sim_metric):
    from nltk.corpus import wordnet as wn
    if sim_metric == "path":
        # https://stackoverflow.com/questions/20075335/is-wordnet-path-similarity-commutative
        sim_score = min(wn.path_similarity(syn1,syn2), wn.path_similarity(syn2,syn1))
    elif sim_metric == "lch":
        if syn1.pos() == syn2.pos():
            sim_score = syn1.lch_similarity(syn2)
        else:
            sim_score = 0
    elif sim_metric == "wup":
        sim_score = syn1.wup_similarity(syn2)
    if sim_score: return sim_score
    else: return 0 
开发者ID:vsoch,项目名称:brainbehavior,代码行数:14,代码来源:cognitiveatlas.py


示例6: get_score

def get_score(tags, groups):
  sscore = 0
  scount = 0 
  illegal_word = 0

  if (tags != None ) :
   for g in groups:
    
    for x in k.tags:
     try : 
      #print str(x.text), 
      #check substring else calculate words similarity score
      if g in str(x.text).lower():
	sscore += 2.0
        scount += 1
      else:
       tag = wn.synset(str(x.text).lower()+'.n.01')
       group = wn.synset(g+ '.n.01')  
       sem = wn.path_similarity(group,tag)
       if sem >= 0.3 :
        sscore += sem
	scount += 1     
     except:
	illegal_word += 1
  if scount != 0 :
    return sscore/scount
  else :
    return 0
开发者ID:tushar19,项目名称:Web-Image-Ranking-Retrieval,代码行数:28,代码来源:imgsearch.py


示例7: internal_word_max_WSD

def internal_word_max_WSD(sentence, word):
    """
    Auxiliary function for sem_wsd()

    Input: a sentence and a word in the sentence,
            sentence is a list of words, not a string

    Return: synset(sense) of the word that maximize one similarity with another word in the sentence

    Derived from code at http://www.jaist.ac.jp/~s1010205/sitemap-2/styled-7/
    """    
    wordsynsets = wn.synsets(word)
    bestScore = 0.0
    result = None
    for synset in wordsynsets:
        for w in sentence:
            score = 0.0
            for wsynset in wn.synsets(w):
                sim = wn.path_similarity(wsynset, synset)
                if(sim == None):
                    continue
                else:
                    score += sim
            if (score > bestScore):
                bestScore = score
                result = synset
    return result
开发者ID:YuanhaoSun,项目名称:PPLearn,代码行数:27,代码来源:ml_feature_engineering.py


示例8: __similarity

 def __similarity(self, word, compareto):
     try:
         score = word.jcn_similarity(compareto, self.wordnet_ic, True)
     except:
         score = wordnet.path_similarity(word, compareto)
     if score == -1: score = None #No path between the words was found
     return score
开发者ID:oakmad,项目名称:Sentiment,代码行数:7,代码来源:dissertation.py


示例9: create_graphs

def create_graphs(doc_list):
    documents = doc_list
    if documents is None:
        documents = default_document_list()

    distance_functions = [
        (wn.lch_similarity(SYNSETS[0], SYNSETS[0]), 'lch', lambda sense_1, sense_2: wn.lch_similarity(sense_1, sense_2)),
        (1.0, 'lin', lambda sense_1, sense_2: wn.lin_similarity(sense_1, sense_2, CORPUS)),
        (10.636958516573292, 'res', lambda sense_1, sense_2: wn.res_similarity(sense_1, sense_2, CORPUS)),
        (wn.jcn_similarity(SYNSETS[0], SYNSETS[0], CORPUS), 'jcn', lambda sense_1, sense_2: wn.jcn_similarity(sense_1, sense_2, CORPUS)),
        (1.0, 'path', lambda sense_1, sense_2: wn.path_similarity(sense_1, sense_2)),
    ]
    all_senses = []
    for doc in documents:
        for sense in doc.top_senses():
            all_senses.append((sense, doc.name))
    against_colors = ['r', 'b', 'g']
    against_to = [wn.synset(word) for word in ["economy.n.01", "philosophy.n.02", "politics.n.01"]]
    create_against_graph('phyl_eco_pol', documents, all_senses, against_to, distance_functions, against_colors)

    against_to = SYNSETS

    against_colors = [(random(), random(), random()) for _i in range(0, len(SYNSETS))]
    create_against_graph('handpicked', documents, all_senses, against_to, distance_functions, against_colors)

    create_graph_top_senses(documents, all_senses, distance_functions)
开发者ID:finiteautomata,项目名称:leninanalysis,代码行数:26,代码来源:top_senses_tables.py


示例10: disambiguateWordSenses

 def disambiguateWordSenses(self,sentence,word):
     wordsynsets = wn.synsets(word)
     bestScore = 0.0
     result = None
     for synset in wordsynsets:
         for w in nltk.word_tokenize(sentence):
             score = 0.0
             for wsynset in wn.synsets(w):
                 sim = wn.path_similarity(wsynset, synset)
                 if(sim == None):
                     continue
                 else:
                     score += sim
                 if (score > bestScore):
                     bestScore = score
                     result = synset
     if result:
         pos = result.pos()
         offset = result.offset()
         pos_score=0.0
         neg_score=0.0
         if (pos, offset) in self.db:
             pos_score, neg_score = self.db[(pos, offset)]
         obj = 1.0-(pos_score+neg_score)
         #print "%%%%%%%%%%"
         #print pos_score,neg_score, obj
     else:
         obj=1.0
         pos=None
         pos_score=0.0
         neg_score=0.0
     return obj,pos,pos_score,neg_score
开发者ID:shreyg,项目名称:GitFiles,代码行数:32,代码来源:test1.py


示例11: relevancy_score

    def relevancy_score(desiredDoc):
        #Each word has score between 0 to 1 in terms of similarity. "None" is returned
        #there is no similarity. 
        newWord =searchWord + ".n.01" 
        searchWordwn = wn.synset(newWord)
##        print (newWord)
##        print (searchWordwn)
        relevancyScore = 0
        currentWordScore = 0
        memo = {}
        for i in range(len(keywords)):
                currentWord = keywords[i][0]
                if currentWord in memo:
                    currentWordScore = memo[currentWord]
                    if currentWordScore != None:
                        relevancyScore += currentWordScore
                else:
                    if wn.synsets(currentWord, pos = wn.NOUN) != []:
                        currentWordwn = wn.synsets(currentWord, pos = wn.NOUN)[0]
                        currentWordScore = wn.path_similarity(searchWordwn,currentWordwn)
                        memo[currentWord] = currentWordScore

                    if currentWordScore != None:
                        relevancyScore += currentWordScore

        return relevancyScore
开发者ID:apurvas,项目名称:inDepthRating,代码行数:26,代码来源:inDepthArticle.py


示例12: syn

def syn(conw,candw):
    syn_strings = lambda x : str(x)[8:-2]
    pos = lambda y : y[-4:]
        
    #find the synsets of the context word
    ssets = wn.synsets(conw)
    sset_strings = map(syn_strings,ssets)

    #synsets of the candidate word
    csets = wn.synsets(candw)
    cset_strings = map(syn_strings,csets)

    #take a synset whose part of speech matches
    
    matches = [(i,j) for i in range(len(sset_strings)) for j in range(len(cset_strings)) if pos(sset_strings[i]) == pos(cset_strings[j])]
    similarity = 0
    if matches != []:
          
        (k,l) = matches[0]
        similarity = wn.path_similarity(ssets[k],csets[l])
    else:
        similarity = 0

    if similarity is None:
        return 0
    else:
        return similarity
开发者ID:vignesh117,项目名称:pyth_checker,代码行数:27,代码来源:similarity.py


示例13: disambiguate_word_senses

    def disambiguate_word_senses(self, sentence, word):
        """
        Attempts to determine the proper sense of the target
        word from the sentence in which it appears.

        Args:
            sentence: String representation of the sentence
            word: String represtnation of word

        Returns:
            Returns a synset which is the best guess.

        Example:
            disambiguateWordSenses('A cat is a good pet', 'cat')
            OUT: Synset('cat.v.01')
        """
        wordsynsets = wn.synsets(word)
        bestScore = 0.0
        result = None
        for synset in wordsynsets:
            for w in nltk.word_tokenize(sentence):
                score = 0.0
                for wsynset in wn.synsets(w):
                    sim = wn.path_similarity(wsynset, synset)
                    if(sim == None):
                        continue
                    else:
                        score += sim
                if (score > bestScore):
                    bestScore = score
                    result = synset
        return result
开发者ID:PainNarrativesLab,项目名称:IOMNarratives,代码行数:32,代码来源:SentimentAnalysis.py


示例14: findMaxPathSimilarity

def findMaxPathSimilarity(ingredSynsets, foodSynsets):
	maxPathSimilarity = 0
	for synseta in ingredSynsets:
		for synsetb in foodSynsets:
			pathSim = wn.path_similarity(synseta, synsetb)
			if pathSim > maxPathSimilarity: 
				maxPathSimilarity = pathSim
	return maxPathSimilarity
开发者ID:venkatvi,项目名称:EYB,代码行数:8,代码来源:NLProcessor.py


示例15: word_similarity

 def word_similarity(self, word1, word2):
     w1synsets = wn.synsets(word1)
     w2synsets = wn.synsets(word2)
     maxsim = 0
     for w1s in w1synsets:
         for w2s in w2synsets:
             current = wn.path_similarity(w1s, w2s)
             if (current > maxsim and current > 0):
                 maxsim = current
     return maxsim
开发者ID:SELCHI,项目名称:TravelProfiling,代码行数:10,代码来源:wsd_helper.py


示例16: get_path_similarity_between_boy_and_dog

def get_path_similarity_between_boy_and_dog():
    """
    Computes the path similarity between "boy" and "dog".

    Returns
    -------
    A float.
    """

    return wn.path_similarity(wn.synset('boy.n.01'), wn.synset('dog.n.01'))
开发者ID:nwngeek212,项目名称:NaturalLanguageProcessing,代码行数:10,代码来源:helper.py


示例17: wnsensesim

def wnsensesim(synset1, synset2, metric):

    if metric == 'path_similarity':
        return wn.path_similarity(synset1, synset2)
    elif metric == 'lch_similarity':
        return wn.lch_similarity(synset1, synset2)
    elif metric == 'wup_similarity':
        return wn.wup_similarity(synset1, synset2)
    else:#add more similarity measures e.g., jcn
        print "Unsupported wn similarity measure requested"
开发者ID:fieryfish,项目名称:wordSubstitutionTask,代码行数:10,代码来源:subs_system.py


示例18: semantic_score

def semantic_score(word1, word2):
    '''
    Semantic score between two words based on WordNet
    Returns: float (the semantic score between word1 and word2)
    '''
    try:
        w1 = wn.synset('%s.n.01'%(word1))
        w2 = wn.synset('%s.n.01'%(word2))
        return wn.path_similarity(w1,w2,simulate_root = False)
    except:
        return 0
开发者ID:najeeb97khan,项目名称:ShapSum,代码行数:11,代码来源:utils.py


示例19: compare

def compare(a,b,min=0.31):
# returns True if a has equal meaning to b, False otherwise
    asyn = wn.synsets(a)
    bsyn = wn.synsets(b)
    if len(asyn) > 0 and len(bsyn) > 0:
        for ax in asyn:
            if len(filter(lambda x : x == True,map(lambda bx : wn.path_similarity(ax,bx) > min, bsyn)))>0:
                return True
        return False
    else:
        return a == b
开发者ID:houbysoft,项目名称:meaningcmp,代码行数:11,代码来源:argmatch.py


示例20: __init__

 def __init__(self, obs_corpus, target_corpus, metric="path", aggregation_mode_prev="", aggregation_mode=""):
     super().__init__(obs_corpus, target_corpus, aggregation_mode, None, aggregation_mode_prev)
     self.metric = metric
     if self.metric == "path":
         self.metric_func = lambda syn1, syn2: wn.path_similarity(syn1, syn2)
     elif self.metric == "lch":
         self.metric_func = lambda syn1, syn2: wn.lch_similarity(syn1, syn2)
     elif self.metric == "wup":
         self.metric_func = lambda syn1, syn2: wn.wup_similarity(syn1, syn2)
     else:
         raise(ValueError("Wrong similarity metric: %s, should be one of path/lch/wup."%self.metric))
开发者ID:amsqr,项目名称:Kaggle_HomeDepot,代码行数:11,代码来源:feature_wordnet_similarity.py



注:本文中的nltk.corpus.wordnet.path_similarity函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python wordnet.synset函数代码示例发布时间:2022-05-27
下一篇:
Python wordnet.morphy函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap