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
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')