'Using Regex to define search pattern for Spacy rule
I have a spacy model and want to include some manual changes to that with the following code
patern = "Juden.*"
#Ruler to correct problems
patterns = [
{"label": "MISC", "pattern": "erwartete"},
{"label": "MISC", "pattern": "Jahren"},
{"label": "MISC", "pattern": "entwöhnte"},
{"label": "MISC", "pattern": "Juden"},
{"label": "MISC", "pattern": {patern}}
]
ruler = nlp.add_pipe("entity_ruler", before ="ner")
nlp.analyze_pipes()
ruler.add_patterns(patterns)
everything works well, but I want to combine the regex
module with spacy
so that I can extract ALL words which start with Juden
, followed by any character.
e.g.
Judenthum, Judenhass, Judennot, etc.
I tried to set up a variable patern
with the regex expression which works itself, but I am now struggling to include this into my patterns
of the spacy
model
Any suggestions or advices?
Thank you !
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|