/** Options for configuring the Naive Bayes classifier. */ interface NaivebayesOptions { /** Custom tokenization function. Receives text, must return an array of tokens. */ tokenizer?: (text: string) => string[]; /** Transform tokens after tokenization (e.g. stopword removal, stemming). */ tokenPreprocessor?: (tokens: string[]) => string[]; /** Additive (Laplace) smoothing parameter. Default: 1. */ alpha?: number; /** Whether to use learned prior probabilities. Default: true. */ fitPrior?: boolean; } /** A single category likelihood result. */ interface Likelihood { category: string; logLikelihood: number; logProba: number; proba: number; } /** The result of a categorize() call. */ interface CategorizeResult { likelihoods: Likelihood[]; predictedCategory: string | null; } /** An influential token result. */ interface InfluentialToken { token: string; probability: number; frequency: number; } /** Per-category statistics. */ interface CategoryStats { docCount: number; wordCount: number; vocabularySize: number; } /** Result of getCategoryStats(). */ interface CategoryStatsResult { [category: string]: CategoryStats; } /** A batch learning item. */ interface BatchItem { text: string; category: string; } /** Keys used to serialize a classifier's state. */ declare const STATE_KEYS: readonly ["categories", "docCount", "totalDocuments", "vocabulary", "vocabularySize", "wordCount", "wordFrequencyCount", "options"]; declare class Naivebayes { options: NaivebayesOptions; tokenizer: (text: string) => string[]; tokenPreprocessor: ((tokens: string[]) => string[]) | null; alpha: number; fitPrior: boolean; vocabulary: Record; vocabularySize: number; totalDocuments: number; docCount: Record; wordCount: Record; wordFrequencyCount: Record>; categories: Record; constructor(options?: NaivebayesOptions); /** Tokenize text and optionally apply the preprocessor. */ tokenize(text: string): string[]; /** Initialize data structure entries for a new category. */ initializeCategory(categoryName: string): this; /** Remove a category and all its associated data. */ removeCategory(categoryName: string): this; /** Train the classifier: associate `text` with `category`. */ learn(text: string, category: string): this; /** Untrain the classifier: remove association of `text` with `category`. */ unlearn(text: string, category: string): this; /** Determine what category `text` belongs to. */ categorize(text: string): CategorizeResult; /** Like categorize(), but returns only the top N most likely categories. */ categorizeTopN(text: string, n: number): CategorizeResult; /** Categorize with a confidence threshold. Returns null predictedCategory if below threshold. */ categorizeWithConfidence(text: string, threshold: number): CategorizeResult; /** Get the top N most influential tokens for a text's classification. */ topInfluentialTokens(text: string, n?: number): InfluentialToken[]; /** Calculate probability that a token belongs to a category. */ tokenProbability(token: string, category: string): number; /** Build a frequency hashmap from an array of tokens. */ frequencyTable(tokens: string[]): Record; /** Serialize the classifier's state as a JSON string. */ toJson(): string; /** Get an array of all category names the classifier has learned. */ getCategories(): string[]; /** Learn from multiple text/category pairs at once. */ learnBatch(items: BatchItem[]): this; /** Reset the classifier to its initial untrained state, preserving options. */ reset(): this; /** Get statistics about each category's training data. */ getCategoryStats(): CategoryStatsResult; } /** Restore a classifier from its JSON representation. */ declare function fromJson(jsonStrOrObject: string | object, options?: NaivebayesOptions): Naivebayes; interface ClassifierFactory { (options?: NaivebayesOptions): Naivebayes; fromJson: typeof fromJson; STATE_KEYS: typeof STATE_KEYS; Naivebayes: typeof Naivebayes; } declare const bayes: ClassifierFactory; export { type BatchItem, type CategorizeResult, type CategoryStats, type CategoryStatsResult, type ClassifierFactory, type InfluentialToken, type Likelihood, Naivebayes, type NaivebayesOptions, STATE_KEYS, bayes as default, fromJson };