Major enhancements for type safety and developer experience: - Add BrainyTypes static API for type management and AI-powered suggestions - Implement strict type validation for all 31 NounType categories - Remove dangerous generic add() method that bypassed type safety - Add intelligent type inference with confidence scoring - Provide helpful error messages with typo suggestions using Levenshtein distance - Update all internal code, examples, and documentation to use typed methods - Enhance CLI with new type management commands (types, suggest, validate) Breaking changes: - Remove deprecated add() method - use addNoun() with explicit type parameter - All addNoun() calls now require explicit type as second parameter This release significantly improves type safety across the entire system while maintaining backward compatibility for properly typed method calls. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
77 lines
No EOL
2.2 KiB
JavaScript
77 lines
No EOL
2.2 KiB
JavaScript
// Demo: Neural Type Inference vs Basic Pattern Matching
|
|
import {
|
|
inferNounTypeFromMetadata,
|
|
inferNounTypeNeural
|
|
} from './dist/utils/typeValidation.js'
|
|
|
|
console.log('🧠 Brainy Type Inference: Pattern vs Neural\n')
|
|
console.log('=' .repeat(50) + '\n')
|
|
|
|
// Test cases showing the difference
|
|
const testCases = [
|
|
{
|
|
name: 'Simple Person (both work)',
|
|
data: {
|
|
email: 'john@example.com',
|
|
name: 'John Doe'
|
|
}
|
|
},
|
|
{
|
|
name: 'Complex Role (neural understands context)',
|
|
data: {
|
|
title: 'Engineering Manager',
|
|
responsibilities: 'Leads team, reviews code, mentors developers',
|
|
department: 'Technology'
|
|
}
|
|
},
|
|
{
|
|
name: 'Ambiguous Entity (neural uses semantic understanding)',
|
|
data: {
|
|
name: 'Tesla',
|
|
founded: 2003,
|
|
employees: 127855,
|
|
products: ['Model S', 'Model 3', 'Model X']
|
|
}
|
|
},
|
|
{
|
|
name: 'Scientific Content (neural recognizes research)',
|
|
data: {
|
|
title: 'Effects of quantum entanglement on superconductivity',
|
|
abstract: 'This study examines the relationship between quantum states...',
|
|
methodology: 'Double-blind controlled experiment',
|
|
results: 'Statistical significance p<0.05'
|
|
}
|
|
},
|
|
{
|
|
name: 'Legal Document (neural understands context)',
|
|
data: {
|
|
parties: ['Company A', 'Company B'],
|
|
effectiveDate: '2024-01-01',
|
|
terms: 'Non-disclosure agreement',
|
|
jurisdiction: 'California'
|
|
}
|
|
}
|
|
]
|
|
|
|
async function runComparison() {
|
|
for (const testCase of testCases) {
|
|
console.log(`📝 Test: ${testCase.name}`)
|
|
console.log(` Data: ${JSON.stringify(testCase.data, null, 2).split('\n').join('\n ')}`)
|
|
|
|
// Basic pattern matching (synchronous)
|
|
const basicType = inferNounTypeFromMetadata(testCase.data)
|
|
console.log(` 🔍 Basic Pattern Match: ${basicType || 'content (default)'}`)
|
|
|
|
// Neural inference (async, uses embeddings)
|
|
const neuralType = await inferNounTypeNeural(testCase.data)
|
|
console.log(` 🧠 Neural Inference: ${neuralType}`)
|
|
|
|
if (basicType !== neuralType) {
|
|
console.log(` ✨ Neural found better match!`)
|
|
}
|
|
|
|
console.log()
|
|
}
|
|
}
|
|
|
|
runComparison().catch(console.error) |