Beispiel #1
0
 def test_make_frequencies(self):
     """Test frequency builder."""
     frequencies = Frequency()
     text = 'Quo Quo Quo Quo usque tandem abutere, Catilina Catilina Catilina, patientia nostra nostra ?'.lower()
     count = frequencies.counter_from_str(text)
     target = Counter({'quo': 4, 'catilina': 3, 'nostra': 2, 'patientia': 1, 'abutere': 1, 'usque': 1, 'tandem': 1})
     self.assertEqual(count, target)
Beispiel #2
0
 def test_make_frequencies(self):
     """Test frequency builder."""
     frequencies = Frequency()
     text = 'Quo Quo Quo Quo usque tandem abutere, Catilina Catilina Catilina, patientia nostra nostra ?'.lower()
     count = frequencies.counter_from_str(text)
     target = Counter({'quo': 4, 'catilina': 3, 'nostra': 2, 'patientia': 1, 'abutere': 1, 'usque': 1, 'tandem': 1})
     self.assertEqual(count, target)
Beispiel #3
0
 def test_make_frequencies(self):
     """Test frequency builder."""
     frequencies = Frequency()
     text = "Quo Quo Quo Quo usque tandem abutere, Catilina Catilina Catilina, patientia nostra nostra ?".lower()
     count = frequencies.counter_from_str(text)
     target = Counter({"quo": 4, "catilina": 3, "nostra": 2, "patientia": 1, "abutere": 1, "usque": 1, "tandem": 1})
     self.assertEqual(count, target)
Beispiel #4
0
 def word_count(self, word=None, mode='cltk'):
     if mode == 'nltk':
         counts = dict(Text(self.tokenize()).vocab())
     else:
         counts = Frequency().counter_from_str(self.data)
     # If a single word was specified, only return that frequency
     if word:
         return counts[word]
     return counts
Beispiel #5
0
    def word_count(self, word=None):
        """Returns counter dictionary with word counts at respective keywords.

        Performs word counts and then stores their values in the respective
        keyword of a counter dictionary. If a word is passed, a simple integer
        count of the number of appearances is returned.

        Args:
            word (:obj:`string`, optional) A single word you want to count

        Returns:
            :obj:`dict` A dictionary with word counts stored in respective keywords

        Example:
            >>> text = LatinText('Gallia est omnis divisa in partes tres tres tres')
            >>> print(text.word_count(word='tres'))
            3
        """ # noqa
        from cltk.utils.frequency import Frequency
        counts = Frequency().counter_from_str(self.data)
        # If a single word was specified, only return that frequency
        if word:
            return counts[word]
        return counts
Beispiel #6
0
 def test_make_list_from_corpus_assert(self):
     """Test frequency builder for corpus, if present."""
     frequencies = Frequency()
     with self.assertRaises(AssertionError):
         frequencies.counter_from_corpus('xxx')
Beispiel #7
0
 def test_make_list_from_corpus_assert(self):
     """Test frequency builder for corpus, if present."""
     frequencies = Frequency()
     with self.assertRaises(AssertionError):
         frequencies.counter_from_corpus('xxx')