<s> from __future__ import absolute_import <EOL> from __future__ import division , print_function , unicode_literals <EOL> import unittest <EOL> from sumy . summarizers . text_rank import TextRankSummarizer <EOL> from sumy . nlp . stemmers import Stemmer <EOL> from sumy . _compat import to_unicode <EOL> from . . utils import build_document <EOL> class TestTextRank ( unittest . TestCase ) : <EOL> def test_empty_document ( self ) : <EOL> document = build_document ( ) <EOL> summarizer = TextRankSummarizer ( Stemmer ( "<STR_LIT>" ) ) <EOL> returned = summarizer ( document , <NUM_LIT:10> ) <EOL> self . assertEqual ( len ( returned ) , <NUM_LIT:0> ) <EOL> def test_single_sentence ( self ) : <EOL> document = build_document ( ( "<STR_LIT>" , ) ) <EOL> summarizer = TextRankSummarizer ( ) <EOL> summarizer . stop_words = ( "<STR_LIT:I>" , "<STR_LIT>" , ) <EOL> returned = summarizer ( document , <NUM_LIT:10> ) <EOL> self . assertEqual ( len ( returned ) , <NUM_LIT:1> ) <EOL> def test_two_sentences ( self ) : <EOL> document = build_document ( ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> summarizer = TextRankSummarizer ( ) <EOL> summarizer . stop_words = ( "<STR_LIT:I>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , ) <EOL> returned = summarizer ( document , <NUM_LIT:10> ) <EOL> self . assertEqual ( len ( returned ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( to_unicode ( returned [ <NUM_LIT:0> ] ) , "<STR_LIT>" ) <EOL> self . assertEqual ( to_unicode ( returned [ <NUM_LIT:1> ] ) , "<STR_LIT>" ) <EOL> def test_stop_words_correctly_removed ( self ) : <EOL> summarizer = TextRankSummarizer ( ) <EOL> summarizer . stop_words = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> document = build_document ( <EOL> ( "<STR_LIT>" , "<STR_LIT>" , ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , ) , <EOL> ) <EOL> sentences = document . sentences <EOL> expected = [ ] <EOL> returned = summarizer . _to_words_set ( sentences [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( expected , returned ) <EOL> returned = summarizer . _to_words_set ( sentences [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( expected , returned ) <EOL> returned = summarizer . _to_words_set ( sentences [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( expected , returned ) <EOL> returned = summarizer . _to_words_set ( sentences [ <NUM_LIT:3> ] ) <EOL> self . assertEqual ( expected , returned ) <EOL> expected = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> returned = summarizer . _to_words_set ( sentences [ <NUM_LIT:4> ] ) <EOL> self . assertEqual ( expected , returned ) <EOL> expected = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> returned = summarizer . _to_words_set ( sentences [ <NUM_LIT:5> ] ) <EOL> self . assertEqual ( expected , returned ) <EOL> def test_three_sentences_but_second_winner ( self ) : <EOL> document = build_document ( [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] ) <EOL> summarizer = TextRankSummarizer ( ) <EOL> summarizer . stop_words = [ "<STR_LIT:I>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> returned = summarizer ( document , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( returned ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( to_unicode ( returned [ <NUM_LIT:0> ] ) , "<STR_LIT>" ) <EOL> def test_sentences_rating ( self ) : <EOL> document = build_document ( [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] ) <EOL> summarizer = TextRankSummarizer ( ) <EOL> summarizer . stop_words = [ "<STR_LIT:I>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> ratings = summarizer . rate_sentences ( document ) <EOL> self . assertEqual ( len ( ratings ) , <NUM_LIT:3> ) <EOL> self . assertTrue ( ratings [ document . sentences [ <NUM_LIT:1> ] ] > ratings [ document . sentences [ <NUM_LIT:0> ] ] ) <EOL> self . assertTrue ( ratings [ document . sentences [ <NUM_LIT:0> ] ] > ratings [ document . sentences [ <NUM_LIT:2> ] ] ) </s>
