MCPcopy Index your code
hub / github.com/clips/pattern / keywords

Method keywords

pattern/vector/__init__.py:565–572  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 3

02-model.pyFile · 0.80
01-document.pyFile · 0.80

Calls 3

sumFunction · 0.85
itervaluesMethod · 0.80
iteritemsMethod · 0.80

Tested by 1