Exemplo n.º 1
0
 public static WordSimilarity GetInstance()
 {
     if (_wordSimilarity == null)
     {
         _wordSimilarity = new WordSimilarity();
     }
     return(_wordSimilarity);
 }
Exemplo n.º 2
0
        /// <summary>
        /// 词性逻辑相似度
        /// </summary>
        /// <param name="speech1"></param>
        /// <param name="speech2"></param>
        /// <returns></returns>
        private double SpeechSimilarity(Tuple <string[], string[]> tuple1, Tuple <string[], string[]> tuple2)
        {
            WordSimilarity similarity = WordSimilarity.GetInstance();
            Hashtable      table1     = GetSemanticFlags(tuple1.Item2, tuple1.Item1);
            Hashtable      table2     = GetSemanticFlags(tuple2.Item2, tuple2.Item1);

            //相似度计算
            double similarValue = 0;
            double totalValue   = 0;

            foreach (DictionaryEntry entry1 in table1)
            {
                if (_semanticAttributes.ContainsKey(entry1.Key))
                {
                    double flagRank = (double)_semanticAttributes[entry1.Key];
                    totalValue += flagRank;
                    if (table2.ContainsKey(entry1.Key))
                    {
                        similarValue +=
                            similarity.SimList((List <string>)entry1.Value, (List <string>)table2[entry1.Key]) *
                            flagRank;
                        table2.Remove(entry1.Key);
                    }
                }
            }

            foreach (DictionaryEntry dictionaryEntry in table2)
            {
                if (_semanticAttributes.ContainsKey(dictionaryEntry.Key))
                {
                    totalValue += (double)_semanticAttributes[dictionaryEntry.Key];
                }
            }
            if (totalValue > 0)
            {
                return(similarValue / totalValue);
            }
            return(0);
        }
Exemplo n.º 3
0
 public static WordSimilarity GetInstance()
 {
     if (_wordSimilarity == null)
     {
         _wordSimilarity = new WordSimilarity();
     }
     return _wordSimilarity;
 }