UNPKG

whichx

Version:

A text description classifier for classifying arbitrary strings into provided labels

88 lines 3.26 kB
export = WhichX; /** * @typedef {Object} Config The WhichX configuration options. * @property {string[]} stopwords The list of stop words in the text. Those words will be ignored during the classification process. */ /** * @typedef {Object} LabelEntry * @property {number} tcount The total number of those labels. * @property {number} wordTotal The total number of words added against that label. */ /** @typedef {Record<string, LabelEntry>} TypeMap The map of labels and descriptions. */ /** * Defining the Whichx object. * @param {Config=} config The optional configuration for WhichX. */ declare function WhichX(config?: Config | undefined): void; declare class WhichX { /** * @typedef {Object} Config The WhichX configuration options. * @property {string[]} stopwords The list of stop words in the text. Those words will be ignored during the classification process. */ /** * @typedef {Object} LabelEntry * @property {number} tcount The total number of those labels. * @property {number} wordTotal The total number of words added against that label. */ /** @typedef {Record<string, LabelEntry>} TypeMap The map of labels and descriptions. */ /** * Defining the Whichx object. * @param {Config=} config The optional configuration for WhichX. */ constructor(config?: Config | undefined); /** * Add a label or list of labels to the classifier. * @param {string | string[]} labels A label or a list of labels to add. */ addLabels: (labels: string | string[]) => void; /** * Add word data from a description to a specified label. * @param {string} label The label the description must be attached to. * @param {string} description The description matching the label. */ addData: (label: string, description: string) => void; /** * Take a description and find the most likely label for it. * @param {string} description The description to classify. * @returns {string} The label that best matches the description. */ classify: (description: string) => string; /** * Exports the WhichX internal data representation learned from provided. * labeled text. Please see the typesMap comments for more details. * @returns {TypeMap} A TypeMap that can be saved for later import in WhichX. */ export: () => TypeMap; /** * Imports a previously exported model. This will write over any data this instance has already learned. * @param {TypeMap} importedTypesMap The types map previously exported from WhichX */ import: (importedTypesMap: TypeMap) => void; } declare namespace WhichX { export { Config, LabelEntry, TypeMap }; } /** * The WhichX configuration options. */ type Config = { /** * The list of stop words in the text. Those words will be ignored during the classification process. */ stopwords: string[]; }; /** * The map of labels and descriptions. */ type TypeMap = Record<string, LabelEntry>; type LabelEntry = { /** * The total number of those labels. */ tcount: number; /** * The total number of words added against that label. */ wordTotal: number; }; //# sourceMappingURL=index.d.ts.map