我試圖在我的機器上從official documentation工作中使Spacy'smatcher example工作。Spacy 2.0匹配器:add()至少需要4個位置參數(給出3個)
from spacy.matcher import Matcher
matcher = Matcher(nlp.vocab)
pattern = [{'LOWER': "hello"}, {'LOWER': "world"}]
matcher.add("HelloWorld", None, pattern)
doc = nlp(u'hello world!')
matches = matcher(doc)
不幸的是我會遇到以下錯誤:
類型錯誤:添加()採用至少4的位置參數(3給出)
對應的源代碼可以發現here,重要部分是
def add(self, key, on_match, *patterns):
"""Add a match-rule to the matcher. A match-rule consists of: an ID
key, an on_match callback, and one or more patterns.
Spacy最近更新到2.0版,我安裝了編輯該版本,併成功地將英文模型與它聯繫起來。感覺我在這裏錯過了一些非常明顯的東西,但我不明白我做錯了什麼。
原來我忘了告訴virtualenv在設置新環境時使用Python 3。因此它確實使用Spacy版本1。感謝您的提示,非常感謝Spacy核心團隊的反應如此之快。 – user3255061