Skip to content
Discussion options

You must be logged in to vote

Please read the guide to Github Markdown for code.

What version of spaCy are you using? This code runs without issue for me.

import spacy

nlp = spacy.load("en_core_web_sm")
doc = nlp("I wrote a book last year.")

deppattern = [
        {"RIGHT_ID": "wrote", "RIGHT_ATTRS": {"LEMMA": "write"}},
        {"LEFT_ID": "wrote", "REL_OP": ">", "RIGHT_ID": "book",
            "RIGHT_ATTRS": {"LEMMA": "book"}}
        ]

from spacy.matcher import DependencyMatcher

dmatcher = DependencyMatcher(nlp.vocab)

dmatcher.add("BOOK", [deppattern])

for _, (start, end) in dmatcher(doc):
    print(doc[start].sent)

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Manish-ZS
Comment options

@polm
Comment options

Answer selected by polm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat / matcher Feature: Token, phrase and dependency matcher v2 spaCy v2.x
2 participants
Converted from issue

This discussion was converted from issue #11028 on June 26, 2022 04:16.