Exemple #1
0
        private int compareByEnsemble(CSpellScore o1, CSpellScore o2)
        {
            int @out = 0;
            OrthographicScore oScore1 = ((CSpellScore)o1).GetOScore();
            OrthographicScore oScore2 = ((CSpellScore)o2).GetOScore();
            FrequencyScore    fScore1 = ((CSpellScore)o1).GetFScore();
            FrequencyScore    fScore2 = ((CSpellScore)o2).GetFScore();
            ContextScore      cScore1 = ((CSpellScore)o1).GetCScore();
            ContextScore      cScore2 = ((CSpellScore)o2).GetCScore();
            double            score1  = 0.6 * oScore1.GetScore() + 0.25 * fScore1.GetScore() + 0.15 * cScore1.GetScore();
            double            score2  = 0.6 * oScore2.GetScore() + 0.25 * fScore2.GetScore() + 0.15 * cScore2.GetScore();

            // 1. compared by orthographic score, best
            // SCR-2: use a fixed number to ensure result is not 0.
            if (score2 > score1)
            {
                // from high to low
                @out = 1;
            }
            else if (score2 < score1)
            {
                @out = -1;
            }
            // 2. alphabetic order
            else
            {
                string cand1 = ((CSpellScore)o1).GetCandStr();
                string cand2 = ((CSpellScore)o2).GetCandStr();
                @out = cand2.CompareTo(cand1);
            }
            return(@out);
        }
Exemple #2
0
        /// <summary>
        /// Compare two object o1 and o2.  Both objects o1 and o2 are
        /// CSpellScore.  The compare algorithm:
        /// </summary>
        /// <param name="o1">  first object to be compared </param>
        /// <param name="o2">  second object to be compared
        /// </param>
        /// <returns>  a negative integer, 0, or positive integer to represent the
        ///          object o1 is less, equals, or greater than object 02. </returns>
        public virtual int Compare(CSpellScore o1, CSpellScore o2)
        {
            OrthographicScoreComparator <OrthographicScore> osc = new OrthographicScoreComparator <OrthographicScore>();
            OrthographicScore oScore1 = ((CSpellScore)o1).GetOScore();
            OrthographicScore oScore2 = ((CSpellScore)o2).GetOScore();
            int @out = osc.Compare(oScore1, oScore2);

            // the following code are simplfied by above
            // We still keep this java file in case we need better implementation
            // in the future
            /// <summary>
            /// int out = 0;
            /// // 1. compared by orthographic score, best
            /// OrthographicScore oScore1 = ((CSpellScore) o1).GetOScore();
            /// OrthographicScore oScore2 = ((CSpellScore) o2).GetOScore();
            /// if(oScore1.GetScore() != oScore2.GetScore())
            /// {
            ///    OrthographicScoreComparator<OrthographicScore> osc
            ///        = new OrthographicScoreComparator<OrthographicScore>();
            ///    out = osc.compare(oScore1, oScore2);
            /// }
            /// else
            /// {
            ///    String cand1 = ((CSpellScore) o1).GetCandStr();
            ///    String cand2 = ((CSpellScore) o2).GetCandStr();
            ///    out = cand2.compareTo(cand1);
            /// }
            ///
            /// </summary>
            return(@out);
        }
Exemple #3
0
        /// <summary>
        /// Compare two object o1 and o2.  Both objects o1 and o2 are
        /// NoisyChannelScore.  The compare algorithm:
        /// </summary>
        /// <param name="o1">  first object to be compared </param>
        /// <param name="o2">  second object to be compared
        /// </param>
        /// <returns>  a negative integer, 0, or positive integer to represent the
        ///          object o1 is less, equals, or greater than object 02. </returns>
        public virtual int Compare(NoisyChannelScore o1, NoisyChannelScore o2)
        {
            // 1. compare how many words for the candidates
            // for now, we assume less word is better,
            // i.e. whatever is better than "what ever"
            int    @out    = 0;
            string cand1   = ((NoisyChannelScore)o1).GetCandStr();
            string cand2   = ((NoisyChannelScore)o2).GetCandStr();
            int    wordNo1 = TermUtil.GetWordNo(cand1);
            int    wordNo2 = TermUtil.GetWordNo(cand2);

            if (wordNo1 != wordNo2)
            {
                @out = wordNo1 - wordNo2;                 // less wordNo has higher rank
            }
            else
            {
                // 2. compare noisy Channel score
                double score1 = ((NoisyChannelScore)o1).GetScore();
                double score2 = ((NoisyChannelScore)o2).GetScore();
                // SCR-2: use a fixed number to ensure result is not 0.
                if (score2 > score1)
                {
                    // from high to low
                    @out = 1;
                }
                else if (score2 < score1)
                {
                    @out = -1;
                }
                else
                {
                    // 3. compare by orthographic score
                    OrthographicScore oScore1 = ((NoisyChannelScore)o1).GetOScore();
                    OrthographicScore oScore2 = ((NoisyChannelScore)o2).GetOScore();
                    if (oScore1.GetScore() != oScore2.GetScore())
                    {
                        OrthographicScoreComparator <OrthographicScore> osc = new OrthographicScoreComparator <OrthographicScore>();
                        @out = osc.Compare(oScore1, oScore2);
                    }
                    else                         // 4. hannelScore
                    {
                        FrequencyScore fScore1 = ((NoisyChannelScore)o1).GetFScore();
                        FrequencyScore fScore2 = ((NoisyChannelScore)o2).GetFScore();
                        if (fScore1.GetScore() != fScore2.GetScore())
                        {
                            FrequencyScoreComparator <FrequencyScore> fsc = new FrequencyScoreComparator <FrequencyScore>();
                            @out = fsc.Compare(fScore1, fScore2);
                        }
                        else                             // 4. alphabetic order
                        {
                            @out = cand2.CompareTo(cand1);
                        }
                    }
                }
            }
            return(@out);
        }
