コード例 #1
0
        // ----------------------------------------------------------------------------------------
        /// <!-- CompareCommon -->
        /// <summary>
        ///      Compares two corpuses returning scores only for words in both
        /// </summary>
        /// <param name="myBible"></param>
        /// <param name="resumes"></param>
        /// <returns></returns>
        public static Dictionary <string, double> CompareCommon(Corpus myBible, Corpus resumes)
        {
            Dictionary <string, double> both  = new Dictionary <string, double>();
            Dictionary <string, double> maybe = new Dictionary <string, double>();

            foreach (string word in myBible.RegularWord.Keys)
            {
                maybe.Add(word, 1);
            }
            foreach (string word in resumes.RegularWord.Keys)
            {
                if (maybe.ContainsKey(word))
                {
                    both.Add(word, myBible.RegularWord[word] / resumes.RegularWord[word]);
                }
            }

            return(both);
        }
コード例 #2
0
        // ----------------------------------------------------------------------------------------
        /// <!-- Compare -->
        /// <summary>
        ///      Compares two corpuses
        /// </summary>
        /// <param name="corpusA"></param>
        /// <param name="corpusB"></param>
        /// <returns></returns>
        public static string Compare(Corpus corpusA, Corpus corpusB)
        {
            Dictionary <string, double> both    = Corpus.CompareCommon(corpusA, corpusB);
            Dictionary <string, double> thisOne = Corpus.CompareAll(corpusA, corpusB);


            List <string> corpusB_Both = Corpus.OrderWordsLowToHigh(both);
            List <string> corpusB_This = Corpus.OrderWordsLowToHigh(thisOne);
            List <string> corpusA_Both = Corpus.OrderWordsHighToLow(both);
            List <string> corpusA_This = Corpus.OrderWordsHighToLow(thisOne);


            int colWidth = 24;

            string str = (corpusB.TotalWords().ToString() + " words").PadRight(colWidth * 2)
                         + (corpusA.TotalWords().ToString() + " words").PadRight(colWidth * 2);

            str += "\r\n";
            str += (corpusB.DisplayName + "(both)").PadRight(colWidth)
                   + (corpusB.DisplayName + "(this)").PadRight(colWidth)
                   + (corpusA.DisplayName + "(both)").PadRight(colWidth)
                   + (corpusA.DisplayName + "(this)").PadRight(colWidth)
            ;

            str += "\r\n";
            str += "----------".PadRight(colWidth);
            str += "----------".PadRight(colWidth);
            str += "----------".PadRight(colWidth);
            str += "----------".PadRight(colWidth);

            for (int i = 0; i < 50; ++i)
            {
                str += "\r\n"
                       + corpusB_Both[i].PadRight(colWidth)
                       + corpusB_This[i].PadRight(colWidth)
                       + corpusA_Both[i].PadRight(colWidth)
                       + corpusA_This[i].PadRight(colWidth);
            }

            return(str);
        }