Gorn Address of a Graph Triple
See original GitHub issueI have some alignment code that iterates through the triples in a graph to find the alignments between nodes (or edges) and words. This generally works and I can easily add the surface alignments (ie ~e.3) to the epidata
since I already have the triple in the iteration loop. The issue is in creating the metadata alignment string (using the ISI/LDC2020T02 format). To form the string I need the Gorn address that represents the triple. I’ve seen #74 and I adapted the code at the end to create a lookup for instances, edges and attributes, which then could be used to find triples. Something like…
def get_addrress_dicts(tree):
node_dict = {}
attr_dict = {}
edge_dict = {}
for path, branch in tree.walk():
# Get the node and attribute addresses
if is_atomic(branch[1]):
address = '.'.join(map(str, path))
concept = branch[1]
if concept.startswith('"'):
attr_dict[address] = concept
else:
node_dict[address] = concept
# Get the edge addresses
if is_atomic(branch[0]) and branch[0] != '/':
address = '.'.join(map(str, path))
edge_name = branch[0]
edge_dict[address] = edge_name
return node_dict, attr_dict, edge_dict
BTW… the ISI convention for edges is to append a .r
onto the address (ie… 7-1.2.1.r) and use the address of the node it’s attached to.
The issue is that edges and attributes names aren’t unique so a lookup here by name alone, isn’t sufficient. In addition, it seems like a lot of messy coding to take a graph, re-parse it into a tree, then walk it to create a bunch of dictionaries to get the addresses to match-up to the triple. Any suggestions on a better way to do this? Ideally I’d create two functions, triple_to_address()
and address_to_triple()
since eventually for test/eval I’ll probably need to take an alignment and get the triple it represents.
In a semi-related question… are the triples ordered and specific way? Right now I’m just looping through graph.triples
when searching for alignments. However, the ordering will potentially impact my alignment code for instances when there’s more than one instance of a word. I think I need an ordering that follows (loosely) a depth first search.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Thanks for the great info. Getting the surface alignments by stripping the
~e.X
should be fairly trivial so I don’t think we need to add code to the lib for that alone. I’ll try a few things and see where I end up and let you know. This part of some other work so it may be a little bit before I have something fully functional.Ok sounds good. And thanks for the link to amrlib. It looks nice!