MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / score

Method score

src/licensedcode/match.py:592–619  ·  view source on GitHub ↗

Return the score for this match as a rounded float between 0 and 100. The score is an indication of the confidence that a match is good. It is computed from the number of matched tokens, the number of query tokens in the matched range (including unknowns and unmatch

(self)

Source from the content-addressed store, hash-verified

590 return self.ispan.density()
591
592 def score(self):
593 """
594 Return the score for this match as a rounded float between 0 and 100.
595
596 The score is an indication of the confidence that a match is good. It is
597 computed from the number of matched tokens, the number of query tokens
598 in the matched range (including unknowns and unmatched) and the matched
599 rule relevance.
600 """
601 # relevance is a number between 0 and 100. Divide by 100
602 relevance = self.rule.relevance / 100
603 if not relevance:
604 return 0
605
606 qmagnitude = self.qmagnitude()
607
608 # Compute the score as the ration of the matched query length to the
609 # qmagnitude, e.g. the length of the matched region
610 if not qmagnitude:
611 return 0
612
613 # FIXME: this should exposed as an q/icoverage() method instead
614 query_coverage = self.len() / qmagnitude
615 rule_coverage = self._icoverage()
616 if query_coverage < 1 and rule_coverage < 1:
617 # use rule coverage in this case
618 return round(rule_coverage * relevance * 100, 2)
619 return round(query_coverage * rule_coverage * relevance * 100, 2)
620
621 def surround(self, other):
622 """

Calls 4

qmagnitudeMethod · 0.95
lenMethod · 0.95
_icoverageMethod · 0.95
roundFunction · 0.85