Skip to main content

Class: StatisticalUtilityAI

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:89

Interface

IUtilityAI Defines the contract for a comprehensive Utility AI service.

Implements

Constructors

Constructor

new StatisticalUtilityAI(utilityId?): StatisticalUtilityAI

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:135

Parameters

utilityId?

string

Returns

StatisticalUtilityAI

Properties

utilityId

readonly utilityId: string

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:90

Implementation of

IUtilityAI.utilityId

Methods

analyzeSentiment()

analyzeSentiment(text, options?): Promise<SentimentResult>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:460

Parameters

text

string

options?

SentimentAnalysisOptions

Returns

Promise<SentimentResult>

Implementation of

IUtilityAI.analyzeSentiment


calculateReadability()

calculateReadability(text, options): Promise<ReadabilityResult>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:607

Parameters

text

string

options

ReadabilityOptions

Returns

Promise<ReadabilityResult>

Implementation of

IUtilityAI.calculateReadability


calculateSimilarity()

calculateSimilarity(text1, text2, options?): Promise<number>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:392

Parameters

text1

string

text2

string

options?

SimilarityOptions

Returns

Promise<number>

Implementation of

IUtilityAI.calculateSimilarity


checkHealth()

checkHealth(): Promise<{ dependencies?: object[]; details?: any; isHealthy: boolean; }>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:664

Returns

Promise<{ dependencies?: object[]; details?: any; isHealthy: boolean; }>

Implementation of

IUtilityAI.checkHealth


classifyText()

classifyText(textToClassify, options): Promise<ClassificationResult>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:290

Parameters

textToClassify

string

options

ClassificationOptions

Returns

Promise<ClassificationResult>

Implementation of

IUtilityAI.classifyText


detectLanguage()

detectLanguage(text, options?): Promise<LanguageDetectionResult[]>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:521

Detect the language of a text string using trigram frequency analysis.

Uses a Cavnar & Trenkle style algorithm that compares the input text's trigram frequency profile against pre-computed reference profiles for 20+ languages. Accuracy improves with longer text; passages under 10 characters return 'und' (undetermined).

Parameters

text

string

The input text to analyse.

options?

LanguageDetectionOptions

maxCandidates controls how many ranked results to return (default 3). The method field is accepted but only 'n_gram' (the default) is supported by this statistical implementation.

Returns

Promise<LanguageDetectionResult[]>

Ranked array of { language, confidence } where language is an ISO 639-1 code (e.g. 'en', 'fr') and confidence is in the range 0-1.

Implementation of

IUtilityAI.detectLanguage


extractKeywords()

extractKeywords(textToAnalyze, options?): Promise<string[]>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:355

Parameters

textToAnalyze

string

options?

KeywordExtractionOptions

Returns

Promise<string[]>

Implementation of

IUtilityAI.extractKeywords


generateNGrams()

generateNGrams(tokens, options): Promise<Record<number, string[][]>>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:586

Parameters

tokens

string[]

options

NGramOptions

Returns

Promise<Record<number, string[][]>>

Implementation of

IUtilityAI.generateNGrams


initialize()

initialize(config): Promise<void>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:147

Parameters

config

StatisticalUtilityAIConfig

Returns

Promise<void>

Implementation of

IUtilityAI.initialize


loadTrainedModel()

loadTrainedModel(modelId, modelType?, storagePath?): Promise<{ message?: string; success: boolean; }>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:744

Parameters

modelId

string

modelType?

string

storagePath?

string

Returns

Promise<{ message?: string; success: boolean; }>

Implementation of

IUtilityAI.loadTrainedModel


normalizeText()

normalizeText(text, options?): Promise<string>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:542

Parameters

text

string

options?

TextNormalizationOptions

Returns

Promise<string>

Implementation of

IUtilityAI.normalizeText


parseJsonSafe()

parseJsonSafe<T>(jsonString, options?): Promise<T | null>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:787

Safely parses a string that is expected to be JSON, potentially using an LLM to fix common issues.

Type Parameters

T

T = any

The expected type of the parsed JSON object.

Parameters

jsonString

string

The string to parse.

options?

ParseJsonOptions<T>

Options for parsing and fixing.

Returns

Promise<T | null>

The parsed object, or null if parsing and fixing fail.

Implementation of

IUtilityAI.parseJsonSafe


saveTrainedModel()

saveTrainedModel(modelId, modelType?, storagePath?): Promise<{ message?: string; pathOrStoreId?: string; success: boolean; }>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:716

Parameters

modelId

string

modelType?

string

storagePath?

string

Returns

Promise<{ message?: string; pathOrStoreId?: string; success: boolean; }>

Implementation of

IUtilityAI.saveTrainedModel


shutdown()

shutdown(): Promise<void>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:803

Returns

Promise<void>

Implementation of

IUtilityAI.shutdown


stemTokens()

stemTokens(tokens, options?): Promise<string[]>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:386

Parameters

tokens

string[]

options?

StemmingOptions

Returns

Promise<string[]>

Implementation of

IUtilityAI.stemTokens


summarize()

summarize(textToSummarize, options?): Promise<string>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:263

Parameters

textToSummarize

string

options?

SummarizationOptions

Returns

Promise<string>

Implementation of

IUtilityAI.summarize


tokenize()

tokenize(text, options?): Promise<string[]>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:368

Parameters

text

string

options?

TokenizationOptions

Returns

Promise<string[]>

Implementation of

IUtilityAI.tokenize


trainModel()

trainModel(trainingData, modelType, trainingOptions?): Promise<{ message?: string; modelId?: string; success: boolean; }>

Defined in: packages/agentos/src/nlp/ai_utilities/StatisticalUtilityAI.ts:680

Parameters

trainingData

object[]

modelType

string

trainingOptions?
alpha?

number

modelId?

string

stemmer?

"porter" | "lancaster"

Returns

Promise<{ message?: string; modelId?: string; success: boolean; }>

Implementation of

IUtilityAI.trainModel