penman.graph#
Data structures for Penman graphs and triples.
- class penman.graph.Graph(triples=None, top=None, epidata=None, metadata=None)[source]#
A basic class for modeling a rooted, directed acyclic graph.
A Graph is defined by a list of triples, which can be divided into two parts: a list of graph edges where both the source and target are variables (node identifiers), and a list of node attributes where only the source is a variable and the target is a constant. The raw triples are available via the
triples
attribute, while theinstances()
,edges()
andattributes()
methods return only those that are concept relations, relations between nodes, or relations between a node and a constant, respectively.- Parameters:
triples – an iterable of triples (
Triple
or 3-tuples)top – the variable of the top node; if unspecified, the source of the first triple is used
epidata – a mapping of triples to epigraphical markers
metadata – a mapping of metadata types to descriptions
Example
>>> from penman.graph import Graph >>> Graph([('b', ':instance', 'bark-01'), ... ('d', ':instance', 'dog'), ... ('b', ':ARG0', 'd')]) <Graph object (top=b) at ...>
- top#
The top variable.
- triples#
The list of triples that make up the graph.
- epidata#
Epigraphical data that describe how a graph is to be expressed when serialized.
- metadata#
Metadata for the graph.
- edges(source=None, role=None, target=None)[source]#
Return edges filtered by their source, role, or target.
Edges don’t include terminal triples (concepts or attributes).
- attributes(source=None, role=None, target=None)[source]#
Return attributes filtered by their source, role, or target.
Attributes don’t include concept triples or those where the target is a nonterminal.
- reentrancies()[source]#
Return a mapping of variables to their re-entrancy count.
A re-entrancy is when more than one edge selects a node as its target. These graphs are rooted, so the top node always has an implicit entrancy. Only nodes with re-entrancies are reported, and the count is only for the entrant edges beyond the first. Also note that these counts are for the interpreted graph, not for the linearized form, so inverted edges are always re-entrant.
- class penman.graph.Triple(source, role, target)[source]#
A relation between nodes or between a node and an constant.
- Parameters:
source – the source variable of the triple
role – the edge label between the source and target
target – the target variable or constant
- source#
The source variable of the triple.
- role#
The edge label between the source and target.
- target#
The target variable or constant.