user759885
user759885

Reputation: 142

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 pluralized a noun and now I need to check for dependent verbs to fix any errors in verb agreement.

So one pattern (of many) would be to match an 'auxpass' verb belonging to a parent verb which is a relative clause of the noun.

Upvotes: 3

Views: 2728

Answers (1)

aab
aab

Reputation: 11484

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.

Upvotes: 6

Related Questions