/** * Semantic models for interpreting graphs. */ import { Graph } from './graph'; import { Constant, Role, Target, Triple, Variable } from './types'; export type _ReificationSpec = [Role, Constant, Role, Role]; type _Reified = [Constant, Role, Role]; type _Dereified = [Role, Role, Role]; type _Reification = [Triple, Triple, Triple]; export interface ModelOptions { topVariable?: Variable; topRole?: Role; conceptRole?: Role; roles?: { [key: Role]: any; }; normalizations?: { [key: Role]: Role; }; reifications?: Array<_ReificationSpec>; } export interface ModelReifyOptions { variables?: Set; } /** * Represents a semantic model for Penman graphs. * * The model defines elements such as valid roles and transformations. */ export declare class Model { reifications: Map>; dereifications: Map>; topVariable: Variable; topRole: Role; conceptRole: Role; roles: { [key: Role]: any; }; normalizations: { [key: Role]: Role; }; private _roleRe; /** * `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. * * @param options - Optional arguments. * @param options.topVariable - The variable of the graph's top. * @param options.topRole - The role linking the graph's top to the top node. * @param options.conceptRole - The role associated with node concepts. * @param options.roles - A mapping of roles to associated data. * @param options.normalizations - A mapping of roles to normalized roles. * @param options.reifications - An array of 4-tuples used to define reifications. */ constructor(options?: ModelOptions); equals(other: Model): boolean; /** * Instantiate a model from a dictionary. */ static fromDict(d: { [key: string]: any; }): Model; /** * 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. * * @param role - The role to check in the model. * @returns `true` if the role is defined by the model, otherwise `false`. */ hasRole(role: Role): boolean; private _hasRole; /** * Return `true` if `role` is inverted. */ isRoleInverted(role: Role): boolean; /** * Invert `role`. */ invertRole(role: Role): Role; /** * 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. * * @param triple - The triple to invert. * @returns The inverted or deinverted triple. */ invert(triple: 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. * * @param triple - The triple to de-invert if necessary. * @returns The de-inverted triple, or the original triple if it wasn't inverted. */ deinvert(triple: Triple): Triple; /** * 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 * * @param role - The role to be canonicalized. * @returns The canonicalized role. */ canonicalizeRole(role: Role): Role; private _canonicalizeInversion; /** * 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`. * * @param triple - The triple to be canonicalized. * @returns The canonicalized triple. */ canonicalize(triple: Triple): Triple; /** * Return `true` if `role` can be reified. */ isRoleReifiable(role: Role): boolean; /** * 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. * * @param triple - The triple to reify. * @param options - Optional arguments. * @param options.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`. * @throws {ModelError} - If the role of `triple` does not have a defined reification. */ reify(triple: Triple, options?: ModelReifyOptions): _Reification; /** * Return `true` if `concept` can be dereified. */ isConceptDereifiable(concept: Target): boolean; /** * 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. * * @param instanceTriple - The triple containing the node's concept. * @param sourceTriple - The source triple from the node. * @param targetTriple - The target triple from the node. * @returns The triple that dereifies the three argument triples. * @throws {ModelError} - If dereification conditions are not met. * @throws {ValueError} - If `instanceTriple` is not valid or if any triple has a different source. */ dereify(instanceTriple: Triple, sourceTriple: Triple, targetTriple: Triple): Triple; /** * Role sorting key that does not change the order. */ originalOrder(_role: Role): boolean; /** * Role sorting key for alphanumeric order. */ alphanumericOrder(role: Role): [string, number]; /** * Role sorting key that finds a canonical order. */ canonicalOrder(role: Role): [boolean, [string, number]]; /** * Role sorting key that randomizes the order. */ randomOrder(_role: Role): number; /** * 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. * * @param graph - The graph to check for errors. * @returns An object describing detected model errors in the graph. * @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'] */ errors(graph: Graph): { [key: string]: string[]; }; } export {};