Skip to content

Help with matcher patterns #9483

Discussion options

You must be logged in to vote

As you noted, the arguments to Matcher.add changed from spaCy 2 to 3. In spaCy 2, the method signature was:

matcher.add(match_id, on_match, *patterns)

Notice the * on *patterns. This is a variable-length argument. So, after the match_id and on_match argument, any remaining arguments to matcher.add(…) would get collected together as a list for patterns.

pattern1 = [{"TEXT": "iPhone", {"TEXT": "X"}]
pattern2 = [{"TEXT": "iOS"}, {"IS_DIGIT": True}]

matcher.add("IPHONE_X_PATTERN", None, pattern1, pattern2)

# The method receives the equivalent of patterns=[pattern1, pattern2],
# from gathering the variable arguments.

In spaCy 3, the method signature changed to:

matcher.add(match_id, patterns, 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by polm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat / matcher Feature: Token, phrase and dependency matcher
2 participants