def test_term_frequency_for(self): document_tokens = ["cisco", "router", "cisco", "switch"] frequencies = WeighingMeasure.term_frequency_for(document_tokens) self.assertEqual(len(frequencies.keys()), 3) self.assertEqual(frequencies["cisco"], 2) self.assertEqual(frequencies["router"], 1)
def term_frequencies(self): if len(self.term_frequency) == 0: self.term_frequency = WeighingMeasure.term_frequency_for(self.all_tokens()) return self.term_frequency