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

Method qmagnitude

src/licensedcode/match.py:488–527  ·  view source on GitHub ↗

Return the maximal query length represented by this match start and end in the query. This number represents the full extent of the matched query region including matched, unmatched AND unknown tokens, but excluding STOPWORDS. The magnitude is the same as th

(self)

Source from the content-addressed store, hash-verified

486 return round(self._icoverage() * 100, 2)
487
488 def qmagnitude(self):
489 """
490 Return the maximal query length represented by this match start and end
491 in the query. This number represents the full extent of the matched
492 query region including matched, unmatched AND unknown tokens, but
493 excluding STOPWORDS.
494
495 The magnitude is the same as the length if the match is a contiguous
496 match without any unknown token in its range. It will be greater than
497 the matched length for a non-contiguous match with gaps between its
498 matched tokens. It can also be greater than the query length when there
499 are unknown tokens in the matched range.
500 """
501 # The query side of the match may not be contiguous and may contain
502 # unmatched known tokens or unknown tokens. Therefore we need to compute
503 # the real portion query length including unknown tokens that is
504 # included in this match, for both matches and unmatched tokens
505
506 query = self.query
507 qspan = self.qspan
508 qmagnitude = self.qregion_len()
509
510 # note: to avoid breaking many tests we check query presence
511 if query:
512 # Compute a count of unknown tokens that are inside the matched
513 # range, ignoring end position of the query span: unknowns here do
514 # not matter as they are never in the match but they influence the
515 # score.
516 unknowns_pos = qspan & query.unknowns_span
517 qspe = qspan.end
518 unknowns_pos = (pos for pos in unknowns_pos if pos != qspe)
519 qry_unkxpos = query.unknowns_by_pos
520 unknowns_in_match = sum(qry_unkxpos[pos] for pos in unknowns_pos)
521
522 # update the magnitude by adding the count of unknowns in the match.
523 # This number represents the full extent of the matched query region
524 # including matched, unmatched and unknown tokens.
525 qmagnitude += unknowns_in_match
526
527 return qmagnitude
528
529 def is_continuous(self):
530 """

Callers 3

is_continuousMethod · 0.95
qdensityMethod · 0.95
scoreMethod · 0.95

Calls 1

qregion_lenMethod · 0.95

Tested by

no test coverage detected