Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-attaching a node both in the basic tree and in the enhanced graph #112

Open
dan-zeman opened this issue Feb 13, 2023 · 1 comment
Open

Comments

@dan-zeman
Copy link
Collaborator

dan-zeman commented Feb 13, 2023

I have repeatedly encountered the following situation: A small change is needed for a batch of nodes, such as changing the DEPREL (or both the HEAD and the DEPREL) for a node that satisfies a condition. Typically I do it directly from the commandline, using udapy -s util.Eval node='if CONDITION: node.parent = X; node.deprel = Y'. Now if the treebank contains enhanced dependencies, the same change should (typically) be also made in the enhanced graph. I usually forget to do it properly but when I want to do it, it is not as simple as the change in the basic tree. I wrote the code below in some of my blocks where I had to do it but I don't like having to repeat the code in several blocks again and again, and can hardly use it in util.Eval from commandline:

    def reattach(self, node, parent, deprel):
        """
        Changes the incoming dependency relation to a node. Makes sure that the
        same change is done in the basic tree and in the enhanced graph.
        """
        if node.deps:
            # If the enhanced graph contains the current basic relation, remove it.
            # Note that the enhanced deprel may contain subtypes that are not in the basic deprel.
            orig_n_deps = len(node.deps)
            node.deps = [x for x in node.deps if x['parent'] != node.parent or re.sub(r':.*', '', x['deprel']) != node.udeprel]
            # Add the new basic relation to the enhanced graph only if the original one was there.
            if len(node.deps) < orig_n_deps:
                node.deps.append({'parent': parent, 'deprel': deprel})
        node.parent = parent
        node.deprel = deprel

Would it make sense to have something similar in the core code, as a method of Node?

@dan-zeman
Copy link
Collaborator Author

Related but more specific: #47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant