private double wupMeasure(SynSet Sense1, SynSet Sense2) { string str1, str2; if (Sense1 == Sense2) { return(1); } double similarity = 0; SynSet LCS = Sense1.GetClosestMutuallyReachableSynset(Sense2, SynSetRelationTypes); SynSet LCSAlternative = Sense2.GetClosestMutuallyReachableSynset(Sense1, SynSetRelationTypes); if (LCS == null || LCSAlternative == null) { return(0); } else { str1 = string.Join(" ", Sense1.Synonyms) + " " + Sense1.Gloss; str2 = string.Join(" ", Sense2.Synonyms) + " " + Sense2.Gloss; str1 = str1.Replace("_", " ").Replace("-", " "); str2 = str2.Replace("_", " ").Replace("-", " "); double overlap = 10 * Math.Log(1 + Intersect(_tokenizer.Tokenize(str1), _tokenizer.Tokenize(str2))); double LCS_Depth = LCS.GetShortestPathTo(RootVirtualNode, SynSetRelationTypes).Count + 1; double LCS_DepthAlter = LCSAlternative.GetShortestPathTo(RootVirtualNode, SynSetRelationTypes).Count + 1; if (LCS_Depth < LCS_DepthAlter) { LCS = LCSAlternative; LCS_Depth = LCS_DepthAlter; } similarity = ((2 * LCS_Depth) + overlap) / ( (Sense1.GetShortestPathTo(LCS, SynSetRelationTypes).Count - 1 + LCS_Depth) + (Sense2.GetShortestPathTo(LCS, SynSetRelationTypes).Count - 1 + LCS_Depth) + overlap ); } return(similarity); }
public double Measure(SynSet synSet1, SynSet synSet2) { if (synSet1 == null) { throw new ArgumentNullException(nameof(synSet1)); } if (synSet2 == null) { throw new ArgumentNullException(nameof(synSet2)); } var tag = GenerateTag(synSet1, synSet2); return(cache.GetOrCreate( tag, entry => { SynSetRelation[] vlist = new SynSetRelation[1]; vlist[0] = SynSetRelation.Hypernym; var common = synSet1.GetClosestMutuallyReachableSynset(synSet2, vlist); double distance = 0; if (common != null) { distance = resnik.GetIC(synSet1) + resnik.GetIC(synSet2) - 2 * resnik.GetIC(common); } if (distance == 0) { return 0; } if (distance < MinDistance) { distance = MinDistance; } return 1 / distance; })); }