penman.transform¶
Tree and graph transformations.
-
penman.transform.
canonicalize_roles
(t, model)[source]¶ Normalize roles in t so they are canonical according to model.
This is a tree transformation instead of a graph transformation because the orientation of the pure graph’s triples is not decided until the graph is configured into a tree.
- Parameters
t – a
Tree
objectmodel – a model defining role normalizations
- Returns
A new
Tree
object with canonicalized roles.
Example
>>> from penman.codec import PENMANCodec >>> from penman.models.amr import model >>> from penman.transform import canonicalize_roles >>> codec = PENMANCodec() >>> t = codec.parse('(c / chapter :domain-of 7)') >>> t = canonicalize_roles(t, model) >>> print(codec.format(t)) (c / chapter :mod 7)
-
penman.transform.
reify_edges
(g, model)[source]¶ Reify all edges in g that have reifications in model.
- Parameters
g – a
Graph
objectmodel – a model defining reifications
- Returns
A new
Graph
object with reified edges.
Example
>>> from penman.codec import PENMANCodec >>> from penman.models.amr import model >>> from penman.transform import reify_edges >>> codec = PENMANCodec(model=model) >>> g = codec.decode('(c / chapter :mod 7)') >>> g = reify_edges(g, model) >>> print(codec.encode(g)) (c / chapter :ARG1-of (_ / have-mod-91 :ARG2 7))
-
penman.transform.
reify_attributes
(g)[source]¶ Reify all attributes in g.
- Parameters
g – a
Graph
object- Returns
A new
Graph
object with reified attributes.
Example
>>> from penman.codec import PENMANCodec >>> from penman.models.amr import model >>> from penman.transform import reify_attributes >>> codec = PENMANCodec(model=model) >>> g = codec.decode('(c / chapter :mod 7)') >>> g = reify_attributes(g) >>> print(codec.encode(g)) (c / chapter :mod (_ / 7))
-
penman.transform.
indicate_branches
(g, model)[source]¶ Insert TOP triples in g indicating the tree structure.
Note
This depends on g containing the epigraphical layout markers from parsing; it will not work with programmatically constructed Graph objects or those whose epigraphical data were removed.
- Parameters
g – a
Graph
objectmodel – a model defining the TOP role
- Returns
A new
Graph
object with TOP roles indicating tree branches.
Example
>>> from penman.codec import PENMANCodec >>> from penman.models.amr import model >>> from penman.transform import indicate_branches >>> codec = PENMANCodec(model=model) >>> g = codec.decode(''' ... (w / want-01 ... :ARG0 (b / boy) ... :ARG1 (g / go-02 ... :ARG0 b))''') >>> g = indicate_branches(g, model) >>> print(codec.encode(g)) (w / want-01 :TOP b :ARG0 (b / boy) :TOP g :ARG1 (g / go-02 :ARG0 b))