Esempio n. 1
0
    def test_analyzes_internals_results_processed(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)
        analyzer.analyze()

        assert analyzer.analyzes_results() == [
            result.results for result in analyzer.internal_results
        ]
Esempio n. 2
0
    def test_analyze_processed_multiples_times(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)

        assert analyzer.processed is False
        assert analyzer.analyze()  # First analyze
        assert analyzer.processed is True
        assert analyzer.analyze() is None
        assert analyzer.analyze() is None
Esempio n. 3
0
    def test_analyzes_results_processed(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)
        analyzer.analyze()

        processed_status = [
            an.result.processed for an in analyzer.analyzes_results()
        ]

        assert processed_status == [True, True, True, True]
Esempio n. 4
0
    def test_analyzes_results_raw_word(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)
        analyzer.analyze()

        words = [
            analyze.result.raw_word for analyze in analyzer.analyzes_results()
        ]

        assert words == ['Mi', 'loĝas', 'en', 'Brazilo']
Esempio n. 5
0
    def test_analyzes_results_word_class(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)
        analyzer.analyze()

        words_classes = [
            an.result.word_class() for an in analyzer.analyzes_results()
        ]

        assert words_classes == [Pronoun, Verb, Preposition, Noun]
Esempio n. 6
0
    def test_format_table_data_without_formating(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)
        analyzer.analyze()

        expected = [['Mi', 'Pronoun'], ['loĝas', 'Verb'],
                    ['en', 'Preposition'], ['Brazilo', 'Noun']]

        assert CLI.format_table_data(analyzer.simple_results(),
                                     colorize=False) == expected
Esempio n. 7
0
    def test_format_table_data_with_formating(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)
        analyzer.analyze()

        expected = [['\x1b[96mMi \x1b[0m', '\x1b[96mPronoun \x1b[0m'],
                    ['\x1b[31mloĝas \x1b[0m', '\x1b[31mVerb \x1b[0m'],
                    ['\x1b[36men \x1b[0m', '\x1b[36mPreposition \x1b[0m'],
                    ['\x1b[34mBrazilo \x1b[0m', '\x1b[34mNoun \x1b[0m']]

        assert CLI.format_table_data(analyzer.simple_results()) == expected
Esempio n. 8
0
    def test_print_results(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)
        analyzer.analyze()

        output = StringIO()

        # Execute the method that will write to `output`
        CLI.print_results(analyzer.simple_results(), output=output)

        assert output.getvalue() == self.EXPECT_OUTPUT_TEST_SENTENCE
Esempio n. 9
0
    def test_analyzes_results_word_classnames(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)
        analyzer.analyze()

        result_classes = [
            analyze.result.word.__class__.__name__
            for analyze in analyzer.analyzes_results()
        ]

        assert result_classes == ['Pronoun', 'Verb', 'Preposition', 'Noun']
Esempio n. 10
0
    def get(self):
        """Return a MorphologicalAnalyzeResult object"""
        sentence = request.args['sentence']

        if not sentence:
            raise SentenceRequiredError()

        analyzer = MorphologicalSentenceAnalyzer(sentence=sentence)
        analyzer.analyze()

        return self._format_results(analyzer.results())
Esempio n. 11
0
    def test_analyze_internal_results_class(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)
        analyzer.analyze()

        classes_names = [
            an.__class__.__name__ for an in analyzer.internal_results
        ]

        assert classes_names == [
            'MorphologicalAnalyzer', 'MorphologicalAnalyzer',
            'MorphologicalAnalyzer', 'MorphologicalAnalyzer'
        ]
Esempio n. 12
0
    def test_analyzes_results_class(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)
        analyzer.analyze()

        classes_names = [
            analyze.__class__.__name__
            for analyze in analyzer.analyzes_results()
        ]

        assert classes_names == [
            'AnalyzeResult', 'AnalyzeResult', 'AnalyzeResult', 'AnalyzeResult'
        ]
Esempio n. 13
0
    def test_undefined_token(self):
        analyzer = MorphologicalSentenceAnalyzer('Mia asdiosdsds')
        analyzer.analyze()

        assert analyzer.simple_results() == [['Mia', 'Pronoun'],
                                             ['asdiosdsds', 'Undefined']]
        assert analyzer.simple_results()[1][1] == 'Undefined'
Esempio n. 14
0
    def test_display_output_for_analyzer_without_executing(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)

        with pytest.raises(AnalyzerNotProcessedError):
            CLI.display_output_for_analyzer(analyzer)
Esempio n. 15
0
    def test_analyzes_results_not_processed(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)

        assert analyzer.analyzes_results() is None
Esempio n. 16
0
    def test_analyze_processed(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)

        assert analyzer.processed is False
        assert analyzer.analyze()
        assert analyzer.processed is True
Esempio n. 17
0
 def test_initialize(self):
     assert MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)
Esempio n. 18
0
    def test_analyze_results(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)

        assert analyzer.analyze()
        assert analyzer.results() is not None
Esempio n. 19
0
    def test_initialize_results(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)

        assert analyzer.results() is None
Esempio n. 20
0
    def test_initialize_sentence_words(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)

        assert analyzer.sentence_words == ['Mi', 'loĝas', 'en', 'Brazilo']
Esempio n. 21
0
    def test_initialize_sentence(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)

        assert analyzer.sentence is self.TEST_SENTENCE
Esempio n. 22
0
    def test_initialize_processed(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)

        assert analyzer.processed is False
Esempio n. 23
0
    def test_analyze_results_size(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)

        assert analyzer.analyze()
        assert len(analyzer.results()) == 4
        assert len(analyzer.results()[1]) == 2
Esempio n. 24
0
    def run(input_sentence=None, output=sys.stdout):
        analyzer = MorphologicalSentenceAnalyzer(input_sentence)
        analyzer.analyze()

        CLI.display_output_for_analyzer(analyzer, output=output)
Esempio n. 25
0
    def test_analyze(self):
        analyzer = MorphologicalSentenceAnalyzer(self.TEST_SENTENCE)

        assert analyzer.analyze()