Skip to main content

model

Class: Model

Represents a semantic model for Penman graphs.

The model defines elements such as valid roles and transformations.

constructor

new Model(options?): Model

options consists of the following:

  • topVariable: The variable of the graph's top.
  • topRole: The role linking the graph's top to the top node.
  • conceptRole: The role associated with node concepts.
  • roles: A mapping of roles to associated data.
  • normalizations: A mapping of roles to normalized roles.
  • reifications: An array of 4-tuples used to define reifications.

conceptRole

conceptRole: string


dereifications

dereifications: Map<Constant, _Dereified[]>


normalizations

normalizations: Object

Index signature

▪ [key: Role]: Role


reifications

reifications: Map<string, _Reified[]>


roles

roles: Object

Index signature

▪ [key: Role]: any


topRole

topRole: string


topVariable

topVariable: string


alphanumericOrder

alphanumericOrder(role): [string, number]

Role sorting key for alphanumeric order.


canonicalOrder

canonicalOrder(role): [boolean, [string, number]]

Role sorting key that finds a canonical order.


canonicalize

canonicalize(triple): Triple

Canonicalize triple.

The role in the triple is canonicalized following the procedure described in the canonicalizeRole method. Unlike a method such as invert, this function does not swap the source and target of triple.


canonicalizeRole

canonicalizeRole(role): string

Canonicalize role.

Role canonicalization will perform the following actions:

  • 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

deinvert

deinvert(triple): Triple

De-invert triple if it is inverted.

Unlike a method such as invert, this only inverts a triple if the model considers it to be already inverted, otherwise it is left unchanged. Unlike a method such as canonicalize, this will not normalize multiple inversions or replace the role with a normalized form.


dereify

dereify(instanceTriple, sourceTriple, targetTriple): Triple

Return the triple that dereifies the three argument triples.

If the target of instanceTriple does not have a defined dereification, or if the roles of sourceTriple and targetTriple do not match those for the dereification of the concept, a ModelError exception is raised. A ValueError is raised if instanceTriple is not an instance triple or any triple does not have the same source variable as the others.

Throws

  • If dereification conditions are not met.

Throws

  • If instanceTriple is not valid or if any triple has a different source.

equals

equals(other): boolean


errors

errors(graph): Object

Return a description of model errors detected in graph.

The description is an object mapping a context to a list of errors. A context is a triple if the error is relevant for the triple, or null for general graph errors.

Example

import { amrModel, Graph } from 'penman-js';

const g = new Graph([
['a', ':instance', 'alpha'],
['a', ':foo', 'bar'],
['b', ':instance', 'beta']
]);

for (const [context, errors] of Object.entries(amrModel.errors(g))) {
console.log(context, errors);
}

// ['a', ':foo', 'bar'] ['invalid role']
// ['b', ':instance', 'beta'] ['unreachable']

hasRole

hasRole(role): boolean

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 a method like canonicalizeRole could return a valid role.


invert

invert(triple): Triple

Invert triple.

This will invert or deinvert a triple regardless of its current state. A method like deinvert will deinvert a triple only if it is already inverted. Unlike a method like canonicalize, this will not perform multiple inversions or replace the role with a normalized form.


invertRole

invertRole(role): string

Invert role.


isConceptDereifiable

isConceptDereifiable(concept): boolean

Return true if concept can be dereified.


isRoleInverted

isRoleInverted(role): boolean

Return true if role is inverted.


isRoleReifiable

isRoleReifiable(role): boolean

Return true if role can be reified.


originalOrder

originalOrder(_role): boolean

Role sorting key that does not change the order.


randomOrder

randomOrder(_role): number

Role sorting key that randomizes the order.


reify

reify(triple, options?): _Reification

Return the three triples that reify triple.

Note that, unless variables is provided, 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 exception is raised.

options consists of the following:

  • variables: A set of variables that should not be used for the reified node's variable.

Throws

  • If the role of triple does not have a defined reification.

fromDict

fromDict(d): Model

Instantiate a model from a dictionary.