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; } }
public void TermNotInDocuments() { double greenIdf = Math.Round(TFIDF.CalculateIDF(m_path, "green"), 5); TFIDF tfidf = new TFIDF(m_path); double greenIdfCached = Math.Round(tfidf.CacheCalculateIDF("green"), 5); double expectedIDF = Math.Round(1.58496250072116, 5); Assert.AreEqual(expectedIDF, greenIdf, "CalculateIDF returns incorrect value"); Assert.AreEqual(expectedIDF, greenIdfCached, "CacheCalculateIDF returns incorrect value"); }
public void TermInAllDocumentsIDFTest() { double heroIdf = TFIDF.CalculateIDF(m_path, "of"); TFIDF tfidf = new TFIDF(m_path); double heroIdfCached = tfidf.CacheCalculateIDF("of"); double expectedIDF = 0; Assert.AreEqual(expectedIDF, heroIdf, "CalculateIDF returns incorrect value"); Assert.AreEqual(expectedIDF, heroIdfCached, "CacheCalculateIDF returns incorrect value"); }
public void TermInSomeDocumentsIdfTest() { double heroIdf = TFIDF.CalculateIDF(m_path, "hero"); TFIDF tfidf = new TFIDF(m_path); double heroIdfCached = tfidf.CacheCalculateIDF("hero"); double expectedIDF = Math.Log((double)3 / (double)2, 2); Assert.AreEqual(expectedIDF, heroIdf, "CalculateIDF returns incorrect value"); Assert.AreEqual(expectedIDF, heroIdfCached, "CacheCalculateIDF returns incorrect value"); }
public void EmptyDirectoryTest() { string emptyDirectoryPath = m_path + "empty Directory"; Directory.CreateDirectory(emptyDirectoryPath); double idf = TFIDF.CalculateIDF(emptyDirectoryPath, "term"); TFIDF tfidf = new TFIDF(emptyDirectoryPath); double cacheIdf = tfidf.CacheCalculateIDF("term"); Assert.AreEqual(0, idf); Assert.AreEqual(0, cacheIdf); Directory.Delete(emptyDirectoryPath); }