コード例 #1
0
        // return candidate scoreObj list sorted by score, higher first
        public static List <NoisyChannelScore> GetCandidateScoreList(string wordStr, HashSet <string> candidates, WordWcMap wordWcMap, double wf1, double wf2, double wf3)
        {
            HashSet <NoisyChannelScore> candScoreSet  = GetCandidateScoreSet(wordStr, candidates, wordWcMap, wf1, wf2, wf3);
            List <NoisyChannelScore>    candScoreList = new List <NoisyChannelScore>(candScoreSet);
            // sort the set to list
            NoisyChannelScoreComparator <NoisyChannelScore> ncsc = new NoisyChannelScoreComparator <NoisyChannelScore>();

            candScoreList.Sort(ncsc);
            return(candScoreList);
        }
コード例 #2
0
        // private methods
        private static int RunTest(bool detailFlag, long limitNo)
        {
            // init dic
            string    configFile = "../data/Config/cSpell.properties";
            CSpellApi cSpellApi  = new CSpellApi(configFile);
            WordWcMap wordWcMap  = cSpellApi.GetWordWcMap();
            double    wf1        = cSpellApi.GetOrthoScoreEdDistFac();
            double    wf2        = cSpellApi.GetOrthoScorePhoneticFac();
            double    wf3        = cSpellApi.GetOrthoScoreOverlapFac();

            cSpellApi.SetRankMode(CSpellApi.RANK_MODE_NOISY_CHANNEL);
            // provide cmdLine interface
            int returnValue = 0;
            NoisyChannelScoreComparator <NoisyChannelScore> ncsc = new NoisyChannelScoreComparator <NoisyChannelScore>();

            try {
                StreamReader stdInput = new StreamReader(Console.OpenStandardInput());
                try {
                    string inText = null;
                    Console.WriteLine("- Please input a text (type \"Ctl-d\" to quit) > ");
                    while (!string.ReferenceEquals((inText = stdInput.ReadLine()), null))
                    {
                        // ---------------------------------
                        // Get spell correction on the input
                        // ---------------------------------
                        // get all possible candidates
                        HashSet <string> candSet = NonWord1To1Candidates.GetCandidates(inText, cSpellApi);
                        Console.WriteLine("-- canSet.size(): " + candSet.Count);
                        // get final suggestion
                        string topRankStr = GetTopRankStr(inText, candSet, wordWcMap, wf1, wf2, wf3);
                        Console.WriteLine("- top tank str: " + topRankStr);
                        // print details
                        if (detailFlag == true)
                        {
                            HashSet <NoisyChannelScore> candScoreSet = GetCandidateScoreSet(inText, candSet, wordWcMap, wf1, wf2, wf3);
                            Console.WriteLine("------ Suggestion List ------");
                            var list = candScoreSet.OrderBy(x => x, ncsc).Take((int)limitNo).Select(obj => obj.ToString()).ToList();
                            foreach (var item in list)
                            {
                                Console.WriteLine(item);
                            }
                        }
                    }
                } catch (Exception e2) {
                    Console.Error.WriteLine(e2.Message);
                    returnValue = -1;
                }
            } catch (Exception e) {
                Console.Error.WriteLine(e.Message);
                returnValue = -1;
            }
            return(returnValue);
        }
コード例 #3
0
 public static void PrintNoisyChannelScore(string inStr, HashSet <string> candSet, WordWcMap wordWcMap, int maxCandNo, double wf1, double wf2, double wf3, bool debugFlag)
 {
     if (debugFlag == true)
     {
         NoisyChannelScoreComparator <NoisyChannelScore> ncsc = new NoisyChannelScoreComparator <NoisyChannelScore>();
         HashSet <NoisyChannelScore> ncScoreSet = RankByNoisyChannel.GetCandidateScoreSet(inStr, candSet, wordWcMap, wf1, wf2, wf3);
         var list = ncScoreSet.OrderBy(x => x, ncsc).Take(maxCandNo).Select(obj => obj.ToString()).ToList();
         foreach (var item in list)
         {
             DebugPrint.PrintNScore(item, debugFlag);
         }
     }
 }
コード例 #4
0
        // by combination, O, N, F, C
        private int compareByCombo(CSpellScore o1, CSpellScore o2)
        {
            int @out = 0;
            OrthographicScore oScore1 = ((CSpellScore)o1).GetOScore();
            OrthographicScore oScore2 = ((CSpellScore)o2).GetOScore();
            NoisyChannelScore nScore1 = ((CSpellScore)o1).GetNScore();
            NoisyChannelScore nScore2 = ((CSpellScore)o2).GetNScore();
            FrequencyScore    fScore1 = ((CSpellScore)o1).GetFScore();
            FrequencyScore    fScore2 = ((CSpellScore)o2).GetFScore();
            ContextScore      cScore1 = ((CSpellScore)o1).GetCScore();
            ContextScore      cScore2 = ((CSpellScore)o2).GetCScore();

            // 1. compared by orthographic score, best
            if (oScore1.GetScore() != oScore2.GetScore())
            {
                OrthographicScoreComparator <OrthographicScore> osc = new OrthographicScoreComparator <OrthographicScore>();
                @out = osc.Compare(oScore1, oScore2);
            }
            // 2. compared by noise channel score, 2nd best
            else if (nScore1.GetScore() != nScore2.GetScore())
            {
                NoisyChannelScoreComparator <NoisyChannelScore> nsc = new NoisyChannelScoreComparator <NoisyChannelScore>();
                @out = nsc.Compare(nScore1, nScore2);
            }
            // 3. compared by pure frequency score, 3rd best
            else if (fScore1.GetScore() != fScore2.GetScore())
            {
                FrequencyScoreComparator <FrequencyScore> fsc = new FrequencyScoreComparator <FrequencyScore>();
                @out = fsc.Compare(fScore1, fScore2);
            }
            // 4. compared by context score, 4 last
            else if (cScore1.GetScore() != cScore2.GetScore())
            {
                ContextScoreComparator <ContextScore> csc = new ContextScoreComparator <ContextScore>();
                @out = csc.Compare(cScore1, cScore2);
            }
            // 5. alphabetic order
            else
            {
                string cand1 = ((CSpellScore)o1).GetCandStr();
                string cand2 = ((CSpellScore)o2).GetCandStr();
                @out = cand2.CompareTo(cand1);
            }
            return(@out);
        }