explosion/spaCy

Acceptor Function Not Rejecting Matches

aikramer2 opened this issue · 2 comments

I'm trying to make use the acceptor function for a matcher, and am getting behavior that I would not expect. My assumption is if an acceptor returns a falsy value (I'm using False), then a match should be rejected. The assertion below fails:

import spacy 
from spacy.attrs import LOWER, ORTH

nlp = spacy.en.English()
text = u"""The golf club is broken"""
doc = nlp(text)

golf_pattern =     [ 
        { ORTH: "golf"},
        { ORTH: "club"}
    ]

def return_false(doc, ent_id, label, start, end):
    return False

matcher = spacy.matcher.Matcher(nlp.vocab)
matcher.add_entity('Sport_Equipment'
                   , acceptor=return_false
                  )
matcher.add_pattern("Sport_Equipment", golf_pattern)
match = matcher(doc)

assert match == []

Inspecting the match, the entity associated with the given ID does indeed have the correct acceptor function registered:

ent_id = match[0][0]
print matcher._acceptors.get(ent_id)

Your Environment

  • Ubuntu
  • Python Version: 2.7
  • Spacy Version: 1.1.2

Definitely a bug, thanks. Will look at this tomorrow.

lock commented

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.