Help with matcher patterns #9483
-
Hello,
In version 3 that generates errors but this code works:
My question is: p.s. obviously version 3 has reduced the number of args in matcher.add from 3 to 2. Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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 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, on_match=None, greedy=None) Putting aside the differences in the order of the arguments, the lack of a pattern1 = [{"TEXT": "iPhone", {"TEXT": "X"}]
pattern2 = [{"TEXT": "iOS"}, {"IS_DIGIT": True}]
matcher.add("IPHONE_X_PATTERN", [pattern1, pattern2])
# The method receives patterns=[pattern1, pattern2] like before,
# but because you've passed the list instead of a variable number of arguments being collected. |
Beta Was this translation helpful? Give feedback.
As you noted, the arguments to Matcher.add changed from spaCy 2 to 3. In spaCy 2, the method signature was:
Notice the
*
on*patterns
. This is a variable-length argument. So, after thematch_id
andon_match
argument, any remaining arguments tomatcher.add(…)
would get collected together as a list forpatterns
.In spaCy 3, the method signature changed to: