aisp-validator 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +20 -10
- package/package.json +1 -1
- package/src/index.js +70 -4
package/bin/cli.js
CHANGED
|
@@ -9,7 +9,7 @@ import { readFile } from 'fs/promises';
|
|
|
9
9
|
import { existsSync } from 'fs';
|
|
10
10
|
|
|
11
11
|
const HELP = `
|
|
12
|
-
AISP Validator v0.2.
|
|
12
|
+
AISP Validator v0.2.1 - Validate AISP 5.1 documents
|
|
13
13
|
|
|
14
14
|
Usage:
|
|
15
15
|
aisp-validator <command> [file]
|
|
@@ -29,11 +29,13 @@ Quality Tiers:
|
|
|
29
29
|
◊⁻ Bronze δ ≥ 0.20
|
|
30
30
|
⊘ Reject δ < 0.20
|
|
31
31
|
|
|
32
|
-
Density
|
|
33
|
-
δ = (blockScore × 0.4) + (bindingScore × 0.6)
|
|
32
|
+
Density Formulas:
|
|
33
|
+
δ (semantic) = (blockScore × 0.4) + (bindingScore × 0.6)
|
|
34
|
+
ρ (pure) = |AISP_symbols| ÷ |non_ws_tokens|
|
|
34
35
|
|
|
35
36
|
blockScore: Required blocks present (⟦Ω⟧, ⟦Σ⟧, ⟦Γ⟧, ⟦Λ⟧, ⟦Ε⟧)
|
|
36
37
|
bindingScore: Semantic operators (≜, ≔, ∀, ∃, λ, ⇒, ∈, etc.)
|
|
38
|
+
pureDensity: Ratio of AISP symbols to total tokens
|
|
37
39
|
|
|
38
40
|
Examples:
|
|
39
41
|
npx aisp-validator validate spec.aisp
|
|
@@ -50,7 +52,7 @@ async function main() {
|
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
if (args[0] === '--version' || args[0] === '-v') {
|
|
53
|
-
console.log('aisp-validator v0.2.
|
|
55
|
+
console.log('aisp-validator v0.2.1');
|
|
54
56
|
process.exit(0);
|
|
55
57
|
}
|
|
56
58
|
|
|
@@ -84,15 +86,17 @@ async function main() {
|
|
|
84
86
|
if (result.valid) {
|
|
85
87
|
console.log(`✓ VALID`);
|
|
86
88
|
console.log(` Tier: ${result.tier} ${result.tierName}`);
|
|
87
|
-
console.log(`
|
|
88
|
-
console.log(`
|
|
89
|
+
console.log(` Semantic (δ): ${result.delta.toFixed(3)}`);
|
|
90
|
+
console.log(` Pure (ρ): ${result.pureDensity.toFixed(3)}`);
|
|
91
|
+
console.log(` Ambiguity: ${result.ambiguity.toFixed(3)}`);
|
|
89
92
|
process.exit(0);
|
|
90
93
|
} else {
|
|
91
94
|
console.log(`✗ INVALID`);
|
|
92
95
|
console.log(` Error: ${result.error || `Error code ${result.errorCode}`}`);
|
|
93
96
|
if (result.tier) {
|
|
94
97
|
console.log(` Tier: ${result.tier} ${result.tierName}`);
|
|
95
|
-
console.log(`
|
|
98
|
+
console.log(` Semantic (δ): ${result.delta.toFixed(3)}`);
|
|
99
|
+
console.log(` Pure (ρ): ${result.pureDensity.toFixed(3)}`);
|
|
96
100
|
}
|
|
97
101
|
process.exit(1);
|
|
98
102
|
}
|
|
@@ -116,8 +120,9 @@ async function main() {
|
|
|
116
120
|
console.log(`\nAISP Density Debug`);
|
|
117
121
|
console.log(`==================`);
|
|
118
122
|
console.log(`\nTier: ${debug.tier} ${debug.tierName}`);
|
|
119
|
-
console.log(`
|
|
120
|
-
console.log(
|
|
123
|
+
console.log(`Semantic (δ): ${debug.delta.toFixed(3)}`);
|
|
124
|
+
console.log(`Pure (ρ): ${debug.pureDensity.toFixed(3)}`);
|
|
125
|
+
console.log(`\nSemantic Score Breakdown:`);
|
|
121
126
|
console.log(` Block Score: ${(debug.blockScore * 100).toFixed(1)}% (weight: 40%)`);
|
|
122
127
|
console.log(` Binding Score: ${(debug.bindingScore * 100).toFixed(1)}% (weight: 60%)`);
|
|
123
128
|
console.log(`\nBlocks Found: ${debug.breakdown.blocksFound}/${debug.breakdown.blocksRequired}`);
|
|
@@ -129,7 +134,12 @@ async function main() {
|
|
|
129
134
|
console.log(` λ lambdas: ${debug.breakdown.lambdas}`);
|
|
130
135
|
console.log(` ⇒⇔ implications: ${debug.breakdown.implications}`);
|
|
131
136
|
console.log(` ∈⊆∩∪ set ops: ${debug.breakdown.setOps}`);
|
|
132
|
-
console.log(`\
|
|
137
|
+
console.log(`\nPure Density Breakdown:`);
|
|
138
|
+
console.log(` AISP Symbols: ${debug.breakdown.symbolCount}`);
|
|
139
|
+
console.log(` Total Tokens: ${debug.breakdown.tokenCount}`);
|
|
140
|
+
console.log(`\nFormulas:`);
|
|
141
|
+
console.log(` δ = (${debug.blockScore.toFixed(2)} × 0.4) + (${debug.bindingScore.toFixed(2)} × 0.6) = ${debug.delta.toFixed(3)}`);
|
|
142
|
+
console.log(` ρ = ${debug.breakdown.symbolCount} ÷ ${debug.breakdown.tokenCount} = ${debug.pureDensity.toFixed(3)}`);
|
|
133
143
|
break;
|
|
134
144
|
}
|
|
135
145
|
}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -10,11 +10,69 @@ import { dirname, join } from 'path';
|
|
|
10
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
11
11
|
const __dirname = dirname(__filename);
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* AISP Symbol Set (Σ_512 subset for density calculation)
|
|
15
|
+
* Formal symbols that define AISP semantic content
|
|
16
|
+
*/
|
|
17
|
+
const AISP_SYMBOLS = [
|
|
18
|
+
// Block delimiters
|
|
19
|
+
'⟦', '⟧',
|
|
20
|
+
// Operators
|
|
21
|
+
'≜', '≔', '≡', '≢',
|
|
22
|
+
// Quantifiers
|
|
23
|
+
'∀', '∃',
|
|
24
|
+
// Lambda
|
|
25
|
+
'λ',
|
|
26
|
+
// Logic
|
|
27
|
+
'⇒', '⇔', '→', '↔', '∧', '∨', '¬', '⊕',
|
|
28
|
+
// Sets
|
|
29
|
+
'∈', '∉', '⊆', '⊇', '∩', '∪', '∅', '𝒫',
|
|
30
|
+
// Relations
|
|
31
|
+
'≤', '≥', '<', '>',
|
|
32
|
+
// Types
|
|
33
|
+
'ℕ', 'ℤ', 'ℝ', '𝔹', '𝕊',
|
|
34
|
+
// Document
|
|
35
|
+
'𝔸',
|
|
36
|
+
// Tier symbols
|
|
37
|
+
'◊', '⊘',
|
|
38
|
+
// Angle brackets (tuples)
|
|
39
|
+
'⟨', '⟩',
|
|
40
|
+
// Greek letters (commonly used)
|
|
41
|
+
'α', 'β', 'γ', 'δ', 'ε', 'φ', 'τ', 'ρ', 'Ω', 'Σ', 'Γ', 'Λ', 'Ε', 'Θ', 'Χ', 'Δ', 'Π'
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Calculate pure density: |AISP_symbols| ÷ |non_ws_tokens|
|
|
46
|
+
* @param {string} text - AISP source
|
|
47
|
+
* @returns {object} { pureDensity, symbolCount, tokenCount }
|
|
48
|
+
*/
|
|
49
|
+
function calculatePureDensity(text) {
|
|
50
|
+
// Count AISP symbols
|
|
51
|
+
let symbolCount = 0;
|
|
52
|
+
for (const symbol of AISP_SYMBOLS) {
|
|
53
|
+
const matches = text.split(symbol).length - 1;
|
|
54
|
+
symbolCount += matches;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Count non-whitespace tokens (split on whitespace, filter empty)
|
|
58
|
+
const tokens = text.split(/\s+/).filter(t => t.length > 0);
|
|
59
|
+
const tokenCount = tokens.length;
|
|
60
|
+
|
|
61
|
+
// Pure density: ratio of AISP symbols to tokens
|
|
62
|
+
const pureDensity = tokenCount > 0 ? symbolCount / tokenCount : 0;
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
pureDensity,
|
|
66
|
+
symbolCount,
|
|
67
|
+
tokenCount
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
13
71
|
/**
|
|
14
72
|
* Calculate semantic density using Block Coverage + Binding Density
|
|
15
73
|
* δ = (blockScore × 0.4) + (bindingScore × 0.6)
|
|
16
74
|
* @param {string} text - AISP source
|
|
17
|
-
* @returns {object} { delta, blockScore, bindingScore, breakdown }
|
|
75
|
+
* @returns {object} { delta, blockScore, bindingScore, breakdown, pureDensity }
|
|
18
76
|
*/
|
|
19
77
|
function calculateSemanticDensity(text) {
|
|
20
78
|
// Required blocks present?
|
|
@@ -33,13 +91,17 @@ function calculateSemanticDensity(text) {
|
|
|
33
91
|
const totalBindings = definitions + assignments + quantifiers + lambdas + implications + setOps;
|
|
34
92
|
const bindingScore = Math.min(1, totalBindings / 20);
|
|
35
93
|
|
|
36
|
-
// Combined score
|
|
94
|
+
// Combined score (semantic delta)
|
|
37
95
|
const delta = (blockScore * 0.4) + (bindingScore * 0.6);
|
|
38
96
|
|
|
97
|
+
// Pure density (symbol/token ratio)
|
|
98
|
+
const pureResult = calculatePureDensity(text);
|
|
99
|
+
|
|
39
100
|
return {
|
|
40
101
|
delta,
|
|
41
102
|
blockScore,
|
|
42
103
|
bindingScore,
|
|
104
|
+
pureDensity: pureResult.pureDensity,
|
|
43
105
|
breakdown: {
|
|
44
106
|
blocksFound: blocksFound.length,
|
|
45
107
|
blocksRequired: blocks.length,
|
|
@@ -49,7 +111,9 @@ function calculateSemanticDensity(text) {
|
|
|
49
111
|
lambdas,
|
|
50
112
|
implications,
|
|
51
113
|
setOps,
|
|
52
|
-
totalBindings
|
|
114
|
+
totalBindings,
|
|
115
|
+
symbolCount: pureResult.symbolCount,
|
|
116
|
+
tokenCount: pureResult.tokenCount
|
|
53
117
|
}
|
|
54
118
|
};
|
|
55
119
|
}
|
|
@@ -143,6 +207,7 @@ const AISP = {
|
|
|
143
207
|
tierValue: tierResult.tierValue,
|
|
144
208
|
tierName: tierResult.tierName,
|
|
145
209
|
delta: densityResult.delta,
|
|
210
|
+
pureDensity: densityResult.pureDensity,
|
|
146
211
|
ambiguity: this._instance.aisp_ambig(docId),
|
|
147
212
|
errorCode: parseResult
|
|
148
213
|
};
|
|
@@ -160,6 +225,7 @@ const AISP = {
|
|
|
160
225
|
return {
|
|
161
226
|
...tierResult,
|
|
162
227
|
delta: densityResult.delta,
|
|
228
|
+
pureDensity: densityResult.pureDensity,
|
|
163
229
|
blockScore: densityResult.blockScore,
|
|
164
230
|
bindingScore: densityResult.bindingScore,
|
|
165
231
|
breakdown: densityResult.breakdown
|
|
@@ -225,4 +291,4 @@ const AISP = {
|
|
|
225
291
|
|
|
226
292
|
export default AISP;
|
|
227
293
|
export const { init, validate, isValid, getDensity, getTier, validateFile, debug, debugFile } = AISP;
|
|
228
|
-
export { calculateSemanticDensity, getTierFromDelta };
|
|
294
|
+
export { calculateSemanticDensity, calculatePureDensity, getTierFromDelta, AISP_SYMBOLS };
|