aisp-validator 0.2.0 → 0.2.2
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/README.md +153 -43
- package/bin/cli.js +20 -10
- package/package.json +1 -1
- package/src/index.js +70 -4
package/README.md
CHANGED
|
@@ -1,20 +1,49 @@
|
|
|
1
1
|
# AISP Validator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/aisp-validator)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
**Validate AI Symbolic Protocol (AISP) 5.1 documents** with <2% ambiguity using a lightweight <10KB WASM kernel.
|
|
7
|
+
|
|
8
|
+
AISP is a formal specification language designed for AI-to-AI communication, providing precise, unambiguous specifications that eliminate interpretation errors.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install aisp-validator
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or run directly with npx:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npx aisp-validator validate your-spec.aisp
|
|
20
|
+
```
|
|
4
21
|
|
|
5
22
|
## Quick Start
|
|
6
23
|
|
|
7
|
-
### CLI
|
|
24
|
+
### CLI Usage
|
|
8
25
|
|
|
9
26
|
```bash
|
|
10
|
-
# Validate a
|
|
27
|
+
# Validate a document
|
|
11
28
|
npx aisp-validator validate spec.aisp
|
|
12
29
|
|
|
13
|
-
# Get quality tier
|
|
30
|
+
# Get quality tier (◊⁺⁺, ◊⁺, ◊, ◊⁻, ⊘)
|
|
14
31
|
npx aisp-validator tier spec.aisp
|
|
15
32
|
|
|
16
33
|
# Get density score
|
|
17
34
|
npx aisp-validator density spec.aisp
|
|
35
|
+
|
|
36
|
+
# Debug - detailed density breakdown
|
|
37
|
+
npx aisp-validator debug spec.aisp
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Example output:**
|
|
41
|
+
```
|
|
42
|
+
✓ VALID
|
|
43
|
+
Tier: ◊⁺⁺ Platinum
|
|
44
|
+
Semantic (δ): 1.000
|
|
45
|
+
Pure (ρ): 1.857
|
|
46
|
+
Ambiguity: 0.010
|
|
18
47
|
```
|
|
19
48
|
|
|
20
49
|
### Node.js
|
|
@@ -25,7 +54,7 @@ import AISP from 'aisp-validator';
|
|
|
25
54
|
await AISP.init();
|
|
26
55
|
|
|
27
56
|
const result = AISP.validate(`
|
|
28
|
-
𝔸1.0.example@2026-01-
|
|
57
|
+
𝔸1.0.example@2026-01-15
|
|
29
58
|
γ≔test
|
|
30
59
|
|
|
31
60
|
⟦Ω:Meta⟧{ ∀D:Ambig(D)<0.02 }
|
|
@@ -36,40 +65,52 @@ const result = AISP.validate(`
|
|
|
36
65
|
`);
|
|
37
66
|
|
|
38
67
|
console.log(result);
|
|
39
|
-
// {
|
|
68
|
+
// {
|
|
69
|
+
// valid: true,
|
|
70
|
+
// tier: '◊⁺⁺',
|
|
71
|
+
// tierName: 'Platinum',
|
|
72
|
+
// delta: 0.82,
|
|
73
|
+
// pureDensity: 1.85,
|
|
74
|
+
// ambiguity: 0.01
|
|
75
|
+
// }
|
|
40
76
|
```
|
|
41
77
|
|
|
42
78
|
### Browser
|
|
43
79
|
|
|
44
80
|
```html
|
|
45
81
|
<script type="module">
|
|
46
|
-
import AISP from '
|
|
82
|
+
import AISP from 'aisp-validator/browser';
|
|
47
83
|
|
|
48
|
-
await AISP.init('/
|
|
84
|
+
await AISP.init('/path/to/aisp.wasm');
|
|
49
85
|
|
|
50
|
-
const result = AISP.validate(
|
|
86
|
+
const result = AISP.validate(documentSource);
|
|
51
87
|
console.log(result.tier); // '◊⁺⁺'
|
|
52
88
|
</script>
|
|
53
89
|
```
|
|
54
90
|
|
|
55
|
-
## API
|
|
91
|
+
## API Reference
|
|
56
92
|
|
|
57
93
|
### `AISP.init(wasmPath?)`
|
|
58
|
-
Initialize the WASM kernel.
|
|
94
|
+
Initialize the WASM kernel. Must be called once before validation.
|
|
59
95
|
|
|
60
96
|
### `AISP.validate(source)`
|
|
61
97
|
Validate an AISP document. Returns:
|
|
62
98
|
```javascript
|
|
63
99
|
{
|
|
64
|
-
valid: boolean,
|
|
65
|
-
tier: string,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
100
|
+
valid: boolean, // true if document passes validation
|
|
101
|
+
tier: string, // '⊘' | '◊⁻' | '◊' | '◊⁺' | '◊⁺⁺'
|
|
102
|
+
tierName: string, // 'Reject' | 'Bronze' | 'Silver' | 'Gold' | 'Platinum'
|
|
103
|
+
tierValue: number, // 0-4 (numeric tier)
|
|
104
|
+
delta: number, // Semantic density δ [0, 1]
|
|
105
|
+
pureDensity: number, // Pure density ρ (symbols/tokens)
|
|
106
|
+
ambiguity: number, // [0, 1], must be <0.02
|
|
107
|
+
errorCode: number // 0 = success
|
|
70
108
|
}
|
|
71
109
|
```
|
|
72
110
|
|
|
111
|
+
### `AISP.debug(source)`
|
|
112
|
+
Get detailed density breakdown for debugging.
|
|
113
|
+
|
|
73
114
|
### `AISP.isValid(source)`
|
|
74
115
|
Quick check: returns `true` if valid.
|
|
75
116
|
|
|
@@ -77,39 +118,92 @@ Quick check: returns `true` if valid.
|
|
|
77
118
|
Returns tier symbol: `'◊⁺⁺'`, `'◊⁺'`, `'◊'`, `'◊⁻'`, or `'⊘'`
|
|
78
119
|
|
|
79
120
|
### `AISP.getDensity(source)`
|
|
80
|
-
Returns density score (δ) between 0 and 1.
|
|
121
|
+
Returns semantic density score (δ) between 0 and 1.
|
|
81
122
|
|
|
82
123
|
### `AISP.validateFile(path)` (Node.js only)
|
|
83
124
|
Validate a file by path.
|
|
84
125
|
|
|
126
|
+
### `AISP.debugFile(path)` (Node.js only)
|
|
127
|
+
Debug a file by path.
|
|
128
|
+
|
|
85
129
|
## Quality Tiers
|
|
86
130
|
|
|
87
|
-
| Tier | Symbol | Threshold |
|
|
88
|
-
|
|
89
|
-
| Platinum | ◊⁺⁺ | δ ≥ 0.75 | Production
|
|
90
|
-
| Gold | ◊⁺ | δ ≥ 0.60 |
|
|
91
|
-
| Silver | ◊ | δ ≥ 0.40 |
|
|
92
|
-
| Bronze | ◊⁻ | δ ≥ 0.20 |
|
|
93
|
-
| Reject | ⊘ | δ < 0.20 | Insufficient
|
|
131
|
+
| Tier | Symbol | Threshold | Use Case |
|
|
132
|
+
|------|--------|-----------|----------|
|
|
133
|
+
| **Platinum** | ◊⁺⁺ | δ ≥ 0.75 | Production deployment |
|
|
134
|
+
| **Gold** | ◊⁺ | δ ≥ 0.60 | Staging/pre-production |
|
|
135
|
+
| **Silver** | ◊ | δ ≥ 0.40 | Development/testing |
|
|
136
|
+
| **Bronze** | ◊⁻ | δ ≥ 0.20 | Draft/review |
|
|
137
|
+
| **Reject** | ⊘ | δ < 0.20 | Insufficient quality |
|
|
138
|
+
|
|
139
|
+
## Density Metrics
|
|
140
|
+
|
|
141
|
+
### Semantic Density (δ)
|
|
142
|
+
Measures specification completeness:
|
|
143
|
+
```
|
|
144
|
+
δ = (blockScore × 0.4) + (bindingScore × 0.6)
|
|
145
|
+
```
|
|
146
|
+
- **blockScore**: Required blocks present (⟦Ω⟧, ⟦Σ⟧, ⟦Γ⟧, ⟦Λ⟧, ⟦Ε⟧)
|
|
147
|
+
- **bindingScore**: Semantic operators (≜, ≔, ∀, ∃, λ, ⇒, ∈, etc.)
|
|
148
|
+
|
|
149
|
+
### Pure Density (ρ)
|
|
150
|
+
Measures symbol concentration:
|
|
151
|
+
```
|
|
152
|
+
ρ = |AISP_symbols| ÷ |non_ws_tokens|
|
|
153
|
+
```
|
|
94
154
|
|
|
95
155
|
## Required AISP Blocks
|
|
96
156
|
|
|
97
|
-
Every valid AISP document must include:
|
|
157
|
+
Every valid AISP document must include these 5 blocks:
|
|
158
|
+
|
|
159
|
+
| Block | Name | Purpose |
|
|
160
|
+
|-------|------|---------|
|
|
161
|
+
| `⟦Ω⟧` | Meta | Metadata and constraints |
|
|
162
|
+
| `⟦Σ⟧` | Types | Type definitions |
|
|
163
|
+
| `⟦Γ⟧` | Rules | Inference rules |
|
|
164
|
+
| `⟦Λ⟧` | Funcs | Function definitions |
|
|
165
|
+
| `⟦Ε⟧` | Evidence | Quality metrics |
|
|
166
|
+
|
|
167
|
+
## Example AISP Document
|
|
168
|
+
|
|
169
|
+
```aisp
|
|
170
|
+
𝔸5.1.tic-tac-toe@2026-01-15
|
|
171
|
+
γ≔game-spec
|
|
172
|
+
|
|
173
|
+
⟦Ω:Meta⟧{
|
|
174
|
+
∀D∈AISP:Ambig(D)<0.02
|
|
175
|
+
Target≜AI-Agents
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
⟦Σ:Types⟧{
|
|
179
|
+
Player≜{X,O}
|
|
180
|
+
Cell≜{Empty,X,O}
|
|
181
|
+
Board≜Cell[9]
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
⟦Γ:Rules⟧{
|
|
185
|
+
∀move:ValidMove(board,pos)⇔board[pos]=Empty
|
|
186
|
+
∀win:WinCondition⇔∃line∈Lines:∀c∈line:c=player
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
⟦Λ:Funcs⟧{
|
|
190
|
+
makeMove≜λ(board,pos,player).board[pos]←player
|
|
191
|
+
checkWin≜λboard.∃p∈Player:WinCondition(board,p)
|
|
192
|
+
}
|
|
98
193
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
- `⟦Γ⟧` - Inference rules
|
|
102
|
-
- `⟦Λ⟧` - Functions
|
|
103
|
-
- `⟦Ε⟧` - Evidence
|
|
194
|
+
⟦Ε⟧⟨δ≜0.75;φ≜100;τ≜◊⁺⁺⟩
|
|
195
|
+
```
|
|
104
196
|
|
|
105
197
|
## Building from Source
|
|
106
198
|
|
|
199
|
+
The validator includes full Rust source code:
|
|
200
|
+
|
|
107
201
|
```bash
|
|
108
202
|
# Prerequisites
|
|
109
203
|
rustup target add wasm32-unknown-unknown
|
|
110
|
-
npm install -g binaryen
|
|
204
|
+
cargo install wasm-opt # or: npm install -g binaryen
|
|
111
205
|
|
|
112
|
-
# Build
|
|
206
|
+
# Build WASM kernel
|
|
113
207
|
cd wasm
|
|
114
208
|
./build.sh
|
|
115
209
|
|
|
@@ -118,19 +212,35 @@ cd wasm
|
|
|
118
212
|
|
|
119
213
|
## Architecture
|
|
120
214
|
|
|
121
|
-
|
|
215
|
+
- **WASM Kernel**: Zero-allocation Rust core (<10KB)
|
|
216
|
+
- **Type System**: Based on dependent type theory
|
|
217
|
+
- **Symbol Table**: AISP Σ_512 glossary (50+ formal symbols)
|
|
218
|
+
- **Validation**: Structural + semantic analysis
|
|
122
219
|
|
|
123
|
-
|
|
124
|
-
- **Type checking**: Based on lean-agentic
|
|
125
|
-
- **Symbol table**: AISP Σ_512 glossary
|
|
126
|
-
- **Density computation**: AISP symbol ratio
|
|
220
|
+
## What is AISP?
|
|
127
221
|
|
|
128
|
-
|
|
222
|
+
**AI Symbolic Protocol (AISP)** is a formal specification language designed for precise AI-to-AI communication. Key benefits:
|
|
223
|
+
|
|
224
|
+
- **<2% Ambiguity**: Eliminates interpretation errors
|
|
225
|
+
- **Formal Semantics**: Based on type theory and logic
|
|
226
|
+
- **Machine-Readable**: Designed for AI agents
|
|
227
|
+
- **Human-Auditable**: Clear structure for review
|
|
129
228
|
|
|
130
|
-
|
|
229
|
+
Learn more:
|
|
230
|
+
- [AI Guide](https://github.com/bar181/aisp-open-core/blob/main/AI_GUIDE.md) - Complete AISP specification
|
|
231
|
+
- [Human Guide](https://github.com/bar181/aisp-open-core/blob/main/HUMAN_GUIDE.md) - Human-readable introduction
|
|
232
|
+
- [Reference (Rosetta Stone)](https://github.com/bar181/aisp-open-core/blob/main/reference.md) - Symbol glossary
|
|
131
233
|
|
|
132
234
|
## Links
|
|
133
235
|
|
|
134
|
-
- [
|
|
135
|
-
- [
|
|
136
|
-
- [
|
|
236
|
+
- **GitHub**: [github.com/bar181/aisp-open-core](https://github.com/bar181/aisp-open-core)
|
|
237
|
+
- **npm**: [npmjs.com/package/aisp-validator](https://www.npmjs.com/package/aisp-validator)
|
|
238
|
+
- **Issues**: [Report bugs](https://github.com/bar181/aisp-open-core/issues)
|
|
239
|
+
|
|
240
|
+
## License
|
|
241
|
+
|
|
242
|
+
MIT License - see [LICENSE](https://github.com/bar181/aisp-open-core/blob/main/validator/LICENSE)
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
**Made for AI agents, auditable by humans.**
|
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.2 - 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.2');
|
|
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 };
|