Skip to main content

graph

Class: Graph

Represents a basic class for modeling a rooted, directed acyclic graph.

A Graph is defined by a list of triples, which can be divided into two parts: a list of graph edges where both the source and target are variables (node identifiers), and a list of node attributes where only the source is a variable and the target is a constant. The raw triples are available via the triples property, while the instances, edges, and attributes methods return only those that are concept relations, relations between nodes, or relations between a node and a constant, respectively.

Example

import { Graph } from 'penman-js';

const graph = new Graph([
['b', ':instance', 'bark-01'],
['d', ':instance', 'dog'],
['b', ':ARG0', 'd']
]);

constructor

new Graph(triples?, options?): Graph

options consists of the following:

  • top: The variable of the top node; if unspecified, the source of the first triple is used.
  • epidata: A mapping of triples to epigraphical markers.
  • metadata: A mapping of metadata types to descriptions.

epidata

epidata: EpidataMap


metadata

metadata: Record<string, string>


triples

triples: Triples = []

An iterable of triples (either Triple objects or 3-tuples).


top

get top(): null | string

The top variable.

set top(top): void


attributes

attributes(options?): Attribute[]

Return attributes filtered by their source, role, or target. Attributes don't include concept triples or those where the target is a nonterminal.

options consists of the following:

  • source: The source variable to filter by.
  • role: The role to filter by.
  • target: The target constant to filter by.

edges

edges(options?): Edge[]

Return edges filtered by their source, role, or target. Edges don't include terminal triples (concepts or attributes).

options consists of the following:

  • source: The source variable to filter by.
  • role: The role to filter by.
  • target: The target variable to filter by.

equals

equals(other): boolean

Return true if this graph is equal to other graph

Equivalent to __eq__ in Python


instances

instances(): Instance[]

Return instances (concept triples).


ior

ior(other): Graph


isub

isub(other): Graph


or

or(other): Graph


pprint

pprint(): string

Equivalent to __repr__ in Python


reentrancies

reentrancies(): Map<string, number>

Return a mapping of variables to their re-entrancy count. A re-entrancy is when more than one edge selects a node as its target. These graphs are rooted, so the top node always has an implicit entrancy. Only nodes with re-entrancies are reported, and the count is only for the entrant edges beyond the first. Also note that these counts are for the interpreted graph, not for the linearized form, so inverted edges are always re-entrant.


sub

sub(other): Graph


toString

toString(): string


variables

variables(): Set<string>

Return the set of variables (nonterminal node identifiers).


Type alias: Triple

Ƭ Triple: [source: Variable, role: Role, target: Target]

Represents a relation between nodes or between a node and a constant.


Type alias: Instance

Ƭ Instance: [source: Variable, role: Role, target: Constant]

A relation indicating the concept of a node.


Type alias: Edge

Ƭ Edge: [source: Variable, role: Role, target: Variable]

A relation between nodes.


Type alias: Attribute

Ƭ Attribute: [source: Variable, role: Role, target: Constant]

A relation between a node and a constant.