Hi everyone I am executing this code in Spacy to match with Regex, but I get an error:
import spacy
from spacy.matcher import Matcher
nlp = spacy.load("en_core_web_md")
doc1 = nlp("Hello hello hello, how are you?")
doc2 = nlp("Hello, how are you?")
doc3 = nlp("How are you?")
pattern = [{"LOWER": {"IN": ["hello", "hi", "hallo"]},"OP": "*",{"IS_PUNCT": True}}]
matcher.add("greetings", [pattern])
for mid, start, end in matcher(doc1):
print(start, end, doc1[start:end])
The error is
pattern = [{"LOWER": {"IN": ["hello", "hi", "hallo"]},"OP": "*",{"IS_PUNCT": True}}]
^
SyntaxError: invalid syntax
I am following a book called Mastering Spacy and I copy-pasted the code from the book, but I checked not to include any special characters.
Regards
pattern = [{"LOWER": {"IN": ["hello", "hi", "hallo"]},"OP": "*","IS_PUNCT": True}]or maybepattern = [{"LOWER": {"IN": ["hello", "hi", "hallo"]}},{"OP": "*"},{"IS_PUNCT": True}]I'm voting to close this as a typo.SyntaxError: ':' expected after dictionary key. That should make it fairly obvious.}herepattern = [{"LOWER": {"IN": ["hello", "hi", "hallo"]},"OP": "*"},{"IS_PUNCT": True}]. Thank you