Giving the MinHash of the query set, retrieve the keys that reference sets with Jaccard similarities likely greater than the threshold. Results are based on minhash segment collision and are thus approximate. For more accurate results, filter again w
(self, minhash)
| 181 | hashtable.insert(H, set([key]), buffer=buffer) |
| 182 | |
| 183 | def query(self, minhash): |
| 184 | ''' |
| 185 | Giving the MinHash of the query set, retrieve |
| 186 | the keys that reference sets with Jaccard |
| 187 | similarities likely greater than the threshold. |
| 188 | |
| 189 | Results are based on minhash segment collision |
| 190 | and are thus approximate. For more accurate results, |
| 191 | filter again with `minhash.jaccard`. For exact results, |
| 192 | filter by computing Jaccard similarity using original sets. |
| 193 | |
| 194 | Args: |
| 195 | minhash (datasketch.MinHash): The MinHash of the query set. |
| 196 | |
| 197 | Returns: |
| 198 | `list` of unique keys. |
| 199 | ''' |
| 200 | if len(minhash) != self.h: |
| 201 | raise ValueError("Expecting minhash with length %d, got %d" |
| 202 | % (self.h, len(minhash))) |
| 203 | candidates = set() |
| 204 | for (start, end), hashtable in zip(self.hashranges, self.hashtables): |
| 205 | H = self._H(minhash.hashvalues[start:end]) |
| 206 | for key in hashtable.get(H): |
| 207 | candidates.add(key) |
| 208 | if self.prepickle: |
| 209 | return [pickle.loads(key) for key in candidates] |
| 210 | else: |
| 211 | return list(candidates) |
| 212 | |
| 213 | def add_to_query_buffer(self, minhash): |
| 214 | ''' |
no test coverage detected