/** * Sentiment Analysis Tool - 90% token reduction through intelligent caching * * Purpose: Analyze sentiment in logs, feedback, and communications * * Operations: * 1. analyze-sentiment - Basic sentiment analysis * 2. detect-emotions - Multi-emotion detection * 3. extract-topics - Topic extraction with relevance scoring * 4. classify-feedback - Feedback classification * 5. trend-analysis - Sentiment trend analysis over time * 6. comparative-analysis - Compare sentiments across groups * 7. batch-analyze - Batch sentiment analysis * 8. train-model - Train custom sentiment models * 9. export-results - Export analysis results * * Token Reduction Strategy: * - Sentiment score caching by text hash (92% reduction, 1-hour TTL) * - Topic model caching (95% reduction, 24-hour TTL) * - Trend aggregation caching (91% reduction, 15-min TTL) * - Emotion classifier caching (93% reduction, infinite TTL) */ import { CacheEngine } from '../../core/cache-engine.js'; import { TokenCounter } from '../../core/token-counter.js'; import { MetricsCollector } from '../../core/metrics.js'; export interface SentimentAnalysisOptions { operation: 'analyze-sentiment' | 'detect-emotions' | 'extract-topics' | 'classify-feedback' | 'trend-analysis' | 'comparative-analysis' | 'batch-analyze' | 'train-model' | 'export-results'; text?: string; texts?: string[]; language?: string; domain?: 'general' | 'technical' | 'support' | 'product'; categories?: string[]; timeRange?: { start: number; end: number; }; granularity?: 'hourly' | 'daily' | 'weekly'; dataPoints?: Array<{ text: string; timestamp: number; }>; groups?: Array<{ name: string; texts: string[]; }>; batchSize?: number; progressCallback?: (progress: number) => void; trainingData?: Array<{ text: string; sentiment: number; emotions?: Record; }>; format?: 'json' | 'csv' | 'markdown'; outputPath?: string; threshold?: { sentiment?: number; emotion?: Record; }; useCache?: boolean; cacheTTL?: number; } export interface SentimentAnalysisResult { success: boolean; data: { sentiment?: { score: number; label: 'positive' | 'neutral' | 'negative'; confidence: number; details?: { comparative: number; positiveWords: string[]; negativeWords: string[]; totalWords: number; }; }; emotions?: Array<{ emotion: 'joy' | 'anger' | 'sadness' | 'fear' | 'neutral'; score: number; confidence: number; triggers?: string[]; }>; topics?: Array<{ topic: string; relevance: number; keywords: string[]; frequency: number; }>; classification?: { category: string; confidence: number; probabilities: Record; reasoning?: string; }; trend?: Array<{ timestamp: number; sentiment: number; volume: number; movingAverage?: number; volatility?: number; }>; comparison?: Array<{ group: string; sentiment: number; emotionsBreakdown: Record; topicDistribution?: Record; sampleSize: number; }>; batch?: { totalProcessed: number; averageSentiment: number; distributionByLabel: Record; topEmotions: Array<{ emotion: string; frequency: number; }>; }; model?: { id: string; accuracy: number; precision: number; recall: number; f1Score: number; trainingSamples: number; }; export?: { format: string; path?: string; recordCount: number; size?: number; }; insights?: Array<{ type: 'sentiment_shift' | 'emotion_spike' | 'topic_emergence' | 'anomaly'; message: string; severity: 'info' | 'warning' | 'critical'; confidence: number; timestamp?: number; }>; alerts?: Array<{ type: string; message: string; threshold: number; actualValue: number; timestamp: number; }>; }; metadata: { tokensUsed?: number; tokensSaved?: number; cacheHit: boolean; processingTime: number; operation: string; textCount?: number; language?: string; }; } export declare class SentimentAnalysisTool { private cache; private tokenCounter; private metrics; private customModels; constructor(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector); /** * Main execution method following Phase 1 architecture */ run(options: SentimentAnalysisOptions): Promise; /** * Execute the requested operation */ private executeOperation; /** * Operation 1: Analyze sentiment of text */ private analyzeSentiment; /** * Operation 2: Detect emotions in text */ private detectEmotions; /** * Operation 3: Extract topics from text */ private extractTopics; /** * Operation 4: Classify feedback into categories */ private classifyFeedback; /** * Operation 5: Analyze sentiment trends over time */ private analyzeTrends; /** * Operation 6: Compare sentiment across groups */ private compareGroups; /** * Operation 7: Batch analyze multiple texts */ private batchAnalyze; /** * Operation 8: Train custom sentiment model */ private trainModel; /** * Operation 9: Export analysis results */ private exportResults; /** * Core sentiment computation using enhanced lexicon */ private computeSentiment; /** * Compute sentiment using a specific lexicon */ private computeSentimentWithLexicon; /** * Synchronous emotion detection (helper) */ private detectEmotionsSync; /** * Get sentiment label from score */ private getSentimentLabel; /** * Tokenize text into words */ private tokenize; /** * Create time buckets for trend analysis */ private createTimeBuckets; /** * Calculate moving average */ private calculateMovingAverage; /** * Calculate volatility (standard deviation) */ private calculateVolatility; /** * Generate insights from trend data */ private generateTrendInsights; /** * Generate unique model ID */ private generateModelId; /** * Convert results to CSV format */ private convertToCSV; /** * Convert results to Markdown format */ private convertToMarkdown; /** * Generate cache key */ private generateCacheKey; /** * Calculate input tokens */ private calculateInputTokens; } export declare function getSentimentAnalysisTool(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector): SentimentAnalysisTool; export declare const SENTIMENT_ANALYSIS_TOOL_DEFINITION: { name: string; description: string; inputSchema: { type: string; properties: { operation: { type: string; enum: string[]; description: string; }; text: { type: string; description: string; }; texts: { type: string; items: { type: string; }; description: string; }; language: { type: string; description: string; default: string; }; domain: { type: string; enum: string[]; description: string; default: string; }; categories: { type: string; items: { type: string; }; description: string; }; timeRange: { type: string; properties: { start: { type: string; }; end: { type: string; }; }; description: string; }; granularity: { type: string; enum: string[]; description: string; default: string; }; dataPoints: { type: string; items: { type: string; properties: { text: { type: string; }; timestamp: { type: string; }; }; }; description: string; }; groups: { type: string; items: { type: string; properties: { name: { type: string; }; texts: { type: string; items: { type: string; }; }; }; }; description: string; }; format: { type: string; enum: string[]; description: string; default: string; }; useCache: { type: string; description: string; default: boolean; }; cacheTTL: { type: string; description: string; }; }; required: string[]; }; }; //# sourceMappingURL=sentiment-analysis.d.ts.map