示例#1
0
def test_dummy():
    scorer = DummyScorer()
    pp = PartialParse((Time(), Interval()), ("rule1", "rule2"))

    assert scorer.score("a", datetime.datetime(2019, 1, 1), pp) == 0.0
    assert scorer.score_final("a", datetime.datetime(2019, 1, 1), pp,
                              pp.prod[0]) == 0.0
示例#2
0
def test_random():
    rng = random.Random(42)
    scorer = RandomScorer(rng)

    pp = PartialParse((Time(), Interval()), ("rule1", "rule2"))

    assert 0.0 <= scorer.score("a", datetime.datetime(2019, 1, 1), pp) <= 1.0
    assert (0.0 <= scorer.score_final("a", datetime.datetime(2019, 1, 1), pp,
                                      pp.prod[1]) <= 1.0)
示例#3
0
def test_partial_parse() -> None:
    match_a = regex.match("(?<R1>a)", "ab")
    match_b = next(regex.finditer("(?<R2>b)", "ab"))

    pp = PartialParse.from_regex_matches(
        (RegexMatch(1, match_a), RegexMatch(2, match_b)))

    assert len(pp.prod) == 2
    assert len(pp.rules) == 2

    assert isinstance(pp.score, float)

    def mock_rule(ts: datetime.datetime, a: Time) -> Time:
        return Time()

    pp2 = pp.apply_rule(datetime.datetime(day=1, month=1, year=2015),
                        mock_rule, 'mock_rule', (0, 1))

    assert pp != pp2

    with pytest.raises(ValueError):
        PartialParse((), ())
示例#4
0
def test_nbscorer():
    # We only test that it runs just fine
    X = [("a", "b"), ("a", ), ("b"), ("a", "b", "a", "b")]
    y = [False, True, True, False]

    model = train_naive_bayes(X, y)
    scorer = NaiveBayesScorer(model)

    pp = PartialParse((Time(), Interval()), ("rule1", "rule2"))

    pp.prod[0].mstart = 0
    pp.prod[1].mend = 1

    pp.prod[0].mend = 1
    pp.prod[1].mend = 2

    assert 0.0 <= scorer.score("ab", datetime.datetime(2019, 1, 1), pp) <= 1.0
    assert (0.0 <= scorer.score_final("ab", datetime.datetime(2019, 1, 1), pp,
                                      pp.prod[1]) <= 1.0)