예제 #1
0
        public IDictionaryWord FindBestWord(IWord source)
        {
            int minUsingCount = 100100100;

            foreach (IDictionaryWord dw in dictionaryWords)
            {
                minUsingCount = Math.Min(minUsingCount, dw.GetUsingCount());
            }
            double          maxEval = -100100100;
            IDictionaryWord res     = null;

            foreach (IDictionaryWord dw in dictionaryWords)
            {
                if (minUsingCount != dw.GetUsingCount())
                {
                    continue;
                }
                double eval = Evaluate(source, dw);
                if (maxEval < eval)
                {
                    maxEval = eval;
                    res     = dw;
                }
            }
            if (res == null)
            {
                ;
            }
            return(res);
        }
예제 #2
0
        public double Evaluate(IWord source, IDictionaryWord target)
        {
            double[,,] dp;
            wc.DoDP(source, (IWord)target, out dp);
            double res = 0;

            for (int i = 0; i < dp.GetLength(1); i++)
            {
                res = Math.Max(res, dp[dp.GetLength(0) - 1, i, 0]);
            }
            if (res + 1e-6 > dp.GetLength(0) - 1)
            {
                return(0);
            }
            return(res);
        }
예제 #3
0
 public Task <IDajare> Generate(List <IWord> keywords)
 {
     return(taskFactory.StartNew(() =>
     {
         keywords = extractMeishi(keywords);
         //keywords数が多い場合は削る
         //TODO: 調整
         while (keywords.Count > 10)
         {
             keywords.RemoveAt(keywords.Count - 1);
         }
         int minUsingCount = 100100100;
         List <IDictionaryWord> searchedWords = new List <IDictionaryWord>();
         Searcher s = Searcher.GetInstance();
         foreach (IWord w in keywords)
         {
             searchedWords.Add(s.FindBestWord(w));
             minUsingCount = Math.Min(minUsingCount, searchedWords.Last().GetUsingCount());
         }
         int index = -1;
         double maxEval = -1e10;
         for (int i = 0; i < searchedWords.Count; i++)
         {
             IDictionaryWord dw = searchedWords[i];
             if (dw.GetUsingCount() > minUsingCount)
             {
                 continue;
             }
             double eval = dw.GetEvalution();
             if (maxEval < eval)
             {
                 maxEval = eval;
                 index = i;
             }
         }
         //Log.Debug("generator", index.ToString());
         WordAssembler wa = new WordAssembler(keywords[index]);
         IDajare res = wa.Assemble(searchedWords[index].GetWord());
         if (res == null)
         {
             ;
         }
         res.AddUsingCount();
         return res;
     }));
 }