尝试使用 spacy matcher
时出现错误:
~\Anaconda3\lib\site-packages\spacy\matcher\matcher.pyx in spacy.matcher.matcher.Matcher.add()
TypeError: add() takes exactly 2 positional arguments (3 given)
spacy.matcher.matcher.Matcher.add()
是否有替代功能? ?
最佳答案
见 SpaCy Matcher.add()
documentation :
Changed in v3.0
As of spaCy v3.0,Matcher.add
takes a list of patterns as the second argument (instead of a variable number of arguments). Theon_match
callback becomes an optional keyword argument.
patterns = [[{"TEXT": "Google"}, {"TEXT": "Now"}], [{"TEXT": "GoogleNow"}]]
- matcher.add("GoogleNow", on_match, *patterns)
+ matcher.add("GoogleNow", patterns, on_match=on_match)
用法示例:
from spacy.matcher import Matcher
matcher = Matcher(nlp.vocab)
pattern = [{"LOWER": "hello"}, {"LOWER": "world"}]
matcher.add("HelloWorld", [pattern])
doc = nlp("hello world!")
matches = matcher(doc)
关于spacy - 使用 spacy.matcher.matcher.Matcher.add() 方法的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66164156/