コード例 #1
0
        public void TfidfTest()
        {
            TFIDF  tfidf = new TFIDF(m_path);
            double tfidfJudeAndHeyJude      = Math.Round(TFIDF.CalculateTFIDF(m_path, m_testFile1, "jude"), 5);
            double cacheTfidfJudeAndHeyJude = Math.Round(tfidf.CacheCalculateTFIDF(m_testFile1, "jude"), 5);

            Assert.AreEqual(0.06891, tfidfJudeAndHeyJude);
            Assert.AreEqual(tfidfJudeAndHeyJude, cacheTfidfJudeAndHeyJude);

            double tfidfJudeAndHisGotTheWholeWorld      = Math.Round(TFIDF.CalculateTFIDF(m_path, m_testFile2, "jude"), 5);
            double cacheTfidfJudeAndHisGotTheWholeWorld = Math.Round(tfidf.CacheCalculateTFIDF(m_testFile2, "jude"), 5);

            Assert.AreEqual(0, tfidfJudeAndHisGotTheWholeWorld);
            Assert.AreEqual(0, cacheTfidfJudeAndHisGotTheWholeWorld);

            double tfidfWorldAndHeyJude      = Math.Round(TFIDF.CalculateTFIDF(m_path, m_testFile1, "world"), 5);
            double cacheTfidfWorldAndHeyJude = Math.Round(tfidf.CacheCalculateTFIDF(m_testFile1, "world"), 5);

            Assert.AreEqual(tfidfWorldAndHeyJude, cacheTfidfWorldAndHeyJude);

            double tfidfWorldAndHisGotTheWholeWorld      = Math.Round(TFIDF.CalculateTFIDF(m_path, m_testFile2, "world"), 5);
            double cacheTfidfWorldAndHisGotTheWholeWorld = Math.Round(tfidf.CacheCalculateTFIDF(m_testFile2, "world"), 5);

            Assert.AreEqual(tfidfWorldAndHisGotTheWholeWorld, cacheTfidfWorldAndHisGotTheWholeWorld);

            double tfidfWorldAndHealTheWorld      = Math.Round(TFIDF.CalculateTFIDF(m_path, m_testFile3, "world"), 5);
            double cacheTfidfWorldAndHealTheWorls = Math.Round(tfidf.CacheCalculateTFIDF(m_testFile3, "world"), 5);

            Assert.AreEqual(tfidfWorldAndHealTheWorld, cacheTfidfWorldAndHealTheWorls);
            Assert.IsTrue(tfidfWorldAndHisGotTheWholeWorld > tfidfWorldAndHealTheWorld && tfidfWorldAndHealTheWorld > tfidfWorldAndHeyJude);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: davidbinyamin/TFIDF
        private static void HandleRunCommand()
        {
            try
            {
                switch (m_useCache)
                {
                case true:
                    switch (m_command)
                    {
                    case Command.TF:
                        m_result = m_tfidf.CacheCalculateTF(m_fileName, m_term);
                        break;

                    case Command.IDF:
                        m_result = m_tfidf.CacheCalculateIDF(m_term);
                        break;

                    case Command.TFIDF:
                        m_result = m_tfidf.CacheCalculateTFIDF(m_fileName, m_term);
                        break;

                    default:
                        break;
                    }
                    break;

                case false:
                    switch (m_command)
                    {
                    case Command.TF:
                        m_result = TFIDF.CalculateTF(m_path, m_fileName, m_term);
                        break;

                    case Command.IDF:
                        m_result = TFIDF.CalculateIDF(m_path, m_term);
                        break;

                    case Command.TFIDF:
                        m_result = TFIDF.CalculateTFIDF(m_path, m_fileName, m_term);
                        break;

                    default:
                        break;
                    }
                    break;

                default:
                    break;
                }

                m_level = MenuLevel.ShowResult;
            }
            catch (Exception e)
            {
                Console.WriteLine("error: {0}", e.Message);
                Console.WriteLine("press any key to try again");
                Console.ReadKey();
                m_level = MenuLevel.SelectCommand;
            }
        }
コード例 #3
0
        public void ArgumanetsValidationTest()
        {
            Assert.ThrowsException <ArgumentException>(() => TFIDF.CalculateTFIDF("", "", ""));
            Assert.ThrowsException <ArgumentException>(() => TFIDF.CalculateTFIDF("path", "filename", ""));
            Assert.ThrowsException <ArgumentException>(() => TFIDF.CalculateTFIDF("path", "", "term"));
            Assert.ThrowsException <ArgumentException>(() => TFIDF.CalculateTFIDF("", "filename", "term"));
            Assert.ThrowsException <ArgumentException>(() => TFIDF.CalculateTFIDF("", "", "term"));
            Assert.ThrowsException <ArgumentException>(() => TFIDF.CalculateTFIDF("", "filename", ""));
            Assert.ThrowsException <ArgumentException>(() => TFIDF.CalculateTFIDF("path", "", ""));
            Assert.ThrowsException <FileNotFoundException>(() => TFIDF.CalculateTFIDF("invalidPath", "invalidFile", "term"));

            TFIDF tfidf = new TFIDF(Directory.GetCurrentDirectory());

            Assert.ThrowsException <ArgumentException>(() => tfidf.CacheCalculateTFIDF("", ""));
            Assert.ThrowsException <ArgumentException>(() => tfidf.CacheCalculateTFIDF("filename", ""));
            Assert.ThrowsException <ArgumentException>(() => tfidf.CacheCalculateTFIDF("", "term"));
            Assert.ThrowsException <FileNotFoundException>(() => tfidf.CacheCalculateTFIDF("filename", "term"));
        }