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

标签 spacy matcher

尝试使用 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/

相关文章:

python-3.x - 使用 spacy 进行 POS 模式挖掘

python - 包空间模型

java - 如何模式匹配第一次出现?

Java Scanner vs Matcher——正则表达式,Matcher 有效,Scanner 无效

java - 类名必须在方法之前,必须是 MatcherAssert.assertThat() 而不仅仅是 assertThat()?

python - 如何使用 Spacy 提取标签属性

python - 我是否缺少 spaCy 词形还原中的预处理功能?

python - 了解 Spacy 的得分手输出

java - 为什么Hamcrest `matches`方法使用Object作为输入类型而不使用泛型类型作为输入

java正则表达式匹配