UNPKG

wordmap

Version:
90 lines (89 loc) 2.49 kB
import NumberObject from "../index/NumberObject"; import Alignment from "./Alignment"; import Ngram from "./Ngram"; /** * Represents a single alignment prediction */ export default class Prediction { private predictedAlignment; private scores; /** * Returns an array of score keys * @return {string[]} */ readonly scoreKeys: string[]; /** * Returns the alignment represented by this prediction * @return {Alignment} */ readonly alignment: Alignment; /** * Convenience method to access the source n-gram of the alignment * @return {Ngram} */ readonly source: Ngram; /** * Convenience method to access the target n-gram of the alignment. * @return {Ngram} */ readonly target: Ngram; /** * Convenience method for retrieving the prediction confidence. * @return {number} */ readonly confidence: number; /** * Returns the prediction key * @return {string} */ readonly key: string; /** * Instantiates a new alignment prediction * @param {Alignment} alignment - the alignment for which a prediction will be calculated */ constructor(alignment: Alignment); /** * Sets a score for this prediction * @param {string} key - the score key * @param {number} value - the score value */ setScore(key: string, value: number): void; /** * Convenience method for setting multiple scores at a time * @param {NumberObject} scores - an object of scores */ setScores(scores: NumberObject): void; /** * Reads a single score from this prediction. * @param {string} key - the score key * @return {number} - the score value */ getScore(key: string): number; /** * Checks if the score key exists. * @param key */ hasScore(key: string): boolean; /** * Returns a copy of the prediction scores * @return {NumberObject} */ getScores(): NumberObject; /** * Checks if this prediction intersects with another prediction. * @param {Prediction} prediction * @return {boolean} */ intersects(prediction: Prediction): boolean; /** * Prints a user friendly form of the prediction * @return {string} */ toString(): string; /** * Outputs the prediction to json * @param verbose - print full metadata. * @return {object} */ toJSON(verbose?: boolean): object; }