UNPKG

geneea-nlp-client

Version:

The TypeScript Client for Geneea Interpretor G3 API.

40 lines (39 loc) 1.67 kB
import { Node } from "./node"; /** A temporary class used during the construction of a tree of tokens or tecto-tokens. */ declare class Tree<T extends Node<T>> { readonly root: T; readonly tokens: T[]; constructor(root: T, tokens: T[]); } declare class TreeBuilder<T extends Node<T>> { private readonly nodes; /** Dependency edges between nodes. */ private readonly deps; /** * Record a single token as a node of the tree. * @param node Token to add. Its index must be correct, parent and children fields are ignored. * @returns The builder to allow chained calls. */ addNode(node: T): TreeBuilder<T>; /** * Record a collection of tokens as nodes of the tree. * @param nodes Tokens to add. Their index must be correct, parent and children fields are ignored. * @returns The builder to allow chained calls. */ addNodes(nodes: Iterable<T>): TreeBuilder<T>; /** * Record a dependency edge. The tokens connected by the edge might be added later. * @param childIdx Index of the child token (note: tokens are indexed within their sentence). * @param parentIdx Index of the parent token (note: tokens are indexed within their sentence); * @returns The builder to allow chained calls. */ addDependency(childIdx: number, parentIdx: number): TreeBuilder<T>; /** All nodes are hanged to the first one. */ addDummyDependencies(): void; private fillParents; private findRoot; private fillChildren; /** Builds a tree based on the current state. Should not be called more than once. */ build(): Tree<T> | null; } export { Tree, TreeBuilder };