@@ -0,0 +1,1205 @@
+'''%0AMatch a dependency pattern. See https://github.com/explosion/spaCy/pull/1120%0A%0AWe start by creating a DependencyTree for the Doc. This class models the document%0Adependency tree. Then we compile the query into a Pattern using the PatternParser.%0AThe syntax is quite simple:%0A%0Awe define a node named 'fox', that must match in the dep tree a token%0Awhose orth_ is 'fox'. an anonymous token whose lemma is 'quick' must have fox%0Aas parent, with a dep_ matching the regex am.* another anonymous token whose%0Aorth_ matches the regex brown%7Cyellow has fox as parent, with whathever dep_%0ADependencyTree.match returns a list of PatternMatch. Notice that we can assign%0Anames to anonymous or defined nodes (%5Bword:fox%5D=f). We can get the Token mapped%0Ato the fox node using match%5B'f'%5D.%0A'''%0Aimport spacy%0Afrom spacy.pattern import PatternParser, DependencyTree%0A%0Anlp = spacy.load('en')%0Adoc = nlp(%22The quick brown fox jumped over the lazy dog.%22)%0Atree = DependencyTree(doc)%0A%0Aquery = %22%22%22fox %5Bword:fox%5D=f%0A           %5Blemma:quick%5D=q %3E/am.*/ fox%0A           %5Bword:/brown%7Cyellow/%5D %3E fox%22%22%22%0A%0Apattern = PatternParser.parse(query)%0Amatches = tree.match(pattern)%0A%0Aassert len(matches) == 1%0Amatch = matches%5B0%5D%0A%0Aassert match%5B'f'%5D == doc%5B3%5D%0A

Add dependency patterns example