-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-nl-query-processing.ts
More file actions
101 lines (89 loc) · 2.48 KB
/
test-nl-query-processing.ts
File metadata and controls
101 lines (89 loc) · 2.48 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bun
/**
* Test natural language query processing with common patterns
*/
import { processQuery } from '../src/ai/orchestrator.js';
// Sample catalog data for testing
const sampleCatalog = [
{
attribute: 'family',
type: 'string',
examples: ['ABeeZee', 'Roboto', 'Times New Roman']
},
{
attribute: 'category',
type: 'string',
examples: ['serif', 'sans-serif', 'display']
},
{
attribute: 'price',
type: 'number',
examples: [10.99, 25.50, 5.00]
},
{
attribute: 'tags',
type: 'string',
examples: ['popular', 'new', 'sale']
}
];
// Sample data stats
const dataStats = {
totalFacts: 5000,
uniqueEntities: 200,
uniqueAttributes: 15
};
// Test cases for different natural language patterns
const testCases = [
{
description: "Simple equality",
query: "show me serif fonts"
},
{
description: "Starts with pattern",
query: "find fonts that start with the letter A"
},
{
description: "Begins with pattern variation",
query: "list fonts beginning with R"
},
{
description: "Contains pattern",
query: "fonts with 'Sans' in the name"
},
{
description: "Numerical comparison",
query: "products over 20 dollars"
},
{
description: "Between range",
query: "items priced between 10 and 30"
},
{
description: "Combined criteria",
query: "serif fonts that start with T"
}
];
// Run the tests
async function runTests() {
console.log("🔍 Testing Natural Language Query Processing\n");
for (const testCase of testCases) {
console.log(`📝 Test: ${testCase.description}`);
console.log(`Query: "${testCase.query}"`);
try {
const result = await processQuery(testCase.query, {
catalog: sampleCatalog,
dataStats: dataStats
});
if (result.error) {
console.log(`❌ Error: ${result.error}`);
} else if (result.eqlsQuery) {
console.log(`✅ Generated EQL-S: ${result.eqlsQuery}`);
}
} catch (error) {
console.log(`❌ Exception: ${error instanceof Error ? error.message : String(error)}`);
}
console.log("----------------------------------------------");
}
console.log("\n✨ Testing complete!");
}
runTests().catch(console.error);