geneea-nlp-client
Version:
The TypeScript Client for Geneea Interpretor G3 API.
117 lines (116 loc) • 5.97 kB
TypeScript
import { HasId } from "../../common/id";
import { Sentence } from "./sentence";
/**
* This is an implementation class, used as a super data class of Token and TectoToken.
* We use the word node to refer to both tokens and tecto-tokens.
* In general, we assume that any tree can be non-projective (i.e. generated by context-sensitive grammar),
* even though the linear order of tecto-tokens has no meaning.
*
* All nodes in the tree have to be of the same type: either all Tokens or all TectoTokens.
*/
declare abstract class Node<T extends Node<T>> implements HasId {
/** ID of this node used to refer to it from other objects. */
readonly id: string;
/** Zero-based index of this node reflecting its word-order position within the sentence. */
readonly idx: number;
/** Node that this node depends on. Null for the root or if no tree-structure is in the analysis. */
parent: T | null;
/** Nodes that depend on this node, ordered by word-order; empty for leafs or if no tree-structure is in the analysis. */
children: T[];
/** Sentence this node belongs to. Can be null only during construction. */
sentence: Sentence;
/** Check whether this node is a leaf (i.e has no dependents). */
isLeaf(): boolean;
/** Check whether this node is the root of the sentence. */
isRoot(): boolean;
/** Checks if the phrase dominated by this node is continuous. */
isContinuous(): boolean;
/** Children of this node that precede it. */
leftChildren(): T[];
/** Children of this node that follow it. */
rigthChildren(): T[];
/**
* Depth of this node in the dependency tree.
* @returns The distance, i.e. number of dependency edges, from the root of the sentence.
*/
depth(): number;
/** Non-recursive string representation of this node. */
abstract toSimpleString(): string;
/**
* Parenthesised representation of the subtree of this node.
* @param printToken Function printing individual nodes.
* @returns A string representation of the tree rooted in this node.
*/
toTreeString(printToken: (token: T) => string): string;
/**
* Indented string representation of the subtree of this node.
* @param printToken A function printing individual nodes.
* @param indentStr A string used to indent each level from the previous one.
* @param depth Indentation level to start with.
*/
toIndentTreeString(printToken: (token: T) => string, indentStr?: string, depth?: number): string;
/** Simple representation of this tree using toSimpleString to convert individual nodes. */
toSimpleTreeString(): string;
/** Simple indented representation of this tree using toSimpleString to convert individual nodes. */
toSimpleIndentString(): string;
/**
* All nodes dominated by this node.
* @param reflexive Whether this node itself is included.
* @param ordered Whether the result should be ordered by word order.
*/
coverage(reflexive?: boolean, ordered?: boolean): T[];
/** In-order iterator over the subtree of this node. */
inOrder(): Iterable<T>;
/**
* In-order iterator over the subtree of this node, optionally skipping some subtrees.
* @param includeFilteredRoot If true, the nodes on which [skipPredicate] returns true are included in the result.
* @param skipPredicate When this predicate is true on any node, the node's subtree is not traversed (skipping only their subtrees).
*/
filteredInOrder(includeFilteredRoot: boolean | undefined, skipPredicate: (n: T) => boolean): Iterable<T>;
/** Pre-order iterator over the subtree of this node. */
preOrder(): Iterable<T>;
/**
* Pre-order iterator over the subtree of this node, optionally skipping some subtrees.
* @param includeFilteredRoot If true, the nodes on which [skipPredicate] returns true are included in the result (skipping only their subtrees).
* @param skipPredicate When this predicate is true on any node, the node's subtree is not traversed.
*/
filteredPreOrder(includeFilteredRoot: boolean | undefined, skipPredicate: (n: T) => boolean): Iterable<T>;
}
declare class NodeUtils {
/**
* Orders the list of nodes in-place by word-order (i.e. their sentence index).
* @param tokens A list of nodes, assumed to be from the same sentence (not checked).
*/
static sort<T extends Node<T>>(tokens: T[]): T[];
/**
* Orders a copy of this list of nodes by word-order (i.e. their sentence index).
* @param tokens A list of nodes, assumed to be from the same sentenced (not checked).
*/
static sorted<T extends Node<T>>(tokens: T[]): T[];
/**
* Checks if this list of nodes is sorted by word-order (i.e. their sentence index).
* @param tokens A list of nodes, assumed to be from the same sentenced (not checked).
*/
static isSorted<T extends Node<T>>(tokens: T[]): boolean;
/**
* Checks if all nodes come from the same sentence.
* @param tokens A list of nodes.
* @returns true if the list of nodes is empty or all nodes are within the same sentence; false otherwise.
*/
static isFromSameSentence<T extends Node<T>>(tokens: T[]): boolean;
/**
* Checks if this list of nodes forms a continuous sequence.
* Assumes the nodes to be sorted and from the same sentence (not checked).
* @param tokens A list of nodes
* @returns true if the list is continuous, false otherwise.
*/
static isContinuous<T extends Node<T>>(tokens: T[]): boolean;
/**
* Utility method converting this list of nodes to a string with a simplified node representation,
* using [Node.toSimpleString].
* @param tokens A list of nodes.
* @param quote Should each node string be surrounded with double quotes?
*/
static toSimpleString<T extends Node<T>>(tokens: T[], quote?: boolean): string;
}
export { Node, NodeUtils };