geneea-nlp-client
Version:
The TypeScript Client for Geneea Interpretor G3 API.
68 lines (67 loc) • 2.97 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Sentence = void 0;
const char_span_1 = require("../../common/char-span");
const common_1 = require("../../common/common");
/** A single sentence with its morphological, syntactical, deep-syntactical and sentimental analysis. */
class Sentence {
/**
*
* @param id ID of the sentence used to refer to it from other objects.
* @param root Token which is the root of the syntactic structure of the sentence.
* @param tokens All tokens of the sentence ordered by word-order.
* @param tectoRoot Tecto token which is the root of the tecto structure of the sentence.
* @param tectoTokens All tecto tokens of the sentence; the order has no meaning; null if not avaialable.
* @param sentiment Optional sentiment of the sentence.
* @param vectors Optional vectors of this paragraph.
*/
constructor(id, root, tokens, tectoRoot, tectoTokens, sentiment, vectors) {
this.id = id;
this.root = root;
this.tokens = tokens;
this.tectoRoot = tectoRoot;
this.tectoTokens = tectoTokens;
this.sentiment = sentiment;
this.vectors = vectors;
}
/** Sentence factory method, public constructor. */
static of(id, root, tokens, tectoRoot = null, tectoTokens = null, sentiment = null, vectors = null) {
return new Sentence(id, root, tokens, tectoRoot, tectoTokens, sentiment, vectors);
}
/** Text span within the paragraph. */
charSpan() {
return char_span_1.CharSpan.of(this.tokens[0].charSpan.start, this.tokens[this.tokens.length - 1].charSpan.end);
}
/** Text of the sentence, possibly after correction. */
text() {
return this.charSpan().extractText(this.paragraph.text);
}
/** Text span within the original paragraph. */
origCharSpan() {
return char_span_1.CharSpan.of(this.tokens[0].origCharSpan.start, this.tokens[this.tokens.length - 1].origCharSpan.end);
}
/** Text of the sentence in the original paragraph. */
origText() {
return this.origCharSpan().extractText(this.paragraph.origText);
}
toString() {
return (0, common_1.objToStr)(this, [
"id",
"tokens",
"root",
"tectoRoot",
"tectoTokens",
"sentiment",
"vectors",
]);
}
}
exports.Sentence = Sentence;
/** Type of a paragraph representing a title of the whole document. Also used for email subjects. */
Sentence.TYPE_TITLE = "TITLE";
/** Type of a paragraph representing an abstract (lead or perex) of the whole document. */
Sentence.TYPE_ABSTRACT = "ABSTRACT";
/** Type of a paragraph containing regular text (for now this is used for the whole body of the document). */
Sentence.TYPE_BODY = "BODY";
/** Type of a paragraph representing a section/chapter heading (not used yet). */
Sentence.TYPE_SECTION_HEADING = "section_heading";