From 5cd3acb2652988bf1dc02913b7db4cb2551f25e2 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sun, 6 Nov 2016 10:50:42 +0100 Subject: [PATCH] Fix #605: Acceptor now rejects matches as expected. --- spacy/matcher.pyx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/spacy/matcher.pyx b/spacy/matcher.pyx index 613135a23..7c694431e 100644 --- a/spacy/matcher.pyx +++ b/spacy/matcher.pyx @@ -382,11 +382,12 @@ cdef class Matcher: ent_id = state.second[1].attrs[0].value label = state.second[1].attrs[1].value acceptor = self._acceptors.get(ent_id) - if acceptor is not None: + if acceptor is None: + matches.append((ent_id, label, start, end)) + else: match = acceptor(doc, ent_id, label, start, end) if match: - ent_id, label, start, end = match - matches.append((ent_id, label, start, end)) + matches.append(match) partials.resize(q) # Check whether we open any new patterns on this token for pattern in self.patterns: @@ -411,8 +412,13 @@ cdef class Matcher: end = token_i+1 ent_id = pattern[1].attrs[0].value label = pattern[1].attrs[1].value - if acceptor is None or acceptor(doc, ent_id, label, start, end): + acceptor = self._acceptors.get(ent_id) + if acceptor is None: matches.append((ent_id, label, start, end)) + else: + match = acceptor(doc, ent_id, label, start, end) + if match: + matches.append(match) for i, (ent_id, label, start, end) in enumerate(matches): on_match = self._callbacks.get(ent_id) if on_match is not None: