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 the instances(), edges() and attributes() methods return only those that are concept relations, relations between nodes, or relations between a node and a constant, respectively.

  • 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


>>> from penman.graph import Graph
>>> Graph([('b', ':instance', 'bark-01'),
...        ('d', ':instance', 'dog'),
...        ('b', ':ARG0', 'd')])
<Graph object (top=b) at ...>

The top variable.


The list of triples that make up the graph.


Epigraphical data that describe how a graph is to be expressed when serialized.


Metadata for the graph.


Return instances (concept triples).

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.


Return the set of variables (nonterminal node identifiers).


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.

  • source – the source variable of the triple

  • role – the edge label between the source and target

  • target – the target variable or constant


The source variable of the triple.


The edge label between the source and target.


The target variable or constant.

class penman.graph.Instance(source, role, target)[source]#

Bases: Triple

A relation indicating the concept of a node.

class penman.graph.Edge(source, role, target)[source]#

Bases: Triple

A relation between nodes.

class penman.graph.Attribute(source, role, target)[source]#

Bases: Triple

A relation between a node and a constant.