Esempio n. 1
0
 def test_prepare_drop_hyphen_and_apostrophe_at_start_or_end_word(self):
     self.stream = StringIO(
         'date some- \'text ’date text'
     )
     dic = DictionaryForText(self.stream)
     words = dic.prepare()
     self.assertEqual({'some': 1, 'text': 2, 'date': 2}, words)
Esempio n. 2
0
 def test_get_content(self):
     # stream = open("myfile.txt", "r", encoding="utf-8")
     # stream = io.StringIO("some initial text data")
     text = 'Some text date.'
     self.stream = StringIO(text)
     dic = DictionaryForText(self.stream)
     self.assertEqual(text, dic.text)
Esempio n. 3
0
 def test_prepare_simple(self):
     self.stream = StringIO('text date \nand more text')
     dic = DictionaryForText(self.stream)
     self.assertEqual(
         {'text': 2, 'date': 1, 'and': 1, 'more': 1},
         dic.prepare()
     )
Esempio n. 4
0
    def test_get_content_after_close_stream(self):
        text = 'Some text date.'
        self.stream = StringIO(text)
        dic = DictionaryForText(self.stream)
        self.stream.close()

        self.assertEqual(text, dic.text)
Esempio n. 5
0
    def test_prepare_text_drop_short_words(self):
        self.stream = StringIO(
            'cat is a word'
        )
        dic = DictionaryForText(self.stream)
        words = dic.prepare()
        self.assertEqual({'cat': 1, 'word': 1}, words)

        self.assertEqual({'is': 1, 'a': 1}, dic.get_drop_short())
Esempio n. 6
0
 def test_prepare_text_with_punctuation_mark_at_end(self):
     self.stream = StringIO(
         'text, date. and? more! text: text; text…; text — text.'
     )
     dic = DictionaryForText(self.stream)
     self.assertEqual(
         {'text': 6, 'date': 1, 'and': 1, 'more': 1},
         dic.prepare()
     )
Esempio n. 7
0
 def test_prepare_drop_end_apostrophe_s(self):
     self.stream = StringIO('that cat and this cat are cat\'s cats')
     dic = DictionaryForText(self.stream)
     words = dic.prepare()
     self.assertEqual(
         {'that': 1, 'cat': 4, 'and': 1, 'this': 1, 'are': 1},
         words
     )
     self.assertEqual({'cat\'s': 'cat'}, dic.get_drop_end_apostrophe_s())
Esempio n. 8
0
 def test_prepare_drop_end_s(self):
     self.stream = StringIO('two cats are cat and cat')
     dic = DictionaryForText(self.stream)
     words = dic.prepare()
     self.assertEqual(
         {'two': 1, 'cat': 3, 'are': 1, 'and': 1},
         words
     )
     self.assertEqual({'cats': 'cat'}, dic.get_drop_end_s())
Esempio n. 9
0
 def test_prepare_drop_proper_name(self):
     self.stream = StringIO('Two cats are two tails, Murzik and Venik.')
     dic = DictionaryForText(self.stream)
     words = dic.prepare()
     self.assertEqual(
         {'two': 2, 'cats': 1, 'are': 1, 'tails': 1, 'and': 1},
         words
     )
     self.assertEqual({'Murzik': 1, 'Venik': 1}, dic.get_drop_proper_name())
Esempio n. 10
0
 def test_prepare_text_with_punctuation_marks_and_other_symbols(self):
     self.stream = StringIO('''
         text, «date». and? {more}! [text]: "text"; text…; (text)
         “text” — text 2date
     ''')
     dic = DictionaryForText(self.stream)
     self.assertEqual(
         {'text': 7, 'date': 2, 'and': 1, 'more': 1},
         dic.prepare()
     )
Esempio n. 11
0
 def test_prepare_drop_end_es(self):
     self.stream = StringIO(
         'classes are object of class class'
     )
     dic = DictionaryForText(self.stream)
     words = dic.prepare()
     self.assertEqual(
         {'are': 1, 'object': 1, 'class': 3},
         words
     )
     self.assertEqual({'classes': 'class'}, dic.get_drop_end_es())
Esempio n. 12
0
 def test_prepare_drop_end_ed(self):
     self.stream = StringIO(
         'the call called. create it. it will be created.'
     )
     dic = DictionaryForText(self.stream)
     words = dic.prepare()
     self.assertEqual(2, words['call'])
     self.assertEqual(2, words['create'])
     self.assertFalse('called' in words)
     self.assertFalse('created' in words)
     self.assertEqual(
         {'called': 'call', 'created': 'create'}, dic.get_drop_end_ed()
     )
Esempio n. 13
0
    def test_prepare_drop_end_ing(self):
        self.stream = StringIO(
            'th the thing are running during I am run too. Music is dur'
        )
        dic = DictionaryForText(self.stream)
        words = dic.prepare()
        self.assertEqual(1, words['thing'])
        self.assertEqual(1, words['during'])
        self.assertEqual(2, words['run'])

        self.assertFalse('running' in words)
        self.assertEqual(
            {'running': 'run'}, dic.get_drop_end_ing()
        )
Esempio n. 14
0
 def test_prepare_drop_end_ies(self):
     self.stream = StringIO(
         'those goodies are one goody for you and one one for you'
     )
     dic = DictionaryForText(self.stream)
     words = dic.prepare()
     self.assertEqual(
         {
             'those': 1, 'are': 1, 'one': 3, 'goody': 2, 'for': 2,
             'you': 2, 'and': 1
         },
         words
     )
     self.assertEqual({'goodies': 'goody'}, dic.get_drop_end_ies())