def test_LicenseMatch_score_0_relevance(self):
        r1 = Rule(text_file='r1', licenses=['apache-2.0'])
        r1.relevance = 0
        r1.length = 6

        m1 = LicenseMatch(rule=r1, qspan=Span(0, 2), ispan=Span(0, 2))
        assert m1.score() == 0
    def test_LicenseMatch_score_100_non_contiguous(self):
        r1 = Rule(text_file='r1', licenses=['apache-2.0'])
        r1.relevance = 100
        r1.length = 42

        m1 = LicenseMatch(rule=r1, qspan=Span(0, 19) | Span(30, 51), ispan=Span(0, 41))
        assert m1.score() == 80.77
Example #3
0
    def test_LicenseMatch_score_50(self):
        r1 = Rule(text_file='r1', licenses=['apache-2.0'])
        r1.relevance = 50
        r1.length = 3

        m1 = LicenseMatch(rule=r1, qspan=Span(0, 2), ispan=Span(0, 2))
        assert m1.score() == 50
Example #4
0
    def test_LicenseMatch_score_100_contiguous(self):
        r1 = Rule(text_file='r1', licenses=['apache-2.0'])
        r1.relevance = 100
        r1.length = 42

        m1 = LicenseMatch(rule=r1, qspan=Span(0, 41), ispan=Span(0, 41))
        assert m1.score() == 100
Example #5
0
    def test_LicenseMatch_score_0_relevance(self):
        r1 = Rule(text_file='r1', license_expression='apache-2.0')
        r1.relevance = 0
        r1.length = 6

        m1 = LicenseMatch(rule=r1, qspan=Span(0, 2), ispan=Span(0, 2))
        assert m1.score() == 0
Example #6
0
    def test_LicenseMatch_score_25_with_stored_relevance(self):
        r1 = Rule(text_file='r1', license_expression='apache-2.0')
        r1.relevance = 50
        r1.length = 6

        m1 = LicenseMatch(rule=r1, qspan=Span(0, 2), ispan=Span(0, 2))
        # NB we do not have a query here
        assert m1.score() == 25
    def test_LicenseMatch_score_25_with_stored_relvance(self):
        r1 = Rule(text_file='r1', licenses=['apache-2.0'])
        r1.relevance = 50
        r1.length = 6

        m1 = LicenseMatch(rule=r1, qspan=Span(0, 2), ispan=Span(0, 2))
        # NB we do not have a query here
        assert m1.score() == 50
Example #8
0
    def test_LicenseMatch_score_100_non_contiguous(self):
        r1 = Rule(text_file='r1', license_expression='apache-2.0')
        r1.relevance = 100
        r1.length = 42

        m1 = LicenseMatch(rule=r1,
                          qspan=Span(0, 19) | Span(30, 51),
                          ispan=Span(0, 41))
        assert m1.score() == 80.77
Example #9
0
    def test_merge_does_not_merge_overlapping_matches_of_same_rules_if_in_sequence_with_gaps_for_long_match(self):
        r1 = Rule(text_file='r1', licenses=['apache-2.0', 'gpl'])
        r1.length = 20
        m1 = LicenseMatch(rule=r1, qspan=Span(1, 10), ispan=Span(1, 10))
        m2 = LicenseMatch(rule=r1, qspan=Span(14, 20), ispan=Span(14, 20))

        expected = [LicenseMatch(rule=r1, qspan=Span(1, 10) | Span(14, 20), ispan=Span(1, 10) | Span(14, 20))]
        results = merge_matches([m1, m2])
        assert expected == results
Example #10
0
    def test_merge_does_not_merge_overlapping_matches_of_same_rules_if_in_sequence_with_gaps(
            self):
        r1 = Rule(text_file='r1', license_expression='apache-2.0 OR gpl')
        r1.length = 50

        m1 = LicenseMatch(rule=r1, qspan=Span(1, 3), ispan=Span(1, 3))
        m2 = LicenseMatch(rule=r1, qspan=Span(14, 20), ispan=Span(4, 10))

        expected = [
            LicenseMatch(rule=r1,
                         qspan=Span(1, 3) | Span(14, 20),
                         ispan=Span(1, 10))
        ]
        results = merge_matches([m1, m2])
        assert expected == results