geneea-nlp-client
Version:
The TypeScript Client for Geneea Interpretor G3 API.
106 lines (105 loc) • 4.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EntityMention = exports.Entity = void 0;
const common_1 = require("../../common/common");
const token_1 = require("./token");
/** A data class encapsulating an Entity. */
class Entity {
/**
*
* @param id ID of the entity used to refer to it from other objects.
* @param gkbId Unique identifier of this entity in Geneea knowladge base.
* @param stdForm Standard form of the entity, abstracting from alternative names.
* @param type Basic type of this entity (e.g. person, location, ...).
* @param mentions Actual occurences of this entity in the text. Empty if not requested/supported.
* @param feats Custom features/properties.
* @param sentiment Sentiment of this entity. null if not requested.
* @param vectors Optional vectors for this entity.
* @param gkbProperties GKB properties. Since 3.3.0.
*/
constructor(id, gkbId = null, stdForm, type, mentions, feats, sentiment = null, vectors = null, gkbProperties) {
this.id = id;
this.gkbId = gkbId;
this.stdForm = stdForm;
this.type = type;
this.mentions = mentions;
this.feats = feats;
this.sentiment = sentiment;
this.vectors = vectors;
this.gkbProperties = gkbProperties;
}
/** Entity factory method, public constructor. */
static of(id, gkbId = null, stdForm, type, mentions = null, feats = null, sentiment = null, vectors = null, gkbProperties = null) {
return new Entity(id, gkbId, stdForm, type, mentions !== null && mentions !== void 0 ? mentions : [], feats !== null && feats !== void 0 ? feats : new Map(), sentiment, vectors, gkbProperties !== null && gkbProperties !== void 0 ? gkbProperties : []);
}
toString() {
return (0, common_1.objToStr)(this, [
"id",
"gkbId",
"stdForm",
"type",
"mentions",
"feats",
"sentiment",
"vectors",
"gkbProperties",
]);
}
}
exports.Entity = Entity;
/** A single occurrence of an entity in the text. */
class EntityMention {
/**
*
* @param id ID of the mention used to refer to it from other objects.
* @param text The form of this entity mention, as it occurs in the text.
* @param mwl Lemma of this mention (potentially multiword lemma), i.e. base form of the entity expression.
* @param tokens Tokens of this entity mention.
* @param feats Custom features/properties.
* @param derivedFrom Entity from which this mention can be derived (e.g. mention `salmon` for entity `fish`), if applicable.
* @param sentiment Sentiment of this mention. Note: Not supported yet.
* @param vectors Optional vectors for this mention.
*/
constructor(id, text, mwl, tokens, feats, derivedFrom, sentiment, vectors) {
this.id = id;
this.text = text;
this.mwl = mwl;
this.tokens = tokens;
this.feats = feats;
this.derivedFrom = derivedFrom;
this.sentiment = sentiment;
this.vectors = vectors;
}
/** EntityMention factory method, public constructor. */
static of(id, text, mwl, tokens, feats = null, derivedFrom = null, sentiment = null, vectors = null) {
return new EntityMention(id, text, mwl, token_1.TokenSupport.of(tokens), feats !== null && feats !== void 0 ? feats : new Map(), derivedFrom, sentiment, vectors);
}
/**
* Sentence containing this entity mention.
* Entity mention belongs to maximally one sentence; artificial mentions without tokens belong to no sentence.
*/
sentence() {
return this.tokens.sentence;
}
/** Checks whether the entity mention is continuous (most are). */
isContinuous() {
return this.tokens.isContinuous;
}
/** True iff this entity mention is derived from some other entity (e.g. mention `salmon` for entity `fish`). */
isDerived() {
return this.derivedFrom != null;
}
toString() {
return (0, common_1.objToStr)(this, [
"id",
"text",
"mwl",
"tokens",
"feats",
"derivedFrom",
"sentiment",
"vectors",
]);
}
}
exports.EntityMention = EntityMention;