Semantic models for interpreting graphs.

class penman.model.Model(top_variable='top', top_role=':TOP', concept_role=':instance', roles=None, normalizations=None, reifications=None)[source]#

A semantic model for Penman graphs.

The model defines things like valid roles and transformations.

  • top_variable – the variable of the graph’s top

  • top_role – the role linking the graph’s top to the top node

  • concept_role – the role associated with node concepts

  • roles – a mapping of roles to associated data

  • normalizations – a mapping of roles to normalized roles

  • reifications – a list of 4-tuples used to define reifications

classmethod from_dict(d)[source]#

Instantiate a model from a dictionary.


Return True if role is defined by the model.

If role is not in the model but a single deinversion of role is in the model, then True is returned. Otherwise False is returned, even if something like canonicalize_role() could return a valid role.


Return a description of model errors detected in graph.

The description is a dictionary mapping a context to a list of errors. A context is a triple if the error is relevant for the triple, or None for general graph errors.


>>> from penman.models.amr import model
>>> from penman.graph import Graph
>>> g = Graph([('a', ':instance', 'alpha'),
...            ('a', ':foo', 'bar'),
...            ('b', ':instance', 'beta')])
>>> for context, errors in model.errors(g).items():
...     print(context, errors)
('a', ':foo', 'bar') ['invalid role']
('b', ':instance', 'beta') ['unreachable']

Return True if role is inverted.


Invert role.


Invert triple.

This will invert or deinvert a triple regardless of its current state. deinvert() will deinvert a triple only if it is already inverted. Unlike canonicalize(), this will not perform multiple inversions or replace the role with a normalized form.


De-invert triple if it is inverted.

Unlike invert(), this only inverts a triple if the model considers it to be already inverted, otherwise it is left alone. Unlike canonicalize(), this will not normalize multiple inversions or replace the role with a normalized form.


Canonicalize role.

Role canonicalization will do the following:

  • Ensure the role starts with ‘:’

  • Normalize multiple inversions (e.g., ARG0-of-of becomes ARG0), but it does not change the direction of the role

  • Replace the resulting role with a normalized form if one is defined in the model


Canonicalize triple.

See canonicalize_role() for a description of how the role is canonicalized. Unlike invert(), this does not swap the source and target of triple.


Return True if role can be reified.

reify(triple, variables=None)[source]#

Return the three triples that reify triple.

Note that, unless variables is given, the node variable for the reified node is not necessarily valid for the target graph. When incorporating the reified triples, this variable should then be replaced.

If the role of triple does not have a defined reification, a ModelError is raised.

  • triple – the triple to reify

  • variables – a set of variables that should not be used for the reified node’s variable


The 3-tuple of triples that reify triple.


Return True if concept can be dereified.

dereify(instance_triple, source_triple, target_triple)[source]#

Return the triple that dereifies the three argument triples.

If the target of instance_triple does not have a defined dereification, or if the roles of source_triple and target_triple do not match those for the dereification of the concept, a ModelError is raised. A ValueError is raised if instance_triple is not an instance triple or any triple does not have the same source variable as the others.

  • instance_triple – the triple containing the node’s concept

  • source_triple – the source triple from the node

  • target_triple – the target triple from the node


The triple that dereifies the three argument triples.


Role sorting key that does not change the order.


Role sorting key for alphanumeric order.


Role sorting key that finds a canonical order.


Role sorting key that randomizes the order.