Skip to content Skip to sidebar Skip to footer

How To Match Dependency Patterns With Spacy?

Is there a way to use spaCy's rule-based pattern matcher (or a similar library) on dependency sequences such as the list of tokens returned by token.ancestors? For example, I have

Solution 1:

I kind of hesitate to recommend something that doesn't have any documentation yet, but if you're adventurous, you could try out the relatively new DependencyMatcher. Check out the examples in the test suite to get an idea of how it works:

https://github.com/explosion/spaCy/blob/bae0455f91c375681868f3f21a9de84136f9a561/spacy/tests/matcher/test_matcher_api.py#L271-L346

The operators are similar to:

https://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/semgraph/semgrex/SemgrexPattern.html

From looking at the relevant issues in github, it might not be very efficient yet and I wouldn't be surprised if you ran into a bug or two, so test things carefully before relying on it for anything crucial.

Post a Comment for "How To Match Dependency Patterns With Spacy?"