def test_delete(): dawg = DAWG() dawg[['a', 'b', 'c']] = True dawg[['a', 'b', 'd']] = False del dawg[['a', 'b', 'd']] assert list(dawg) == [['a', 'b', 'c']] assert len(dawg) == 1
def __init__(self, rules: List[List[str]] = None): if rules is None: with (Path(__file__).parent / 'negex_triggers.txt').open('r') as f: rules = make_rules(f) self.dawg = DAWG() for rule, tag in rules: self.dawg[rule] = tag
def test_matcher(): dawg = DAWG() dawg[['a', 'b', 'c']] = True dawg[['a', 'b', 'd']] = False matcher = dawg.matcher() assert matcher.advance('x') == [] assert matcher.advance('a') == [] assert matcher.advance('b') == [] assert matcher.advance('c') == [(3, True)] assert matcher.advance('d') == []
def test_create_dawg(): dawg = DAWG() dawg[['a', 'b', 'c']] = True dawg[['a', 'b', 'd']] = False assert ['a', 'b', 'c'] in dawg assert ['a', 'b', 'd'] in dawg assert ['a', 'b'] not in dawg assert ['a', 'b', 'x'] not in dawg assert dawg[['a', 'b', 'c']] assert not dawg[['a', 'b', 'd']]
def __init__(self, rules: List[List[str]] = None, tokens_range: int = 40): if rules is None: with (Path(__file__).parent / 'negex_triggers.txt').open('r') as f: rules = make_rules(f) self.dawg = DAWG() for rule, tag in rules: try: tags = self.dawg[rule] except KeyError: tags = [] self.dawg[rule] = tags tags.append(tag) self.tokens_range = tokens_range
def test_delete_absent(): dawg = DAWG() dawg[['a', 'b', 'c']] = True dawg[['a', 'b', 'd']] = False with pytest.raises(KeyError): del dawg[['a', 'b']]
def test_iter(): dawg = DAWG() dawg[['a', 'b', 'c']] = True dawg[['a', 'b', 'd']] = False assert ['a', 'b', 'c'] in list(dawg) assert ['a', 'b', 'd'] in list(dawg)