decomp.semantics.uds.graph

Module for representing UDS sentence and document graphs.

class decomp.semantics.uds.graph.UDSDocumentGraph(graph, name)

A Universal Decompositional Semantics document-level graph

Parameters
  • graph (DiGraph) – the NetworkX DiGraph from which the document-level graph is to be constructed

  • name (str) – the name of the graph

add_annotation(node_attrs, edge_attrs, sentence_ids)

Add node and or edge annotations to the graph

Parameters
  • node_attrs (Dict[str, Dict[str, Any]]) – the node annotations to be added

  • edge_attrs (Dict[str, Dict[str, Any]]) – the edge annotations to be added

  • sentence_ids (Dict[str, str]) – the IDs of all sentences in the document

Return type

None

class decomp.semantics.uds.graph.UDSGraph(graph, name)

Abstract base class for sentence- and document-level graphs

Parameters
  • graph (DiGraph) – a NetworkX DiGraph

  • name (str) – a unique identifier for the graph

property edges

All the edges in the graph

classmethod from_dict(graph, name='UDS')

Construct a UDSGraph from a dictionary

Parameters
  • graph (Dict[str, Any]) – a dictionary constructed by networkx.adjacency_data

  • name (str) – identifier to append to the beginning of node ids

Return type

UDSGraph

property nodes

All the nodes in the graph

to_dict()

Convert the graph to a dictionary

Return type

Dict

class decomp.semantics.uds.graph.UDSSentenceGraph(graph, name, sentence_id=None, document_id=None)

A Universal Decompositional Semantics sentence-level graph

Parameters
  • graph (DiGraph) – the NetworkX DiGraph from which the sentence-level graph is to be constructed

  • name (str) – the name of the graph

  • sentence_id (Optional[str]) – the UD identifier for the sentence associated with this graph

  • document_id (Optional[str]) – the UD identifier for the document associated with this graph

add_annotation(node_attrs, edge_attrs, add_heads=True, add_subargs=False, add_subpreds=False, add_orphans=False)

Add node and or edge annotations to the graph

Parameters
  • node_attrs (Dict[str, Dict[str, Any]]) –

  • edge_attrs (Dict[str, Dict[str, Any]]) –

  • add_heads (bool) –

  • add_subargs (bool) –

  • add_subpreds (bool) –

  • add_orphans (bool) –

Return type

None

argument_edges(nodeid=None)

The edges between predicates and their arguments

Parameters

nodeid (Optional[str]) – The node that must be incident on an edge

Return type

Dict[Tuple[str, str], Dict[str, Any]]

argument_head_edges(nodeid=None)

The edges between nodes and their semantic heads

Parameters

nodeid (Optional[str]) – The node that must be incident on an edge

Return type

Dict[Tuple[str, str], Dict[str, Any]]

property argument_nodes: Dict[str, Dict[str, Any]]

The argument (semantics) nodes in the graph

Return type

Dict[str, Dict[str, Any]]

head(nodeid, attrs=['form'])

The head corresponding to a semantics node

Parameters
  • nodeid (str) – the node identifier for a semantics node

  • attrs (List[str]) – a list of syntax node attributes to return

Return type

Tuple[int, List[Any]]

Returns

  • a pairing of the head position and the requested

  • attributes

instance_edges(nodeid=None)

The edges between syntax nodes and semantics nodes

Parameters

nodeid (Optional[str]) – The node that must be incident on an edge

Return type

Dict[Tuple[str, str], Dict[str, Any]]

maxima(nodeids=None)

The nodes in nodeids not dominated by any other nodes in nodeids

Return type

List[str]

minima(nodeids=None)

The nodes in nodeids not dominating any other nodes in nodeids

Return type

List[str]

property predicate_nodes: Dict[str, Dict[str, Any]]

The predicate (semantics) nodes in the graph

Return type

Dict[str, Dict[str, Any]]

query(query, query_type=None, cache_query=True, cache_rdf=True)

Query graph using SPARQL 1.1

Parameters
  • query (Union[str, Query]) – a SPARQL 1.1 query

  • query_type (Optional[str]) – whether this is a ‘node’ query or ‘edge’ query. If set to None (default), a Results object will be returned. The main reason to use this option is to automatically format the output of a custom query, since Results objects require additional postprocessing.

  • cache_query (bool) – whether to cache the query; false when querying particular nodes or edges using precompiled queries

  • clear_rdf – whether to delete the RDF constructed for querying against. This will slow down future queries but saves a lot of memory

Return type

Union[Result, Dict[str, Dict[str, Any]]]

property rdf: Graph

The graph as RDF

Return type

Graph

property rootid

The ID of the graph’s root node

semantics_edges(nodeid=None, edgetype=None)

The edges between semantics nodes

Parameters
  • nodeid (Optional[str]) – The node that must be incident on an edge

  • edgetype (Optional[str]) – The type of edge (“dependency” or “head”)

Return type

Dict[Tuple[str, str], Dict[str, Any]]

property semantics_nodes: Dict[str, Dict[str, Any]]

The semantics nodes in the graph

Return type

Dict[str, Dict[str, Any]]

property semantics_subgraph: DiGraph

The part of the graph with only semantics nodes

Return type

DiGraph

property sentence: str

The sentence annotated by this graph

Return type

str

span(nodeid, attrs=['form'])

The span corresponding to a semantics node

Parameters
  • nodeid (str) – the node identifier for a semantics node

  • attrs (List[str]) – a list of syntax node attributes to return

Return type

Dict[int, List[Any]]

Returns

  • a mapping from positions in the span to the requested

  • attributes in those positions

syntax_edges(nodeid=None)

The edges between syntax nodes

Parameters

nodeid (Optional[str]) – The node that must be incident on an edge

Return type

Dict[Tuple[str, str], Dict[str, Any]]

property syntax_nodes: Dict[str, Dict[str, Any]]

The syntax nodes in the graph

Return type

Dict[str, Dict[str, Any]]

property syntax_subgraph: DiGraph

The part of the graph with only syntax nodes

Return type

DiGraph