gpt4 book ai didi

spacy - 使用 spacy.matcher.matcher.Matcher.add() 方法的问题

转载 作者:行者123 更新时间:2023-12-04 01:06:50 25 4
gpt4 key购买 nike

尝试使用 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). The on_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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com