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

Method vector_space_search

pattern/vector/__init__.py:1060–1076  ·  view source on GitHub ↗

Returns related documents from the model as a list of (similarity, document)-tuples. The given words can be a string (one word), a list or tuple of words, or a Document.

(self, words=[], **kwargs)

Source from the content-addressed store, hash-verified

1058 similar = related = neighbors = nn = nearest_neighbors
1059
1060 def vector_space_search(self, words=[], **kwargs):
1061 """ Returns related documents from the model as a list of (similarity, document)-tuples.
1062 The given words can be a string (one word), a list or tuple of words, or a Document.
1063 """
1064 top = kwargs.pop("top", 10)
1065 if not isinstance(words, (list, tuple, Document)):
1066 words = [words]
1067 if not isinstance(words, Document):
1068 kwargs.setdefault("threshold", 0) # Same stemmer as other documents should be given.
1069 words = Document(" ".join(words), **kwargs)
1070 words._model = self # So we can calculate tf-idf.
1071 # Documents that are not in the model,
1072 # consisting only of words that are not in the model,
1073 # have no related documents in the model:
1074 if len([True for w in words if w in self.vector]) == 0:
1075 return []
1076 return self.nearest_neighbors(words, top)
1077
1078 search = vector_space_search
1079

Callers

nothing calls this directly

Calls 5

nearest_neighborsMethod · 0.95
lenFunction · 0.85
DocumentClass · 0.70
popMethod · 0.45
setdefaultMethod · 0.45

Tested by

no test coverage detected