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
-
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. OtherwiseFalse
is returned, even if something likecanonicalize_role()
could return a valid 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. Unlikecanonicalize()
, 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. Unlikecanonicalize()
, 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
becomesARG0
), but it does not change the direction of the roleReplace 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. Unlikeinvert()
, this does not swap the source and target of triple.
-
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.