|
| 1 | +#!/usr/bin/env npx ts-node |
| 2 | +/** |
| 3 | + * AAC Scanning & Vocabulary Benchmark Script |
| 4 | + * |
| 5 | + * This script analyzes AAC pagesets (Snap, Grid 3, TouchChat) for: |
| 6 | + * 1. Scanning efficiency (steps and selections) |
| 7 | + * 2. Vocabulary coverage (core word lists) |
| 8 | + * 3. Effort scores (how hard it is to reach words) |
| 9 | + * |
| 10 | + * Usage: |
| 11 | + * npx ts-node scripts/analysis/scanning_benchmark.ts [directory_path] |
| 12 | + * |
| 13 | + * If no directory is specified, it will look in '/tmp' as an example. |
| 14 | + */ |
| 15 | + |
| 16 | +import * as fs from 'fs'; |
| 17 | +import * as path from 'path'; |
| 18 | +import { getProcessor, Analytics, AACTree, isExtensionSupported } from '../../src/index'; |
| 19 | + |
| 20 | +async function runBenchmark() { |
| 21 | + const targetDir = process.argv[2] || './tmp'; |
| 22 | + |
| 23 | + console.log(`\n🚀 AAC Scanning Benchmark`); |
| 24 | + console.log(`=========================`); |
| 25 | + console.log(`Target Directory: ${targetDir}`); |
| 26 | + console.log(`Date: ${new Date().toISOString()}\n`); |
| 27 | + |
| 28 | + if (!fs.existsSync(targetDir)) { |
| 29 | + console.error(`❌ Error: Directory '${targetDir}' does not exist.`); |
| 30 | + console.log(`\nUsage: npx ts-node scripts/analysis/scanning_benchmark.ts [directory_path]`); |
| 31 | + console.log(`Hint: Provide a folder containing .gridset, .sps (Snap), or .zip (TouchChat) files.\n`); |
| 32 | + process.exit(1); |
| 33 | + } |
| 34 | + |
| 35 | + const files = fs.readdirSync(targetDir).filter(file => { |
| 36 | + const ext = path.extname(file).toLowerCase(); |
| 37 | + // Special case for TouchChat which can be .zip sometimes, or .ce |
| 38 | + return isExtensionSupported(ext) || ext === '.zip'; |
| 39 | + }); |
| 40 | + |
| 41 | + if (files.length === 0) { |
| 42 | + console.warn(`⚠️ No supported AAC files found in ${targetDir}.`); |
| 43 | + console.log(`Supported extensions: .gridset, .sps, .spb, .ce, .obfset, etc.`); |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + console.log(`Found ${files.length} pageset(s) to analyze.\n`); |
| 48 | + |
| 49 | + const calculator = new Analytics.MetricsCalculator(); |
| 50 | + const vocabAnalyzer = new Analytics.VocabularyAnalyzer(); |
| 51 | + |
| 52 | + for (const file of files) { |
| 53 | + const filePath = path.join(targetDir, file); |
| 54 | + const ext = path.extname(file).toLowerCase(); |
| 55 | + |
| 56 | + console.log(`Processing: ${file}...`); |
| 57 | + |
| 58 | + try { |
| 59 | + // Use standard processor factory |
| 60 | + // TouchChat specifically often comes in .zip, so we map it if needed |
| 61 | + const processorExt = ext === '.zip' ? '.ce' : ext; |
| 62 | + const processor = getProcessor(processorExt); |
| 63 | + |
| 64 | + const tree = processor.loadIntoTree(filePath); |
| 65 | + |
| 66 | + // Analyze with default settings (auto-detects scanning if configured in properties) |
| 67 | + // or we can force scanning for the benchmark |
| 68 | + const metrics = calculator.analyze(tree); |
| 69 | + |
| 70 | + // Vocabulary analysis |
| 71 | + const vocabAnalysis = vocabAnalyzer.analyze(metrics); |
| 72 | + |
| 73 | + printSummary(file, metrics, vocabAnalysis); |
| 74 | + } catch (err) { |
| 75 | + console.error(` ❌ Failed to process ${file}: ${(err as Error).message}`); |
| 76 | + } |
| 77 | + console.log(`--------------------------------------------------`); |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +function printSummary(filename: string, metrics: any, vocab: any) { |
| 82 | + console.log(` ✅ Analysis Complete`); |
| 83 | + console.log(` Format-Specific Metric: ${metrics.grid.columns}x${metrics.grid.rows} Average Grid`); |
| 84 | + console.log(` Total Unique Words: ${vocab.total_unique_words}`); |
| 85 | + console.log(` Total Buttons Analyzed: ${metrics.total_buttons}`); |
| 86 | + |
| 87 | + console.log(`\n 🌟 Effort Scores (Scanning Context):`); |
| 88 | + const avgEffort = metrics.buttons.reduce((sum: number, b: any) => sum + b.effort, 0) / metrics.buttons.length; |
| 89 | + console.log(` Average Effort: ${avgEffort.toFixed(3)}`); |
| 90 | + |
| 91 | + // Highlighting Core List Coverage |
| 92 | + console.log(`\n 📊 Core Vocabulary Coverage:`); |
| 93 | + Object.entries(vocab.core_coverage).forEach(([listId, data]: [string, any]) => { |
| 94 | + console.log(` - ${data.name}: ${data.coverage_percent.toFixed(1)}% (${data.covered}/${data.total_words})`); |
| 95 | + console.log(` Avg Effort to core: ${data.average_effort.toFixed(3)}`); |
| 96 | + }); |
| 97 | + |
| 98 | + // Highlight specific low/high effort items |
| 99 | + if (vocab.low_effort_words.length > 0) { |
| 100 | + const top3 = vocab.low_effort_words.slice(0, 3).map((w: any) => `${w.word} (${w.effort.toFixed(2)})`).join(', '); |
| 101 | + console.log(`\n ✨ Most Accessible Words: ${top3}`); |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +runBenchmark().catch(err => { |
| 106 | + console.error(`FATAL ERROR: ${err.message}`); |
| 107 | + process.exit(1); |
| 108 | +}); |
0 commit comments