penman.model

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.

Parameters
  • 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.

has_role(role)[source]

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.

is_role_inverted(role)[source]

Return True if role is inverted.

invert_role(role)[source]

Invert role.

invert(triple)[source]

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.

deinvert(triple)[source]

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)[source]

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)[source]

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.

is_reifiable(triple)[source]

Return True if the role of triple 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.

Parameters
  • triple – the triple to reify

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

Returns

The 3-tuple of triples that reify triple.

original_order(branch)[source]

Branch sorting key that does not change the order.

canonical_order(branch)[source]

Branch sorting key that finds a canonical order.

random_order(branch)[source]

Branch sorting key that randomizes the order.