Skip to content

Acceptor Function Not Rejecting Matches #605

@aikramer2

Description

@aikramer2

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBugs and behaviour differing from documentation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions