textanalysis-tool
Version:
A TypeScript module providing text analysis functionalities with various operations.
248 lines (247 loc) • 7.79 kB
TypeScript
/**
* @class SentimentAnalyzer
* @summary A utility class for analyzing text sentiment
*/
export declare class SentimentAnalyzer {
private positiveWords;
private negativeWords;
constructor();
/**
* @function analyze
* @summary Analyzes the sentiment of the provided text
* @param {string} text - The text to analyze
* @returns {SentimentResult} Object containing sentiment score and classification
*/
analyze(text: string): SentimentResult;
/**
* @private
* @function classifySentiment
* @summary Classifies sentiment based on score
* @param {number} score - The sentiment score
* @returns {SentimentClassification} The classification of sentiment
*/
private classifySentiment;
/**
* @function addCustomLexicon
* @summary Adds custom words to the sentiment lexicons
* @param {Object} lexicon - Object containing positive and negative word arrays
* @param {string[]} lexicon.positive - Array of positive words
* @param {string[]} lexicon.negative - Array of negative words
*/
addCustomLexicon(lexicon: {
positive?: string[];
negative?: string[];
}): void;
}
/**
* @interface SentimentResult
* @summary Result of sentiment analysis
*/
export interface SentimentResult {
score: number;
positiveWordCount: number;
negativeWordCount: number;
totalWords: number;
classification: SentimentClassification;
}
/**
* @type SentimentClassification
* @summary Classifications for sentiment analysis
*/
export type SentimentClassification = "positive" | "negative" | "neutral";
/**
* @class TextSummarizer
* @summary A utility class for summarizing text
*/
export declare class TextSummarizer {
private stopWords;
constructor();
/**
* @function extractiveSummarize
* @summary Generates an extractive summary of the text
* @param {string} text - The text to summarize
* @param {number} [sentenceCount=3] - Number of sentences in the summary
* @returns {string} Summarized text
*/
extractiveSummarize(text: string, sentenceCount?: number): string;
/**
* @private
* @function calculateWordFrequency
* @summary Calculates frequency of each word in text
* @param {string} text - Input text
* @returns {Record<string, number>} Word frequency map
*/
private calculateWordFrequency;
/**
* @function addStopWords
* @summary Adds custom stop words to the analyzer
* @param {string[]} words - Array of stop words to add
*/
addStopWords(words: string[]): void;
}
/**
* @class TextStatistics
* @summary A utility class for computing readability metrics
*/
export declare class TextStatistics {
/**
* @function fleschKincaidReadability
* @summary Calculate Flesch-Kincaid readability score
* @param {string} text - Text to analyze
* @returns {ReadabilityResult} Readability scores and metrics
*/
fleschKincaidReadability(text: string): ReadabilityResult;
/**
* @private
* @function countSyllables
* @summary Estimates syllable count in text
* @param {string} text - Input text
* @returns {number} Estimated syllable count
*/
private countSyllables;
/**
* @private
* @function estimateSyllablesInWord
* @summary Estimates syllables in a word using heuristics
* @param {string} word - Word to analyze
* @returns {number} Estimated syllable count
*/
private estimateSyllablesInWord;
/**
* @private
* @function getComplexityLabel
* @summary Get descriptive label for readability score
* @param {number} score - Flesch readability score
* @returns {string} Descriptive complexity label
*/
private getComplexityLabel;
}
/**
* @interface ReadabilityResult
* @summary Result of readability analysis
*/
export interface ReadabilityResult {
readabilityScore: number;
gradeLevel: number;
wordCount: number;
sentenceCount: number;
syllableCount: number;
avgWordsPerSentence: number;
avgSyllablesPerWord: number;
complexity: string;
}
/**
* @class LanguageDetector
* @summary Detects probable language of text
*/
export declare class LanguageDetector {
private languageProfiles;
constructor();
/**
* @private
* @function initializeLanguageProfiles
* @summary Initialize frequency profiles for common languages
*/
private initializeLanguageProfiles;
/**
* @function detect
* @summary Detects the most likely language of the text
* @param {string} text - The text to analyze
* @returns {LanguageDetectionResult} The detected language and confidence scores
*/
detect(text: string): LanguageDetectionResult;
/**
* @private
* @function createTextProfile
* @summary Creates a profile of ngrams for the input text
* @param {string} text - Input text
* @returns {Map<string, number>} Frequency map of ngrams
*/
private createTextProfile;
/**
* @private
* @function calculateSimilarity
* @summary Calculates similarity between two profiles
* @param {Map<string, number>} textProfile - Profile of analyzed text
* @param {Map<string, number>} langProfile - Profile of reference language
* @returns {number} Similarity score (0-1)
*/
private calculateSimilarity;
/**
* @function addCustomLanguage
* @summary Adds a new language profile
* @param {string} language - Name of the language
* @param {Record<string, number>} profile - Language profile as object
*/
addCustomLanguage(language: string, profile: Record<string, number>): void;
}
/**
* @interface LanguageDetectionResult
* @summary Result of language detection
*/
export interface LanguageDetectionResult {
detectedLanguage: string;
confidence: number;
scores: Record<string, number>;
}
/**
* @class TextDiff
* @summary Compare text and generate difference information
*/
export declare class TextDiff {
/**
* @function compare
* @summary Compare two texts and calculate their similarity
* @param {string} text1 - First text to compare
* @param {string} text2 - Second text to compare
* @returns {TextDiffResult} Comparison results
*/
compare(text1: string, text2: string): TextDiffResult;
/**
* @private
* @function levenshteinDistance
* @summary Calculate Levenshtein distance between two strings
* @param {string} s1 - First string
* @param {string} s2 - Second string
* @returns {number} Edit distance
*/
private levenshteinDistance;
/**
* @private
* @function findCommonSubstrings
* @summary Find common substrings between two texts
* @param {string} s1 - First string
* @param {string} s2 - Second string
* @returns {Array<{substring: string, length: number}>} Common substrings
*/
private findCommonSubstrings;
/**
* @private
* @function getWordDifference
* @summary Compare word arrays and find differences
* @param {string[]} words1 - First array of words
* @param {string[]} words2 - Second array of words
* @returns {Object} Word difference analysis
*/
private getWordDifference;
}
/**
* @interface TextDiffResult
* @summary Result of text comparison
*/
export interface TextDiffResult {
similarity: number;
editDistance: number;
commonSubstrings: Array<{
substring: string;
length: number;
}>;
wordDifference: {
added: string[];
removed: string[];
unchanged: string[];
addedCount: number;
removedCount: number;
unchangedCount: number;
};
}