transform
The transformation functions in this module alter the content of the graph. Other functions may change the shape or form of the graph without altering its content, such as:
Function: canonicalizeRoles
▸ canonicalizeRoles(t
, options?
): Tree
Normalize roles in t
so they are canonical according to model
.
This is a tree transformation rather than a graph transformation because the orientation of the pure graph's triples is not decided until the graph is configured into a tree.
options
consists of the following:
model
: A model defining role normalizations.
Example
import { PENMANCodec, amrModel, canonicalizeRoles } from 'penman-js';
const codec = new PENMANCodec();
const t = codec.parse('(c / chapter :domain-of 7)');
const canonicalizedTree = canonicalizeRoles(t, { model: amrModel });
console.log(codec.format(canonicalizedTree));
// (c / chapter
// :mod 7)
Function: reifyEdges
▸ reifyEdges(g
, options?
): Graph
Reify all edges in g
that have reifications in model
.
options
consists of the following:
model
: A model defining reifications.
Example
import { PENMANCodec, amrModel, reifyEdges } from 'penman-js';
const codec = new PENMANCodec(model);
const g = codec.decode('(c / chapter :mod 7)');
const reifiedGraph = reifyEdges(g, { model: amrModel });
console.log(codec.encode(reifiedGraph));
// (c / chapter
// :ARG1-of (_ / have-mod-91
// :ARG2 7))
Function: dereifyEdges
▸ dereifyEdges(g
, options?
): Graph
Dereify edges in g
that have reifications in model
.
options
consists of the following:
model
: A model defining reifications.
Example
import { PENMANCodec, amrModel, dereifyEdges } from 'penman-js';
const codec = new PENMANCodec({ model: amrModel });
const g = codec.decode(
`(c / chapter
:ARG1-of (_ / have-mod-91
:ARG2 7))`
);
const dereifiedGraph = dereifyEdges(g, { model: amrModel });
console.log(codec.encode(dereifiedGraph));
// (c / chapter
// :mod 7)
Function: reifyAttributes
▸ reifyAttributes(g
): Graph
Reify all attributes in g
.
Example
import { PENMANCodec, amrModel, reifyAttributes } from 'penman-js';
const codec = new PENMANCodec(amrModel);
const g = codec.decode('(c / chapter :mod 7)');
const reifiedGraph = reifyAttributes(g);
console.log(codec.encode(reifiedGraph));
// (c / chapter
// :mod (_ / 7))
Function: indicateBranches
▸ indicateBranches(g
, model
): Graph
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.
Example
import { PENMANCodec, amrModel, indicateBranches } from 'penman-js';
const codec = new PENMANCodec(amrModel);
const g = codec.decode(`
(w / want-01
:ARG0 (b / boy)
:ARG1 (g / go-02
:ARG0 b))`);
const branchedGraph = indicateBranches(g, amrModel);
console.log(codec.encode(branchedGraph));
// (w / want-01
// :TOP b
// :ARG0 (b / boy)
// :TOP g
// :ARG1 (g / go-02
// :ARG0 b))