UNPKG

wordmap

Version:
44 lines (43 loc) 1.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const FrequencyIndex_1 = require("./FrequencyIndex"); /** * An index of n-gram frequencies */ class NgramIndex extends FrequencyIndex_1.default { /** * Reads a value from the index * @param ngram - the n-gram index to read. This may be a specific key, or the ngram object to read the default key. */ read(ngram) { if (typeof ngram === "string") { return this.readIndex(ngram); } else { return this.readIndex(ngram.key); } } /** * Writes a value to the index * @deprecated - use {@link increment} instead * @param {Ngram} ngram - the n-gram index to write * @param {number} value */ write(ngram, value) { this.writeIndex(ngram.key, value); } /** * Increments the n-gram frequency. * This will increment all of the important keys in the n-gram such as * the words in question, lemma, etc. * @param {Ngram} ngram - the n-gram index to add * @param {number} value */ increment(ngram, value = 1) { this.incrementIndex(ngram.key, value); if (ngram.lemmaKey !== undefined) { this.incrementIndex(ngram.lemmaKey, value); } } } exports.default = NgramIndex;