-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from sadit/pre17
merges 0.17 into main
- Loading branch information
Showing
16 changed files
with
390 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# This file is a part of TextSearch.jl | ||
|
||
export QgramsLookup | ||
|
||
struct QgramsLookup <: AbstractTokenLookup | ||
voc::Vocabulary{TokenLookup} | ||
idx::BinaryInvertedFile | ||
maxdist::Float32 | ||
end | ||
|
||
""" | ||
QgramsLookup( | ||
voc::Vocabulary, | ||
dist::SemiMetric=JaccardDistance(); | ||
maxdist::Real = 0.7, | ||
textconfig=TextConfig(qlist=[3]), | ||
doc_min_freq::Integer=1, # any hard vocabulary pruning are expected to be made in `voc` | ||
doc_max_ratio::AbstractFloat=0.4 # popular tokens are likely to be thrash | ||
) | ||
""" | ||
function QgramsLookup( | ||
voc::Vocabulary, | ||
dist::SemiMetric=JaccardDistance(); | ||
maxdist::Real = 0.7, | ||
textconfig=TextConfig(qlist=[3]), | ||
doc_min_freq::Integer=1, # any hard vocabulary pruning are expected to be made in `voc` | ||
doc_max_ratio::AbstractFloat=0.4 # popular tokens are likely to be thrash | ||
) | ||
|
||
voc_ = Vocabulary(textconfig, token(voc)) | ||
voc_ = filter_tokens(voc_) do t | ||
doc_min_freq <= t.ndocs <= doc_max_ratio * vocsize(voc_) | ||
end | ||
|
||
invfile = BinaryInvertedFile(vocsize(voc_), dist) | ||
append_items!(invfile, VectorDatabase(bagofwords_corpus(voc_, token(voc)))) | ||
QgramsLookup(voc_, invfile, maxdist) | ||
end | ||
|
||
function token2id(voc::Vocabulary{QgramsLookup}, tok)::UInt32 | ||
lookup = voc.lookup | ||
i = get(voc.token2id, tok, zero(UInt32)) | ||
i > 0 && return i | ||
tok == "" && return 0 | ||
res = KnnResult(1) | ||
search(lookup.idx, bagofwords(lookup.voc, tok), res) | ||
p = res[1] | ||
p.weight > lookup.maxdist ? 0 : p.id | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.