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

Function compute_relevance

src/licensedcode/models.py:2574–2626  ·  view source on GitHub ↗

Return a computed ``relevance`` given a ``length`` and a threshold. The relevance is a integer between 0 and 100 where 100 means highly relevant and 0 means not relevant at all. The relevance is computed base on the rule or detection ``length`` using a relevance schedule based

(length)

Source from the content-addressed store, hash-verified

2572
2573
2574def compute_relevance(length):
2575 """
2576 Return a computed ``relevance`` given a ``length`` and a threshold.
2577 The relevance is a integer between 0 and 100 where 100 means highly
2578 relevant and 0 means not relevant at all.
2579
2580 The relevance is computed base on the rule or detection ``length`` using
2581 a relevance schedule based on the ``length``
2582
2583 For instance a match to the "gpl" or the "cpol" words have a fairly low
2584 relevance as they are a weak indication of an actual license and could
2585 be a false positive and should therefore be assigned a low relevance. In
2586 contrast a match to most or all of the apache-2.0 license text is highly
2587 relevant. The relevance is used as the basis to compute a LicenseMatch
2588 and LicenseDetection score.
2589
2590 For example::
2591 >>> compute_relevance(0)
2592 0
2593 >>> compute_relevance(1)
2594 5
2595 >>> compute_relevance(17)
2596 94
2597 >>> compute_relevance(18)
2598 100
2599 >>> compute_relevance(19)
2600 100
2601 >>> compute_relevance(100)
2602 100
2603 """
2604 if length > 18:
2605 return 100
2606 return {
2607 0: 0,
2608 1: 5,
2609 2: 11,
2610 3: 16,
2611 4: 22,
2612 5: 27,
2613 6: 33,
2614 7: 38,
2615 8: 44,
2616 9: 50,
2617 10: 55,
2618 11: 61,
2619 12: 66,
2620 13: 72,
2621 14: 77,
2622 15: 83,
2623 16: 88,
2624 17: 94,
2625 18: 100,
2626 }[length]
2627
2628
2629def compute_thresholds_occurences(

Callers 2

relevanceMethod · 0.90
set_relevanceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected