zensols.amr.wlk package

Submodules

zensols.amr.wlk.amr_similarity module

zensols.amr.wlk.graph_helpers module

class zensols.amr.wlk.graph_helpers.GraphParser(input_format='penman', edge_to_node_transform=False)[source]

Bases: object

__init__(input_format='penman', edge_to_node_transform=False)[source]
graphs_to_triples(string_graphs)[source]
parse(string_graphs)[source]
zensols.amr.wlk.graph_helpers.add_edges(G, triples, src_tgt_index_map)[source]

add edges to graph.

Parameters:
  • G (nx medi graph) – a graph

  • triples (list) – list with (s, rel, t) tuples

  • src_tgt_index_map (dict) – a map from amr variables to node ids

Returns:

None

zensols.amr.wlk.graph_helpers.add_nodes(G, nodelist, label_map)[source]

add nodes to a graph

Parameters:
  • G (nx medi graph) – input graph

  • nodelist (list) – a list with node ids to be inserted into G

  • label_map (dict) – a map node id –> label (e.g., {0:”boy”, …})

Returns:

None

zensols.amr.wlk.graph_helpers.amrtriples2nxmedigraph(triples, edge_to_node_transform=False)[source]

builds nx medi graph from amr triples.

Parameters:
  • triples (list) – list with AMR triples, e.g. [(“a”, “:instance”, “boy”), (“r”, “:arg0”, “b”), …]

  • add_coref_to_labels (bool) – if true then add (redundant) coref info to node labels (default: False)

Returns:

nx multi edge di graph where nodes are ids and nodes and labels carry attribute “label”.

zensols.amr.wlk.graph_helpers.do_edge_node_transform(triples)[source]
zensols.amr.wlk.graph_helpers.get_var_concept_map(triples)[source]
creates a dictionary that maps varibales to their concepts

e.g., [(x, :instance, y),…] —> {x:y,…}

Parameters:

triples (list) – triples

Returns:

dictionary

zensols.amr.wlk.graph_helpers.get_var_index_map(triples)[source]
creates a dictionary that maps varibales to indeces

e.g., [(x, :instance, y),…] —> {x:y,…}

Parameters:

triples (list) – triples

Returns:

dictionary

zensols.amr.wlk.graph_helpers.maybe_fix_if_concept_node_same_as_var_node(triples)[source]
zensols.amr.wlk.graph_helpers.nx_digraph_to_triples(G)[source]

convert nx graph to triples. Attention: there may be info loss

zensols.amr.wlk.graph_helpers.penmangraph2triples(G)[source]
zensols.amr.wlk.graph_helpers.reify_nodes(triples)[source]
zensols.amr.wlk.graph_helpers.stringamr2graph(string)[source]

uses penman to convert serialized AMR to penman graph

Parameters:

string (str) – serialized AMR ‘(n / concept :arg1 ()…)’

Returns:

penman graph object

zensols.amr.wlk.graph_helpers.triples2penmangraph(triples)[source]
zensols.amr.wlk.graph_helpers.tsv2triples(string)[source]

Parses tsv graph to triples

Parameters:

string (str) –

tsv graph e.g.

x y :edge_1 y z :edge_2 z x :edge_3 x dog :instance y cat :instance z like :instance

defines a graph between source and target nodes with edge labels. Node labels are indicated with special :instance edge

Returns:

triples

zensols.amr.wlk.score module

Module contents

Weisfeiler-Leman Graph Kernels for AMR Graph Similarity

Juri Opitz, Angel Daza, and Anette Frank. 2021. Weisfeiler-Leman in the Bamboo: Novel AMR Graph Metrics and a Benchmark for AMR Graph Similarity. Transactions of the Association for Computational Linguistics, 9:1425–1441.

see:

WLK