decomp.semantics.uds.graph¶
Graph representations for Universal Decompositional Semantics (UDS) annotations.
This module provides the core graph infrastructure for representing UDS annotations at both sentence and document levels using NetworkX directed graphs. The graphs capture syntactic structure, semantic predicates and arguments, and the interfaces between them.
Key Components¶
- Type Aliases
NodeID: String identifiers for graph nodesEdgeKey: Tuples identifying edges between nodesNodeAttributes,EdgeAttributes: Dictionaries storing node/edge propertiesDomainType: The domain a node belongs to (‘syntax’, ‘semantics’, ‘document’)NodeType: The type of node (‘token’, ‘predicate’, ‘argument’, ‘root’)EdgeType: The type of edge (‘head’, ‘dependency’, ‘interface’)
- Classes
UDSGraph: Abstract base class providing core graph functionalityUDSSentenceGraph: Sentence-level graphs with syntax and semantics layersUDSDocumentGraph: Document-level graphs connecting multiple sentences
The graphs use a consistent naming scheme where node IDs incorporate the graph name and domain (e.g., ‘ewt-001-1-syntax-1’ for a syntax token). Edge attributes specify the domain and type of relationship between nodes.
Features include SPARQL querying via RDF conversion, graph operations for finding maximal/minimal nodes, extracting subgraphs by domain, and adding UDS annotations to existing graph structures. The sentence graphs automatically add performative nodes representing the speaker/addressee for discourse representation.
See also
decomp.semantics.uds.annotationUDS annotation classes
decomp.semantics.uds.corpusCorpus-level UDS graph collections
decomp.graph.nxNetworkX graph utilities
- class UDSGraph[source]¶
Bases:
ABCAbstract base class for sentence- and document-level graphs.
- property nodes: dict[NodeID, NodeAttributes]¶
All nodes in the graph with their attributes.
- Returns:
Mapping from node IDs to their attributes
- Return type:
dict[NodeID, NodeAttributes]
- property edges: dict[EdgeKey, EdgeAttributes]¶
All edges in the graph with their attributes.
- Returns:
Mapping from edge tuples to their attributes
- Return type:
dict[EdgeKey, EdgeAttributes]
- class UDSSentenceGraph[source]¶
Bases:
UDSGraphA Universal Decompositional Semantics sentence-level graph.
- Parameters:
graph (
DiGraph) – the NetworkX DiGraph from which the sentence-level graph is to be constructedname (
str) – the name of the graphsentence_id (
str|None, default:None) – the UD identifier for the sentence associated with this graphdocument_id (
str|None, default:None) – the UD identifier for the document associated with this graph
- property rdf: Graph¶
The graph converted to RDF format.
- Returns:
RDFLib graph representation
- Return type:
Graph
- Raises:
AttributeError – If RDFConverter is not available
- property rootid: NodeID¶
The ID of the graph’s root node.
- Returns:
The root node identifier
- Return type:
NodeID
- Raises:
ValueError – If the graph has no root or multiple roots
- query(query, query_type=None, cache_query=True, cache_rdf=True)[source]¶
Query graph using SPARQL 1.1.
- Parameters:
query_type (
str|None, default:None) – 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, default:True) – whether to cache the query; false when querying particular nodes or edges using precompiled queriesclear_rdf – whether to delete the RDF constructed for querying against. This will slow down future queries but saves a lot of memory
- Return type:
Result|dict[str,TypeAliasType] |dict[TypeAliasType,TypeAliasType]
- property syntax_subgraph: DiGraph¶
Subgraph containing only syntax nodes.
- Returns:
NetworkX subgraph with syntax nodes
- Return type:
DiGraph
- property semantics_subgraph: DiGraph¶
Subgraph containing only semantics nodes.
- Returns:
NetworkX subgraph with semantics nodes
- Return type:
DiGraph