mirror of
https://github.com/explosion/spaCy.git
synced 2025-06-29 01:13:17 +03:00
Fix #1434: Matcher failed on ending ? if no token
This commit is contained in:
parent
fec53f09f7
commit
d8391b1c4d
|
@ -391,7 +391,7 @@ cdef class Matcher:
|
||||||
matches.append((ent_id, start, end))
|
matches.append((ent_id, start, end))
|
||||||
# Look for open patterns that are actually satisfied
|
# Look for open patterns that are actually satisfied
|
||||||
for state in partials:
|
for state in partials:
|
||||||
while state.second.quantifier in (ZERO, ZERO_PLUS):
|
while state.second.quantifier in (ZERO, ZERO_ONE, ZERO_PLUS):
|
||||||
state.second += 1
|
state.second += 1
|
||||||
if state.second.nr_attr == 0:
|
if state.second.nr_attr == 0:
|
||||||
start = state.first
|
start = state.first
|
||||||
|
|
22
spacy/tests/regression/test_issue1434.py
Normal file
22
spacy/tests/regression/test_issue1434.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from spacy.tokens import Doc
|
||||||
|
from spacy.vocab import Vocab
|
||||||
|
from spacy.matcher import Matcher
|
||||||
|
from spacy.lang.lex_attrs import LEX_ATTRS
|
||||||
|
|
||||||
|
|
||||||
|
def test_issue1434():
|
||||||
|
'''Test matches occur when optional element at end of short doc'''
|
||||||
|
vocab = Vocab(lex_attr_getters=LEX_ATTRS)
|
||||||
|
hello_world = Doc(vocab, words=['Hello', 'World'])
|
||||||
|
hello = Doc(vocab, words=['Hello'])
|
||||||
|
|
||||||
|
matcher = Matcher(vocab)
|
||||||
|
matcher.add('MyMatcher', None,
|
||||||
|
[ {'ORTH': 'Hello' }, {'IS_ALPHA': True, 'OP': '?'} ])
|
||||||
|
|
||||||
|
matches = matcher(hello_world)
|
||||||
|
assert matches
|
||||||
|
matches = matcher(hello)
|
||||||
|
assert matches
|
Loading…
Reference in New Issue
Block a user