1.ValueError: [E966] nlp.add_pipe
now takes the string name of the registered component factory, not a callable component. Expected string, but got <spacy.pipeline.entityruler.EntityRuler object at 0x0000006C570CA2C0> (name: ‘None’).
-
If you created your component with
nlp.create_pipe('name')
: remove nlp.create_pipe and callnlp.add_pipe('name')
instead. -
If you passed in a component like
TextCategorizer()
: callnlp.add_pipe
with the string name instead, e.g.nlp.add_pipe('textcat')
. -
If you’re using a custom component: Add the decorator
@Language.component
(for function components) or@Language.factory
(for class components / factories) to your custom component and assign it a name, e.g.@Language.component('your_name')
. You can then runnlp.add_pipe('your_name')
to add it to the pipeline.
import spacy
text = "Martha, a senior, moved to Spain where she will be playing basketball until 05 June 2022 or until she can't play any longer."
nlp = spacy.load("en_core_web_sm")
doc_ori = nlp(text)
for en in doc_ori.ents:
print(en)
print("--"*10)
ruler = nlp.create_pipe("entity_ruler") # 这里有问题,应该是修改了函数
ruler.add_patterns([{"label": "SPORT", "pattern": "basketball"}])
nlp.add_pipe(ruler,before="ner")
doc = nlp(text)
for en1 in doc.ents:
print(en1,en1.label_)
改一下两行,然后就可以了
ruler = nlp.add_pipe("entity_ruler")
ruler.add_patterns([{"label": "SPORT", "pattern": "basketball"}])
# nlp.add_pipe(ruler,before="ner")