Skip to content

Commit 962d1f5

Browse files
committed
Improve licenses detection accuracy of unknowns using ngrams
Signed-off-by: akugarg <akanksha.garg2k@gmail.com>
1 parent aecab91 commit 962d1f5

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/licensedcode/index.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
from intbitset import intbitset
2121

22-
from licensedcode import SMALL_RULE, match_unknown
22+
from licensedcode import SMALL_RULE
23+
from licensedcode import match_unknown
2324
from licensedcode.legalese import common_license_words
2425
from licensedcode import match
2526
from licensedcode import match_aho
@@ -32,6 +33,7 @@
3233
from licensedcode.seq import match_blocks as match_blocks_seq
3334
from licensedcode import query
3435
from licensedcode import tokenize
36+
from licensedcode.spans import Span
3537

3638
"""
3739
Main license index construction, query processing and matching entry points for
@@ -883,6 +885,25 @@ def match(
883885
# break if deadline has passed
884886
if time() > deadline:
885887
break
888+
889+
# refining matches without filtering false positives
890+
matches, _discarded = match.refine_matches(
891+
matches=matches,
892+
idx=self,
893+
query=qry,
894+
min_score=min_score,
895+
filter_false_positive=False,
896+
merge=True,
897+
)
898+
899+
original_qspan = Span(0, len(qry.tokens)-1)
900+
matched_qspans = [m.qspan for m in matches]
901+
matched_qspan = Span()
902+
matched_qspan.union(*matched_qspans)
903+
unmatched_qspan = original_qspan.difference(matched_qspan)
904+
905+
for subspan in unmatched_qspan.subspans():
906+
query_run = query.QueryRun(query=qry, start=subspan.start, end=subspan.end)
886907

887908
if not matches:
888909
return []

src/licensedcode/match_unknown.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def add_ngrams(automaton, tids, rule_length, unknown_ngram_length=7):
4949
automaton.add_word(ngram, ngram)
5050

5151

52-
def unknown_match(idx, query_run, automaton, unknown_ngram_length=7, **kwargs):
52+
def match_unknowns(idx, query_run, automaton, unknown_ngram_length=7, **kwargs):
5353
"""
5454
Return a list of unknown LicenseMatch by matching the `query_run` against
5555
the `automaton` and `idx` index.

0 commit comments

Comments
 (0)