我在尝试使用 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()
?
See the SpaCy Matcher.add()文档 https://spacy.io/api/matcher#add:
v3.0 中更改
从 spaCy v3.0 开始,Matcher.add
将模式列表作为第二个参数(而不是可变数量的参数)。这on_match
回调成为可选的关键字参数。
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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)