repair_text
Analyzes and repairs errors in transcribed text to improve accuracy, ensuring natural formatting and contextual corrections. Accepts text content or file paths for processing.
Instructions
Analyzes and repairs transcription errors with greater than 90% confidence
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input_text | Yes | Text content or path to file containing transcribed text | |
| is_file_path | No | Whether input_text is a file path |
Input Schema (JSON Schema)
{
"properties": {
"input_text": {
"description": "Text content or path to file containing transcribed text",
"type": "string"
},
"is_file_path": {
"default": false,
"description": "Whether input_text is a file path",
"type": "boolean"
}
},
"required": [
"input_text"
],
"type": "object"
}
Implementation Reference
- src/tools/repair.ts:24-124 (handler)Main handler function that executes the repair_text tool logic: resolves input, applies simulated NLP corrections for common errors, logs process, writes output file, and returns path.export async function repairText(params: RepairTextParams): Promise<{ output_file: string }> { try { const { input_text, is_file_path = false } = params; // Resolve content (either direct text or from file) const textContent = await FileHandler.resolveTextContent(input_text, is_file_path); // Create a session ID and logger const logger = new Logger(); const sessionId = logger.getSessionId(); // This would be a more complex NLP processing in a real implementation // Here we just simulate the repair process with some example corrections // Split text into words for processing const words = textContent.split(/\s+/); const totalWords = words.length; // Simulate finding and correcting errors const corrections: Array<{ original: string; corrected: string; confidence: number; context: string; evidence: string[]; }> = []; // In a real implementation, this would use NLP models to identify errors // Here we're just simulating with some basic replacements const commonErrors = [ { pattern: /recieve/gi, replacement: 'receive', confidence: 95 }, { pattern: /defiantly/gi, replacement: 'definitely', confidence: 93 }, { pattern: /irregardless/gi, replacement: 'regardless', confidence: 91 }, { pattern: /alot/gi, replacement: 'a lot', confidence: 97 }, { pattern: /seperate/gi, replacement: 'separate', confidence: 94 } ]; // Process the text let repairedText = textContent; let totalConfidence = 0; for (const error of commonErrors) { if (error.pattern.test(repairedText)) { // Find all instances of this error const matches = repairedText.match(error.pattern) || []; for (const match of matches) { // Get some context around the error (simulated) const contextIndex = repairedText.indexOf(match); const start = Math.max(0, contextIndex - 20); const end = Math.min(repairedText.length, contextIndex + match.length + 20); const context = repairedText.substring(start, end); corrections.push({ original: match, corrected: match.replace(error.pattern, error.replacement), confidence: error.confidence, context, evidence: [ 'Pattern recognition', 'Dictionary verification', 'Semantic analysis' ] }); totalConfidence += error.confidence; } // Apply the correction to the full text repairedText = repairedText.replace(error.pattern, error.replacement); } } // Calculate statistics const correctionsMade = corrections.length; const averageConfidence = correctionsMade > 0 ? Math.round(totalConfidence / correctionsMade) : 0; // Write the repaired text to a file const outputFile = 'repaired.txt'; await FileHandler.writeTextFile(outputFile, repairedText); // Log the repair process const stats = { totalWords, correctionsMade, averageConfidence }; const logPath = await logger.logRepairProcess( is_file_path ? input_text : 'direct_input', corrections, stats ); return { output_file: outputFile }; } catch (error) { throw new Error(`Repair process failed: ${error instanceof Error ? error.message : String(error)}`); } }
- src/tools/repair.ts:4-10 (schema)TypeScript interface defining input parameters for the repair_text tool./** * Interface for the repair_text function parameters */ export interface RepairTextParams { input_text: string; is_file_path?: boolean; }
- src/index.ts:56-72 (registration)Tool registration in listTools handler, including name, description, and input schema.name: 'repair_text', description: 'Analyzes and repairs transcription errors with greater than 90% confidence', inputSchema: { type: 'object', properties: { input_text: { type: 'string', description: 'Text content or path to file containing transcribed text' }, is_file_path: { type: 'boolean', description: 'Whether input_text is a file path', default: false } }, required: ['input_text'] }
- src/index.ts:155-168 (registration)Dispatch handler in callToolRequest that routes 'repair_text' calls to the repairText function.case 'repair_text': // Validate required parameters if (!args || typeof args.input_text !== 'string') { throw new McpError(ErrorCode.InvalidParams, 'Missing required parameter: input_text'); } const repairResult = await repairText(args as unknown as RepairTextParams); return { content: [ { type: 'text', text: JSON.stringify(repairResult, null, 2) } ] };