Semgrex and Ssurgeon, Searching and Manipulating Dependency Graphs (2023)

Abstract: Searching dependency graphs and manipulating them can be a time consuming and challenging task to get right. We document Semgrex, a system for searching dependency graphs, and introduce Ssurgeon, a system for manipulating the output of Semgrex. The compact language used by these systems allows for easy command line or API processing of dependencies. Additionally, integration with publicly released toolkits in Java and Python allows for searching text relations and attributes over natural text.

## introduction with the rapid growth in languages supported by universal dependencies @xcite , being able to easily and quickly search over dependency graphs greatly simplifies processing of ud datasets. tools which allow for searching of specific relation structures greatly simplify the work of linguists interested in specific syntactic constructions and researchers extracting relations as features for downstream tasks. furthermore, converting existing dependency treebanks from non-ud sources to match the ud format is valuable for adding additional data to universal dependencies, and doing this conversion automatically greatly reduces the time needed to add more datasets to ud. accordingly, several tools have been developed for searching, displaying, and converting existing datasets. in this paper, we describe semgrex, a tool which searches for regex-like patterns in dependency graphs, and ssurgeon, a tool to rewrite dependency graphs using the output of semgrex. both systems are written in java, with java api and command line tools available. in addition, there is a python interface, including using displacy @xcite as a library to visualize the results of searches and transformation operations. the tools can be used programmatically to enable further processing of the results or used via the included command line tools. furthermore, a web interface foot_0 shows the results of applying patterns to raw text. semgrex was released as part of corenlp @xcite . as such, it has been used in several projects (section 4). several existing uses of semgrex make use of it via the api, one of the strengths of the system, such as the openie relation extraction of @xcite . more recently, we have added new pattern matching capabilities such as exact edge matching, a new python interface, and performance improvements. the previously unpublished ssurgeon adds useful new capabilities for transforming dependency graphs. many of the features described here are similar to those in grew-match @xcite and semgrex-plus @xcite . similar to ssurgeon, semgrex-plus uses semgrex to find matches for editing, but ssurgeon supports a wider range of operations. compared with grew-match, semgrex and ssurgeon have the ability to start with raw text and search for dependency relations directly. ## semgrex semgrex and ssurgeon are publicly released as part of the corenlp software package @xcite ., attribute word pos lemma ner idx upos ## ssurgeon ssurgeon is an extension of semgrex which includes rules to rewrite dependency graphs. a pattern in ssurgeon is a pattern for semgrex with required named nodes and/or edges, depending on the edit type, along with a edit definition. ## related work the analysis of dependency treebanks, especially universal dependencies, has a long history of using dependency searching and rewriting tools. constituency treebanks such as the penn treebank @xcite predate universal dependencies. to analyze such constituency datasets, tgrep @xcite and its successor tgrep2 (rohde, 2003) set the initial standard for searching tree structured data. tregex and tsurgeon (levy and andrew, 2006) extended the language and added functionality to rewrite constituency trees. semgrex was one of the earliest tools to address the problem of searching in dependency graphs. it was previous briefly described in a paper on entailment that was the first to use semgrex, @xcite , although that paper did not include ssurgeon or fully explain the usage of semgrex. semgrex has been used by other research several times in the following years. the authors of the ud_italian-vit @xcite dataset used an extension of sem-grex, semgrex-plus @xcite , to convert the dependency form of vit to universal dependencies. semgrex-plus adds edge creation, edge deletion, and word relabeling to a semgrex result. also connected with universaldependencies are multiple search engines which allow for easier viewing of the treebanks. tündra @xcite allows for searching of a variety of treebanks using the tigersearch format (lezius et al., 2002). 8 additional treebanks not part of ud are included @xcite , although recent ud updates have not been incorporated. grew-match (guillaume, 2021) foot_7 hosts a website which allows for searching of existing ud and other dependency datasets. the interface is frequently updated, hosting the latest 2.11 treebanks as of january 2023. @xcite provides a web interface to backend parsers such as @xcite and provides search, visual editing, and automatic pattern matching and replacement. however, it does not include a command line tool. other tools include udeasy (brigada villa, 2022), which provides a graphical interface which allows for searching of ud treebanks or any other dependency formalism. spacy reimplemented semgrex as part of the 3.0 release, adding the de-pendencymatcher tool @xcite . 10 udapi @xcite provides mechanisms for searching dependency graphs, parsing text, visualizing the graphs, and manipulating the graphs themselves. odin is a rule-based event extraction framework over dependency structures @xcite . ## conclusion we have introduced semgrex and ssurgeon, flexible, simple systems for dependency matching and dependency tree manipulation.