Skip to main content
Glama
ThemeExtractor.tsโ€ข1.03 kB
/** * ThemeExtractor - Extract main themes from content */ import { WritingStorage } from "../storage/WritingStorage.js"; export interface ThemeOptions { scope?: string; numThemes?: number; } export class ThemeExtractor { constructor(private storage: WritingStorage) {} async extractThemes(options?: ThemeOptions) { const { numThemes = 5 } = options || {}; const files = await this.storage.getAllFiles(); const wordFreq = new Map<string, number>(); // Simple theme extraction based on word frequency for (const file of files) { const words = file.content.toLowerCase().match(/\b\w+\b/g) || []; for (const word of words) { if (word.length > 4) { // Skip short words wordFreq.set(word, (wordFreq.get(word) || 0) + 1); } } } // Get top themes const themes = Array.from(wordFreq.entries()) .sort((a, b) => b[1] - a[1]) .slice(0, numThemes) .map(([word, count]) => ({ theme: word, count })); return themes; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/xiaolai/claude-writers-aid-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server