UNPKG

geneea-nlp-client

Version:

The TypeScript Client for Geneea Interpretor G3 API.

65 lines (64 loc) 2.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TectoToken = void 0; const common_1 = require("../../common/common"); const node_1 = require("./node"); const token_1 = require("./token"); /** * A tecto token, i.e. a tectogrammatical abstraction of a word (e.g. "did not sleep" are three tokens but a single * tecto-token) * Tecto tokens have an zero-based index reflecting their position within their sentence. */ class TectoToken extends node_1.Node { constructor(id, idx, /** Label of the dependency edge. */ fnc, /** Tecto lemma. */ lemma, /** Grammatical and other features of the tecto token. */ feats, /** * Surface token corresponding to this tecto token; not necessarily adjacent; ordered by word-order; * Might be null, because the root or dropped phrases have no surface realization. */ tokens, /** Entity mention associated with this tecto token; null if there is no such entity. */ entityMention, /** * Legacy value: Entity associated with this tecto token; null if there is no such entity. * (Used only by F3, not by G3) */ entity) { super(); this.id = id; this.idx = idx; this.fnc = fnc; this.lemma = lemma; this.feats = feats; this.tokens = tokens; this.entityMention = entityMention; this.entity = entity; } /** TectoToken factory method, public constructor. */ static of(id, idx, fnc, lemma, feats = null, tokens = null, entityMention = null, entity = null) { let tokenSupport = null; if (tokens !== null && tokens.length > 0) { tokenSupport = new token_1.TokenSupport(node_1.NodeUtils.sorted(tokens), node_1.NodeUtils.isContinuous(tokens)); } return new TectoToken(id, idx, fnc, lemma, feats !== null && feats !== void 0 ? feats : new Map(), tokenSupport, entityMention, entity); } /** Converts the tecto token to a default non-recursive string: index + lemma. */ toSimpleString() { return this.toStringWith(true, false); } /** Converts the token to a non-recursive string: index + [lemma] + [fnc]. */ toStringWith(lemma, fnc) { const l = lemma ? `:${this.lemma}` : ""; const f = fnc ? `:${this.fnc}` : ""; return `${this.idx}${l}${f}`; } toString() { return (0, common_1.objToStr)(this, ["id", "idx", "fnc", "lemma", "feats"]); } } exports.TectoToken = TectoToken;