-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-comparison.ts
More file actions
75 lines (61 loc) · 2.4 KB
/
debug-comparison.ts
File metadata and controls
75 lines (61 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bun
import { EAVStore, jsonEntityFacts } from '../src/eav-engine.js';
import { EQLSProcessor } from '../src/query/eqls-parser.js';
import { DatalogEvaluator } from '../src/query/datalog-evaluator.js';
console.log('🔍 Debugging > Comparison\n');
const sampleData = [
{ id: 1, title: "Hello World", views: 1500, reactions: { likes: 100 } },
{ id: 2, title: "TypeScript Guide", views: 2000, reactions: { likes: 1200 } },
{ id: 3, title: "Graph Theory", views: 800, reactions: { likes: 50 } }
];
const store = new EAVStore();
const processor = new EQLSProcessor();
const evaluator = new DatalogEvaluator(store);
// Load data
sampleData.forEach((item, index) => {
const entityId = `post:${item.id}`;
const facts = jsonEntityFacts(entityId, item, 'post');
store.addFacts(facts);
});
const catalog = store.getCatalog();
processor.setSchema(catalog);
// Debug the specific query that's failing
const problematicQuery = 'FIND post AS ?p WHERE ?p.views > 1000 RETURN ?p, ?p.title';
console.log(`Testing: ${problematicQuery}\n`);
// First, let's see what facts we have for views
console.log('📊 Facts for views attribute:');
const allFacts = store.getAllFacts();
const viewsFacts = allFacts.filter(f => f.a === 'views');
console.log(viewsFacts);
console.log('\n📊 Facts for type attribute:');
const typeFacts = allFacts.filter(f => f.a === 'type');
console.log(typeFacts);
console.log('\n📋 Catalog for views:');
const viewsCatalogEntry = catalog.find(c => c.attribute === 'views');
console.log(viewsCatalogEntry);
// Parse the query
console.log('\n🔍 Parsing query...');
const parseResult = processor.process(problematicQuery);
if (parseResult.errors.length > 0) {
console.log('❌ Parse errors:');
parseResult.errors.forEach(error => {
console.log(` - ${error.message}`);
});
} else {
console.log('✅ Parse successful');
console.log('Goals:');
parseResult.query!.goals.forEach((goal, i) => {
console.log(` ${i}: ${JSON.stringify(goal)}`);
});
// Try evaluating
console.log('\n🔍 Evaluating...');
try {
const result = evaluator.evaluate(parseResult.query!);
console.log(`Results: ${result.bindings.length}`);
result.bindings.forEach((binding, i) => {
console.log(` ${i}: ${JSON.stringify(binding)}`);
});
} catch (error: any) {
console.log('❌ Evaluation error:', error.message);
}
}