예제 #1
0
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
예제 #2
0
 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
예제 #3
0
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') == []
예제 #4
0
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']]
예제 #5
0
 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
예제 #6
0
def test_delete_absent():
    dawg = DAWG()
    dawg[['a', 'b', 'c']] = True
    dawg[['a', 'b', 'd']] = False
    with pytest.raises(KeyError):
        del dawg[['a', 'b']]
예제 #7
0
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)