This project implements Locality Sensitive Hashing algorithms and data structures for indexing and querying text documents. The primary use cases for Gaoya are deduplication and clustering.
```python
import gaoya index = gaoya.minhash.MinHashStringIndex(hashsize=32, jaccardthreshold=0.5, numbands=42, bandsize=3, numhashes=42*3, analyzer='word', lowercase=True, ngramrange=(1,1)) corpus = [ ... 'This is the first document.', ... 'This document is the second document.', ... 'And this is the third document.', ... 'Is this the first document?', ... 'This not the first nor the second nor the third, but the fourth document' ... ]
for i, doc in enumerate(corpus): index.insert_document(i, doc) ... index.query('This is the first document.') [0, 1, 2, 3]
```
$ pip3 install gaoya
Document Deduplication with Gaoya
```rust use gaoya::minhash::{MinHashIndex, MinHasher32, MinHasher} ; use gaoya::text::whitespacesplit; use fxhash::FxHashSet; let corpus = [ "This is the first document.", "This document is the second document.", "And this is the third document.", "Is this the first document?", "This not the first nor the second nor the third, but the fourth document"]; let (numbands, bandwidth) = (42, 3); let minhasher = MinHasher32::new(numbands * bandwidth); let mut index = MinHashIndex::new(numbands, bandwidth, 0.5); for (i, doc) in corpus.iter().enumerate() { index.insert(i, minhasher.createsignature(whitespacesplit(&doc.tolowercase()))); } for (i, doc) in corpus.iter().enumerate() { if i < 4 { let mut expected = FxHashSet::default(); expected.extend(vec![0, 1, 2, 3].intoiter()); let signature = minhasher.createsignature(whitespacesplit(&doc.tolowercase())); asserteq!(index.queryowned(&signature), expected); } else { let mut expected = FxHashSet::default(); expected.insert(4); let signature = minhasher.createsignature(whitespacesplit(&doc.tolowercase())); asserteq!(index.query_owned(&signature), expected); } }
```
[1] Chapter 3, Mining of Massive Datasets
[2] Similarity Estimation Techniques from Rounding Algorithms