Context manager for batch insertion of documents into a MinHashLSH.
| 347 | |
| 348 | |
| 349 | class MinHashLSHInsertionSession: |
| 350 | '''Context manager for batch insertion of documents into a MinHashLSH. |
| 351 | ''' |
| 352 | |
| 353 | def __init__(self, lsh, buffer_size): |
| 354 | self.lsh = lsh |
| 355 | self.lsh.buffer_size = buffer_size |
| 356 | |
| 357 | def __enter__(self): |
| 358 | return self |
| 359 | |
| 360 | def __exit__(self, exc_type, exc_val, exc_tb): |
| 361 | self.close() |
| 362 | |
| 363 | def close(self): |
| 364 | self.lsh.keys.empty_buffer() |
| 365 | for hashtable in self.lsh.hashtables: |
| 366 | hashtable.empty_buffer() |
| 367 | |
| 368 | def insert(self, key, minhash, check_duplication=True): |
| 369 | ''' |
| 370 | Insert a unique key to the index, together |
| 371 | with a MinHash (or weighted MinHash) of the set referenced by |
| 372 | the key. |
| 373 | |
| 374 | Args: |
| 375 | key (hashable): The unique identifier of the set. |
| 376 | minhash (datasketch.MinHash): The MinHash of the set. |
| 377 | ''' |
| 378 | self.lsh._insert(key, minhash, check_duplication=check_duplication, |
| 379 | buffer=True) |
nothing calls this directly
no outgoing calls
no test coverage detected