def test__same_text_correlation(self): """ Test that for same text correlation is 1""" _log.info('-'*80) # arrange text1 = "love is rain as long story short" text2 = text1 dump_file = getInputFile("swiki_knowledge_output.xml") parsed_file = getOutputFile("swiki_knowledge_output.parsed.xml") #wdb_file = getOutputFile("swiki_knowledge_output.wdb") articles = ['Rain', 'Love', 'Tree'] # act wn.make_dump(dump_file, articles, compress=False) wn.parse_dump(dump_file, parsed_file) db_wrapper = wn.build_database_wrapper(parsed_file, StopWordsStemmer([])) #self.addCleanup(os.remove, self.tmp_dump_file) comparer = SemanticComparer(db_wrapper) correlation = comparer.compare(text1, text2) _log.info(test_utils.get_texts_correlation_message(text1, text2, correlation)) self.assertAlmostEqual(correlation, 1.0, msg="for same text correlation should be 1")
def test__same_text_correlation(self): """ Test that for same text correlation is 1""" _log.info('-' * 80) # arrange text1 = "love is rain as long story short" text2 = text1 dump_file = getInputFile("swiki_knowledge_output.xml") parsed_file = getOutputFile("swiki_knowledge_output.parsed.xml") #wdb_file = getOutputFile("swiki_knowledge_output.wdb") articles = ['Rain', 'Love', 'Tree'] # act wn.make_dump(dump_file, articles, compress=False) wn.parse_dump(dump_file, parsed_file) db_wrapper = wn.build_database_wrapper(parsed_file, StopWordsStemmer([])) #self.addCleanup(os.remove, self.tmp_dump_file) comparer = SemanticComparer(db_wrapper) correlation = comparer.compare(text1, text2) _log.info( test_utils.get_texts_correlation_message(text1, text2, correlation)) self.assertAlmostEqual(correlation, 1.0, msg="for same text correlation should be 1")
def test__make_dump(self): #create the dump file article_title=["Rain"] articles_expected_set = set(article_title) wiki_knowledge.make_dump(self.tmp_dump_file,article_title) actual_titles_set = {wikidoc.title for wikidoc in parse_tools.iterate_wiki_pages(self.tmp_dump_file)} self.assertEqual(actual_titles_set, articles_expected_set, "title mismatch")
def test__make_dump(self): #create the dump file article_title = ["Rain"] articles_expected_set = set(article_title) wiki_knowledge.make_dump(self.tmp_dump_file, article_title) actual_titles_set = { wikidoc.title for wikidoc in parse_tools.iterate_wiki_pages(self.tmp_dump_file) } self.assertEqual(actual_titles_set, articles_expected_set, "title mismatch")
def test__execution(self): """ This is not exactly a test, but a program execution...""" text1 = "i love to learn" text2 = "the world we know" dump_file = self.tmp_dump_file wiki_knowledge.make_dump(dump_file, self.expected_articles, compress=False) wiki_knowledge.parse_dump(dump_file, self.tmp_parse_file) db_wrapper = wiki_knowledge.build_database_wrapper(self.tmp_parse_file, StopWordsStemmer([])) #wiki_knowledge = test_utils.Factory.build_wiki_knowledge() #clean up file created by factory at end self.addCleanup(os.remove, self.tmp_dump_file) comparer = semantic_interpreter.SemanticComparer(db_wrapper) correlation = comparer.compare(text1, text2) _log.info(test_utils.get_texts_correlation_message(text1, text2, correlation))
def test__execution(self): """ This is not exactly a test, but a program execution...""" text1 = "i love to learn" text2 = "the world we know" dump_file = self.tmp_dump_file wiki_knowledge.make_dump(dump_file, self.expected_articles, compress=False) wiki_knowledge.parse_dump(dump_file, self.tmp_parse_file) db_wrapper = wiki_knowledge.build_database_wrapper( self.tmp_parse_file, StopWordsStemmer([])) #wiki_knowledge = test_utils.Factory.build_wiki_knowledge() #clean up file created by factory at end self.addCleanup(os.remove, self.tmp_dump_file) comparer = semantic_interpreter.SemanticComparer(db_wrapper) correlation = comparer.compare(text1, text2) _log.info( test_utils.get_texts_correlation_message(text1, text2, correlation))
def makedump(args): _log.debug("run makedump with args={}".format(args)) wiki_knowledge.make_dump(args.dumpfile, args.article)