def test_float_items_count(): count = ItemsCount(3.5) returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) assert returned == [0, 1, 2] count = ItemsCount(True) returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) assert returned == [0] count = ItemsCount(False) returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) assert returned == []
def test_float_items_count(self): count = ItemsCount(3.5) returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) self.assertEqual(returned, [0, 1, 2]) count = ItemsCount(True) returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) self.assertEqual(returned, [0]) count = ItemsCount(False) returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) self.assertEqual(returned, [])
def handle_arguments(): document_format = "plaintext" sourceFile = raw_input("Enter Soruce file path \n") if sourceFile is not None: parser = PARSERS.get(document_format, PlaintextParser) with open(sourceFile, "rb") as file: document_content = file.read() else: parser = PARSERS["plaintext"] document_content = sys.stdin.read() summarizer_builder = AVAILABLE_METHODS["1"] method = AVAILABLE_METHODS[raw_input( "Select Algorithm \n press 1 and enter for luhn. \n press 2 and enter for lsa. \n press 3 and enter for lex-rank. \n press 4 and enter for text-rank. \n press 5 and enter for sum-basic.\n press 6 and enter for kl.\n press 0 and enter to exit. \n" )] for method, builder in AVAILABLE_METHODS.items(): if method: summarizer_builder = builder break items_count = ItemsCount(25) parser = parser(document_content, Tokenizer(language)) reference_summary = raw_input("Enter reference_summary file with path \n") with open(reference_summary, "r") as file: reference_summmary = file.read().decode("utf-8") return summarizer_builder( parser, language), parser.document, items_count, reference_summmary
def test_percentage_items_count(self): count = ItemsCount("20%") returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) self.assertEqual(returned, [0, 1]) count = ItemsCount("100%") returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) self.assertEqual(returned, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) count = ItemsCount("50%") returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) self.assertEqual(returned, [0, 1, 2, 3, 4]) count = ItemsCount("30%") returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) self.assertEqual(returned, [0, 1, 2]) count = ItemsCount("35%") returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) self.assertEqual(returned, [0, 1, 2])
def test_percentage_items_count(): count = ItemsCount("20%") returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) assert returned == [0, 1] count = ItemsCount("100%") returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) assert returned == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] count = ItemsCount("50%") returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) assert returned == [0, 1, 2, 3, 4] count = ItemsCount("30%") returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) assert returned == [0, 1, 2] count = ItemsCount("35%") returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) assert returned == [0, 1, 2]
def summarize(method, length, url): html_content = fetch_url(url) iso_lang = detect_language(html_content) language = SUMY_LANGUAGES[iso_lang] stemmer = Stemmer(language) parser = HtmlParser.from_string(html_content, url, Tokenizer(language)) summarizer_class = AVAILABLE_METHODS[method] summarizer = build_summarizer(summarizer_class, get_stop_words(language), stemmer, parser) sentences = summarizer(parser.document, ItemsCount(length)) summary = ' '.join([unicode(sentence) for sentence in sentences]) return summary, iso_lang
def test_unsuported_items_count(self): count = ItemsCount("Hacker") self.assertRaises(ValueError, count, [])
def test_unsupported_items_count(): count = ItemsCount("Hacker") with pytest.raises(ValueError): count([])
def test_supported_items_count(amount, expected_result): count = ItemsCount(amount) returned = count([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) assert returned == expected_result