Semantic models for interpreting graphs.
Model(top_variable='top', top_role=':TOP', concept_role=':instance', roles=None, normalizations=None, reifications=None)¶
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
Instantiate a model from a dictionary.
Trueif role is defined by the model.
If role is not in the model but a single deinversion of role is in the model, then
Trueis returned. Otherwise
Falseis 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
Nonefor 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']
Trueif role is inverted.
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.
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.
Role canonicalization will do the following:
Ensure the role starts with ‘:’
Normalize multiple inversions (e.g.,
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
Trueif role can be reified.
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
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.
Trueif concept can be dereified.
dereify(instance_triple, source_triple, target_triple)¶
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
ModelErroris raised. A
ValueErroris 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.