Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
        public void TermInFileTest()
        {
            double tfNoCache = TFIDF.CalculateTF(m_path, m_testFile, "data");
            TFIDF  tfidf     = new TFIDF(m_path);
            double tfCached  = tfidf.CacheCalculateTF(m_testFile, "data");

            Assert.AreEqual(0.125, tfNoCache);
            Assert.AreEqual(tfNoCache, tfCached);
        }
Exemplo n.º 3
0
        public void ArgumanetsValidationTest()
        {
            Assert.ThrowsException <ArgumentException>(() => TFIDF.CalculateTF("", "", ""));
            Assert.ThrowsException <ArgumentException>(() => TFIDF.CalculateTF("path", "filename", ""));
            Assert.ThrowsException <ArgumentException>(() => TFIDF.CalculateTF("path", "", "term"));
            Assert.ThrowsException <ArgumentException>(() => TFIDF.CalculateTF("", "filename", "term"));
            Assert.ThrowsException <ArgumentException>(() => TFIDF.CalculateTF("", "", "term"));
            Assert.ThrowsException <ArgumentException>(() => TFIDF.CalculateTF("", "filename", ""));
            Assert.ThrowsException <ArgumentException>(() => TFIDF.CalculateTF("path", "", ""));
            Assert.ThrowsException <FileNotFoundException>(() => TFIDF.CalculateTF("invalidPath", "invalidFile", "term"));
            Assert.ThrowsException <ArgumentException>(() => new TFIDF(""));
            Assert.ThrowsException <DirectoryNotFoundException>(() => new TFIDF("invalidPath"));

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

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