Package: depgrep
depgrepDependency parse searching for CONLL-U DataFramesVersion 0.1.3Note: this tool currently doesn't have tests, CI, etc. It is not yet advised to use this tool outside of the depgrep methods provided by thebuzzlibrary.InstallationpipinstalldepgrepUsageThe tool is designed to work with corpora made from CONLL-U files and parsed into DataFrames bybuzz. The best thing to do is usebuzzto model corpora, and then use itsdepgrepmethod.pipinstallbuzzThen, in Python:frombuzzimportCorpuscorpus=Corpus('path/to/conll/files')query='l"have"'# match the lemma "have"Syntaxdepgrep searches work through a combination ofnodesandrelations, just like Tgrep2, on which this tool is based.NodesA node targets one token feature (word, lemma, POS, wordclass, dependency role, etc). It may be specified as a regular expression or a simple string match:f/amod|nsubj/will match tokens filling thensubjoramodrole;l"be"will match the lemma,be.The first part of the node query chooses which token attribute is to be searched. It can be any of:w : word
l : lemma
p : part of speech tag
x : wordclass / XPOS
f : dependency role
i : index in sentence
s : sentence numberCase sensitivity is controlled by the case of the attribute you are searching:p/VB/is case-insensitive, andP/VB/is case sensitive. Therefore, the following query matches words ending ining,ING,Ing, etc:w/ing$/For case-insensitivity across the query, use thecase_sensitive=Falsekeyword argument.RelationsRelations specify the relationship between nodes. For example, we can usef"nsubj" <- f"ROOT"to locate nominal subjects governed by nodes in the role ofROOT. The thing you want to find is the leftmost node in the query. So, while the above query finds nominal subject tokens, you could use inverse relation,f"ROOT" -> f"nsubj"to return the ROOT tokens.Available relations:a = b   : a and b are the same node
a & b   : a and b are the same node (same as =)

a <- b  : a is a dependent of b
a <<- b : a is a descendent of b, with any distance in between
a <-: b : a is the only dependent of b
a <-N b : a is descendent of b by N generations

a -> b  : a is the governor of a
a ->> b : a is an ancestor of b, with any distance in between
a ->: b : a is the only governor of b (as is normal in many grammars)
a ->N b : a is ancestor of b by N generations

a + b   : a is immediately to the left of b
a +N b  : a is N places to the left of b
a <| b  : a is left of b, with any distance in between

a - b   : a is immediately to the right of b
a -N b  : a is n places to the right of b
a |> b  : a is right of b, with any distance in between

a $ b   : a and b share a governor (i.e. are sisters)

a $> b  : a is a sister of and to the right of b.
a $< b  : a is a sister of and to the left of b.NegationAdd!before a relation to negate it:f"ROOT" != x"VERB"will find non-verbal ROOT nodes.BracketsBrackets can be used to make more complex queries:f"amod" = l/^[abc]/ <- (f/nsubj/ != x/NOUN/)The above translates tomatch adjectival modifiers starting with a, b or c, which are governed by nominal subjects that are not nounsNote thatwithoutbrackets, each relation/node refers to the leftmost node. In the following, the plural noun must be the same node as thensubj, not theROOT:f"nsubj" <- f"ROOT" = p"NNS"OrexpressionsYou can use the pipe (|) to create anORexpression.# match all kinds of modifiers
x"ADJ" | f"amod" | f"appos" | p/^JJ/
x"NOUN" <- f"ROOT" | = p"NNS"Above, we match nouns that are either governed byROOT, or are plural.WildcardYou can use__or*to stand in for any token. To match any token that is the governor of a verb, do:__ -> x"VERB"