Returns a sorted list of (relevance, word)-tuples that are top keywords in the document. With normalized=True, weights are normalized between 0.0 and 1.0 (their sum will be 1.0).
(self, top=10, normalized=True)
| 563 | return self._vector |
| 564 | |
| 565 | def keywords(self, top=10, normalized=True): |
| 566 | """ Returns a sorted list of (relevance, word)-tuples that are top keywords in the document. |
| 567 | With normalized=True, weights are normalized between 0.0 and 1.0 (their sum will be 1.0). |
| 568 | """ |
| 569 | n = normalized and sum(self.vector.itervalues()) or 1.0 |
| 570 | v = ((f/n, w) for w, f in self.vector.iteritems()) |
| 571 | v = heapq.nsmallest(top, v, key=lambda v: (-v[0], v[1])) |
| 572 | return v |
| 573 | |
| 574 | def cosine_similarity(self, document): |
| 575 | """ Returns the similarity between the two documents as a number between 0.0-1.0. |