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)
| 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 |
nothing calls this directly
no test coverage detected