{ "paper_id": "2020", "header": { "generated_with": "S2ORC 1.0.0", "date_generated": "2023-01-19T03:11:17.819795Z" }, "title": "UDon2: a library for manipulating Universal Dependencies trees", "authors": [ { "first": "Dmytro", "middle": [], "last": "Kalpakchi", "suffix": "", "affiliation": { "laboratory": "", "institution": "KTH Royal Institute of Technology Stockholm", "location": { "country": "Sweden" } }, "email": "dmytroka@kth.se" }, { "first": "Johan", "middle": [], "last": "Boye", "suffix": "", "affiliation": { "laboratory": "", "institution": "KTH Royal Institute of Technology Stockholm", "location": { "country": "Sweden" } }, "email": "jboye@kth.se" } ], "year": "", "venue": null, "identifiers": {}, "abstract": "UDon2 is an open-source library for manipulating dependency trees represented in the CoNLL-U format. The library is compatible with the Universal Dependencies. UDon2 is aimed at developers of downstream Natural Language Processing applications that require manipulating dependency trees on the sentence level (to complement other available tools geared towards working with treebanks). 1 import udon2 2 nodes = udon2.ConllReader.read_file(\"example.conll\") 3 sing = [obj for node in nodes for obj in node.select_by(\"deprel\", \"obj\") 4 if obj.has(\"feats\", \"Number\", \"Sing\")] UDon2 is an open-source library written in C++ with Python bindings, combining the speed of C++ and the flexibility and ease-of-use of Python. UDon2 is hosted on Github (the source code is available at https://github.com/udon2/udon2), and everyone is welcome to contribute. 2 Example use cases UDon2 operates on dependency trees for individual sentences. Preparing a raw text for downstream applications requires segmenting it into sentences and then parsing every sentence to get its dependency tree stored in CoNLL-U format. The result of reading a CoNLL-U file is an instance of the Node class This work is licensed under a Creative Commons Attribution 4.", "pdf_parse": { "paper_id": "2020", "_pdf_hash": "", "abstract": [ { "text": "UDon2 is an open-source library for manipulating dependency trees represented in the CoNLL-U format. The library is compatible with the Universal Dependencies. UDon2 is aimed at developers of downstream Natural Language Processing applications that require manipulating dependency trees on the sentence level (to complement other available tools geared towards working with treebanks). 1 import udon2 2 nodes = udon2.ConllReader.read_file(\"example.conll\") 3 sing = [obj for node in nodes for obj in node.select_by(\"deprel\", \"obj\") 4 if obj.has(\"feats\", \"Number\", \"Sing\")] UDon2 is an open-source library written in C++ with Python bindings, combining the speed of C++ and the flexibility and ease-of-use of Python. UDon2 is hosted on Github (the source code is available at https://github.com/udon2/udon2), and everyone is welcome to contribute. 2 Example use cases UDon2 operates on dependency trees for individual sentences. Preparing a raw text for downstream applications requires segmenting it into sentences and then parsing every sentence to get its dependency tree stored in CoNLL-U format. The result of reading a CoNLL-U file is an instance of the Node class This work is licensed under a Creative Commons Attribution 4.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Abstract", "sec_num": null } ], "body_text": [ { "text": "Universal Dependencies (UD) is a framework unifying ways of annotating grammar for different human languages (Nivre et al., 2020) . To date, the UD community has produced more than 150 treebanks in 90 languages and a number of UD-compatible tools for processing data. Most of the available tools focus on working with treebanks, e.g. annotating textual data, validating existing treebanks or making simple edits. However, many downstream Natural Language Processing (NLP) applications require researchers to manipulate individual dependency trees. For instance, finding all subordinate clauses in the sentence might help in performing text simplification, finding all objects connected to a verb in the passive form might be useful for creating a list of candidate referents for co-reference resolution, and being able to remove certain subtrees might assist in generating reading-comprehension questions.", "cite_spans": [ { "start": 109, "end": 129, "text": "(Nivre et al., 2020)", "ref_id": "BIBREF3" } ], "ref_spans": [], "eq_spans": [], "section": "Introduction", "sec_num": "1" }, { "text": "Some of those tasks are easy to achieve with some simple scripting, but such ad-hoc solutions become difficult to maintain over time. Furthermore, they tend to lack speed and hinder large-scale experimentation, since they are typically written in high-level programming languages in presence of time pressure. To aid the community in solving these tasks, we present UDon2 -a library for manipulating UD dependency trees optimized for querying. UDon2 has a user-friendly API allowing to perform routine tasks with only a couple of lines of code. For instance, finding all nominal objects in singular requires only a code snippet below.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Introduction", "sec_num": "1" }, { "text": "representing a 'root' pseudonode of the dependency tree. The dependent of the 'root' pseudonode will be later referred to as a root word. In the section below, we present possible use cases along with the manipulations available for a generic Node instance n, and exemplify using the dependency tree in Figure 1 with its root word study being denoted as r. Figure 1 : A dependency tree for the sentence \"You should study these topics or you will fail the exam\", obtained using the ewt-model of Stanza package (Qi et al., 2020) and visualized using UDon2.", "cite_spans": [ { "start": 509, "end": 526, "text": "(Qi et al., 2020)", "ref_id": "BIBREF6" } ], "ref_spans": [ { "start": 303, "end": 311, "text": "Figure 1", "ref_id": null }, { "start": 357, "end": 365, "text": "Figure 1", "ref_id": null } ], "eq_spans": [], "section": "Introduction", "sec_num": "1" }, { "text": "Each node n has a number of accessors and mutators for its word index, universal part-of-speech (POS) tag, language-specific POS tag, lemma, form, dependency relation with its head node, universal morphological features (FEATS) or any other annotation (MISC). Each accessor can be called as n. substituting for id, upos, xpos, lemma, form, deprel, feats and misc respectively. The last two will be referred to as key-value properties. Each mutator can be called as n. = val with the same values of . The parent node of n can be accessed by calling n.parent, and the children of n can be accessed by calling n.children. While mutator for a parent is available (by calling n.parent = n1), no direct mutator for children is. Instead, calling n.add child or n.remove child is required to modify the list of children.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Accessing basic properties", "sec_num": "2.1" }, { "text": "Let T n denote a subtree rooted at n. Calling n.get subtree text() will return a textual representation of T n . For instance, calling r.get subtree text() will return the whole sentence.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Accessing basic properties", "sec_num": "2.1" }, { "text": "Comments and enhanced dependency relations are currently not supported, since those are typically not provided by existing dependency parsers.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Accessing basic properties", "sec_num": "2.1" }, { "text": "Multiword tokens are supported and can be accessed by calling n.multi word. If n belongs to any multiword token, an instance of udon2.MultiWordNode will be returned, otherwise the accessor will return None. Mutators for multi-word nodes are currently not available. Getting a textual representation of a subtree (by calling n.get subtree text()) accounts for the multiword nodes. Empty nodes 1 are currently ignored while reading CoNLL-U files.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Multiword and empty nodes", "sec_num": "2.2" }, { "text": "Querying a dependency tree for a specific type of node is useful, for instance, for finding all relative clauses of a sentence, or finding the subject of a sentence. UDon2 allows issuing a variety of queries for selecting the nodes in T n :", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Querying", "sec_num": "2.3" }, { "text": "\u2022 having a property with a specified value, by calling n.select by(, ). Here, could be substituted for the same values as in the previous section, except key-value properties. should be substituted for the desired value of the respective property. For instance, r.select by(\"upos\", \"VERB\") will return a list of Nodes corresponding to the verbs study and fail;", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Querying", "sec_num": "2.3" }, { "text": "\u2022 having specified key-value properties in the universal feature format 2 , by calling n.select having(, ), where is one of feats or misc. For instance, the nodes for words You and you will be returned after calling r.select having(\"feats\", \"Case=Nom|Person=2|PronType=Prs\"));", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Querying", "sec_num": "2.3" }, { "text": "\u2022 being direct children of n and having a specified non key-value property, by calling n.get by(, ).", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Querying", "sec_num": "2.3" }, { "text": "\u2022 having a specified chain of dependency relations, by calling n.select by deprel chain or n.get by deprel chain (if the requirement of being a direct child is added). For instance, r.select by deprel chain(\"obj.det\") will return a list of Nodes corresponding to the determiners these and the, whereas r.get by deprel chain(\"obj.det\") will return only the Node corresponding to the determiner these;", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Querying", "sec_num": "2.3" }, { "text": "\u2022 being identical to another node n', by calling n.select identical(n');", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Querying", "sec_num": "2.3" }, { "text": "\u2022 being identical to another node n' except for properties props, by calling n.select identical except(n', props) with props being a comma-separated string of property names (later referred to as a prop-string), e.g. pos, rel;", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Querying", "sec_num": "2.3" }, { "text": "A number of simpler indicator queries to check whether a specified property is present are also available and described in our online documentation 3 .", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Querying", "sec_num": "2.3" }, { "text": "Suppose we want, as a step in text simplification, to split all coordinate clauses in a sentence into separate sentences. This requires identifying the nodes corresponding to the roots of coordinate clauses, by using the querying functionality from the previous section. Each clause should then be converted to a separate dependency tree, and all coordinate conjunctions should be removed. UDon2 makes this possible via its n.prune() and n.make root() functions, where rel corresponds to the chain of dependency relations pointing at the node to be pruned. To exemplify the pruning operation, r.prune(\"conj\") will result in a subtree corresponding to the sentence \"You should study these topics\". r.make root() function will create a root pseudonode and assign it to be a parent of r.", "cite_spans": [], "ref_spans": [], "eq_spans": [], "section": "Pruning", "sec_num": "2.4" }, { "text": "If the same tree is going to be used multiple times, destructive pruning might not be a viable option. In order to avoid copying trees, which might be a time-intensive (currently not implemented) operation, UDon2 allows ignoring individual nodes or subtrees by calling n.ignore(