Exemple #4
0
        // private method
        private static void Test(string srcStr, string tarStr)
        {
            double            wf1 = 1.00;  // weighting factor
            double            wf2 = 0.70;
            double            wf3 = 0.80;
            OrthographicScore os  = new OrthographicScore(srcStr, tarStr, wf1, wf2, wf3);

            Console.WriteLine(os.ToString());
        }
Exemple #5
0
 // private constructor
 public NoisyChannelScore(string wordStr, string candStr, WordWcMap wordWcMap, double wf1, double wf2, double wf3)
 {
     wordStr_ = wordStr;
     candStr_ = candStr;
     // calculate score
     oScore_ = new OrthographicScore(wordStr_, candStr_, wf1, wf2, wf3);
     fScore_ = new FrequencyScore(candStr_, wordWcMap);
     score_  = oScore_.GetScore() * fScore_.GetScore();
 }
 // private constructor
 public CSpellScore(string wordStr, string candStr, WordWcMap wordWcMap, DoubleVec contextVec, Word2Vec word2Vec, double wf1, double wf2, double wf3)
 {
     wordStr_ = wordStr;
     candStr_ = candStr;
     // calculate score
     oScore_ = new OrthographicScore(wordStr_, candStr_, wf1, wf2, wf3);
     fScore_ = new FrequencyScore(candStr_, wordWcMap);
     nScore_ = new NoisyChannelScore(wordStr_, candStr_, wordWcMap, wf1, wf2, wf3);
     cScore_ = new ContextScore(candStr_, contextVec, word2Vec);
 }
        // return candidate set with orthographic score
        // inStr is the srcTxt used to calculate the score between it and cand
        public static HashSet <OrthographicScore> GetCandidateScoreSet(string inStr, HashSet <string> candidates, double wf1, double wf2, double wf3)
        {
            HashSet <OrthographicScore> candScoreSet = new HashSet <OrthographicScore>();

            foreach (string cand in candidates)
            {
                OrthographicScore os = new OrthographicScore(inStr, cand, wf1, wf2, wf3);
                candScoreSet.Add(os);
            }
            return(candScoreSet);
        }
Exemple #8
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);
        }
Exemple #9
0
        private int compareByOrthographics(CSpellScore o1, CSpellScore o2)
        {
            int @out = 0;
            OrthographicScore oScore1 = ((CSpellScore)o1).GetOScore();
            OrthographicScore oScore2 = ((CSpellScore)o2).GetOScore();

            // 1. compared by orthographic score, best
            if (oScore1.GetScore() != oScore2.GetScore())
            {
                OrthographicScoreComparator <OrthographicScore> osc = new OrthographicScoreComparator <OrthographicScore>();
                @out = osc.Compare(oScore1, oScore2);
            }
            // 2. alphabetic order
            else
            {
                string cand1 = ((CSpellScore)o1).GetCandStr();
                string cand2 = ((CSpellScore)o2).GetCandStr();
                @out = cand2.CompareTo(cand1);
            }
            return(@out);
        }
        /// <summary>
        /// Compare two object o1 and o2.  Both objects o1 and o2 are
        /// OrthographicScore.  The compare algorithm:
        /// </summary>
        /// <param name="o1">  first object to be compared </param>
        /// <param name="o2">  second object to be compared
        /// </param>
        /// <returns>  a negative integer, 0, or positive integer to represent the
        ///          object o1 is less, equals, or greater than object 02. </returns>
        public virtual int Compare(OrthographicScore o1, OrthographicScore o2)
        {
            // 1. compare total score first
            double score1 = ((OrthographicScore)o1).GetScore();
            double score2 = ((OrthographicScore)o2).GetScore();
            int    @out   = 0;

            // SCR-2: use a fixed number to ensure result is not 0.
            if (score2 > score1)
            {
                // from high to low
                //out = (int) (1000*(score2-score1)); might result 0
                @out = 1;
            }
            else if (score2 < score1)
            {
                @out = -1;
            }
            else
            {
                // 2. compare edit score
                double tokenScore1 = ((OrthographicScore)o1).GetTokenScore();
                double tokenScore2 = ((OrthographicScore)o2).GetTokenScore();
                // SCR-2: use a fixed number to ensure result is not 0.
                if (tokenScore2 > tokenScore1)
                {
                    @out = 1;
                }
                if (tokenScore2 < tokenScore1)
                {
                    @out = -1;
                }
                else
                {
                    // 3. compare phoneticScore
                    double pScore1 = ((OrthographicScore)o1).GetPhoneticScore();
                    double pScore2 = ((OrthographicScore)o2).GetPhoneticScore();
                    // SCR-2: use a fixed number to ensure result is not 0.
                    if (pScore2 > pScore1)
                    {
                        @out = 1;
                    }
                    else if (pScore2 < pScore1)
                    {
                        @out = -1;
                    }
                    else
                    {
                        double oScore1 = ((OrthographicScore)o1).GetOverlapScore();
                        double oScore2 = ((OrthographicScore)o2).GetOverlapScore();
                        // 4. compare overlap Score
                        // SCR-2: use a fixed number to ensure result is not 0.
                        if (oScore2 > oScore1)
                        {
                            @out = 1;
                        }
                        else if (oScore2 < oScore1)
                        {
                            @out = -1;
                        }
                        else                             // 5. Alphabetic order
                        {
                            string str1 = ((OrthographicScore)o1).GetTarStr();
                            string str2 = ((OrthographicScore)o2).GetTarStr();
                            @out = str2.CompareTo(str1);
                        }
                    }
                }
            }
            return(@out);
        }