Skip to content

Commit 8a25b51

Browse files
committed
fix test failure
1 parent a50b3db commit 8a25b51

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

src/licensedcode/match.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,11 +1081,16 @@ def is_extra_words_position_valid(match):
10811081
do not exceed the maximum allowed word count at those positions.
10821082
Otherwise, return False.
10831083
"""
1084-
1085-
rule_spans = match.ispan.subspans()
1084+
# Find `query_coverage_coefficient` such that match have `extra-words` or not
1085+
score_coverage_relevance = (
1086+
match.coverage() * match.rule.relevance
1087+
) / 100
1088+
1089+
# Calculate the query coverage coefficient
1090+
query_coverage_coefficient = score_coverage_relevance - match.score()
10861091

1087-
# If there are multiple subspans, it means not all required tokens are contiguous.
1088-
if len(rule_spans) > 1:
1092+
# Return False if the match has no extra words
1093+
if query_coverage_coefficient == 0:
10891094
return False
10901095

10911096
matched_tokens = list(index_tokenizer(match.matched_text(whole_lines=False, highlight=False)))

tests/licensedcode/test_match.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,29 +1482,6 @@ def test_LicenseMatch_score_100_non_contiguous(self):
14821482
m1 = LicenseMatch(rule=r1, qspan=Span(0, 19) | Span(30, 51), ispan=Span(0, 41))
14831483
assert m1.score() == 80.77
14841484

1485-
def test_LicenseMatch_matches_score_100_for_extra_words_within_limit(self):
1486-
rule_text = 'Neither the name of [[3]] nor the names of its'
1487-
rule = create_rule_from_text_and_expression(license_expression='bsd_new', text=rule_text)
1488-
idx = index.LicenseIndex([rule])
1489-
1490-
query = 'Neither the name of XXX YYY ZZZ nor the names of its'
1491-
matches = idx.match(query_string=query, _skip_hash_match=True)
1492-
match = matches[0]
1493-
score = match.score()
1494-
assert score == 100
1495-
1496-
def test_LicenseMatch_matches_score_not_100_for_extra_words_exceed_limit(self):
1497-
rule_text = 'Neither the name of [[3]] nor the names of its'
1498-
rule = create_rule_from_text_and_expression(license_expression='bsd_new', text=rule_text)
1499-
idx = index.LicenseIndex([rule])
1500-
1501-
# The query includes 4 extra words instead of the allowed 3.
1502-
query = 'Neither the name of XXX YYY ZZZ AAA nor the names of its'
1503-
matches = idx.match(query_string=query, _skip_hash_match=True)
1504-
match = matches[0]
1505-
score = match.score()
1506-
assert score != 100
1507-
15081485
def test_LicenseMatch_stopwords_are_treated_as_unknown_2484(self):
15091486
rules_dir = self.get_test_loc('stopwords/index/rules')
15101487
lics_dir = self.get_test_loc('stopwords/index/licenses')

0 commit comments

Comments
 (0)