예제 #1
0
    def test_split_text_on_words(self):
        text = " While I pounded, weak  and weary. Over "
        proc = LineProcessor()
        all_words = proc.split_text_on_words(text)
        separators = [w for w in all_words if w.is_separator]
        words = [w for w in all_words if not w.is_separator]

        assert len(separators) == 8
        assert len(words) == 7
예제 #2
0
    def test_check_phrase_starts_with_phrase(self):
        text = 'While I pounded, weak and weary. Over many a quaint and curious volume of forgotten lore'
        proc = LineProcessor()
        words = proc.split_text_on_words(text)

        ret = proc.check_phrase_starts_with_phrase(words, 2, ['I', 'goat'])
        assert ret

        ret = proc.check_phrase_starts_with_phrase(words, 3, ['I', 'goat'])
        assert not ret

        ret = proc.check_phrase_starts_with_phrase(words, 6, ['I', 'weak'])
        assert ret

        ret = proc.check_phrase_starts_with_phrase(words, 6,
                                                   ['I', ['weak', 'and']])
        assert ret

        ret = proc.check_phrase_starts_with_phrase(words, 6,
                                                   ['I', ['weak', 'weary']])
        assert not ret