@aleph-ai/tinyaleph 1.2.1 → 1.3.0
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 +187 -2
- package/backends/bioinformatics/binding.js +503 -0
- package/backends/bioinformatics/dna-computing.js +664 -0
- package/backends/bioinformatics/encoding.js +339 -0
- package/backends/bioinformatics/folding.js +454 -0
- package/backends/bioinformatics/genetic-code.js +269 -0
- package/backends/bioinformatics/index.js +522 -0
- package/backends/bioinformatics/transcription.js +221 -0
- package/backends/bioinformatics/translation.js +264 -0
- package/backends/index.js +25 -1
- package/core/compound.js +532 -0
- package/core/hilbert.js +454 -1
- package/core/index.js +106 -12
- package/core/inference.js +605 -0
- package/core/resonance.js +245 -616
- package/core/symbols/archetypes.js +478 -0
- package/core/symbols/base.js +302 -0
- package/core/symbols/elements.js +487 -0
- package/core/symbols/hieroglyphs.js +303 -0
- package/core/symbols/iching.js +471 -0
- package/core/symbols/index.js +77 -0
- package/core/symbols/tarot.js +211 -0
- package/core/symbols.js +22 -0
- package/docs/design/BIOINFORMATICS_BACKEND_DESIGN.md +493 -0
- package/docs/guide/06-symbolic-ai.md +370 -0
- package/docs/guide/README.md +2 -1
- package/docs/reference/05-symbolic-ai.md +570 -0
- package/docs/reference/06-bioinformatics.md +546 -0
- package/docs/reference/README.md +32 -2
- package/docs/theory/11-prgraph-memory.md +559 -0
- package/docs/theory/12-resonant-attention.md +661 -0
- package/modular.js +33 -1
- package/package.json +1 -1
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol Database Base Infrastructure
|
|
3
|
+
*
|
|
4
|
+
* Provides the core SymbolDatabase class and utilities for loading
|
|
5
|
+
* symbol definition files. Symbol definitions are stored in separate
|
|
6
|
+
* files for easy maintenance and extension.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
10
|
+
// Symbol Categories
|
|
11
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
12
|
+
|
|
13
|
+
const SymbolCategory = {
|
|
14
|
+
// Original categories
|
|
15
|
+
PEOPLE_ARCHETYPES: 'people_archetypes',
|
|
16
|
+
PLACES_LOCATIONS: 'places_locations',
|
|
17
|
+
OBJECTS_TOOLS: 'objects_tools',
|
|
18
|
+
ABSTRACT_CONCEPTS: 'abstract_concepts',
|
|
19
|
+
NATURAL_ELEMENTS: 'natural_elements',
|
|
20
|
+
|
|
21
|
+
// Divination systems
|
|
22
|
+
ICHING_HEXAGRAMS: 'iching_hexagrams',
|
|
23
|
+
TAROT_MAJOR_ARCANA: 'tarot_major_arcana',
|
|
24
|
+
TAROT_MINOR_ARCANA: 'tarot_minor_arcana',
|
|
25
|
+
|
|
26
|
+
// Ancient writing systems
|
|
27
|
+
EGYPTIAN_HIEROGLYPHS: 'egyptian_hieroglyphs',
|
|
28
|
+
|
|
29
|
+
// Alchemical
|
|
30
|
+
ALCHEMICAL_SYMBOLS: 'alchemical_symbols',
|
|
31
|
+
|
|
32
|
+
// Astrological
|
|
33
|
+
ZODIAC_SIGNS: 'zodiac_signs',
|
|
34
|
+
PLANETARY_SYMBOLS: 'planetary_symbols'
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
38
|
+
// Prime Generator (Sieve of Eratosthenes)
|
|
39
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
40
|
+
|
|
41
|
+
class PrimeGenerator {
|
|
42
|
+
constructor(limit = 20000) {
|
|
43
|
+
this.primes = [];
|
|
44
|
+
this.generatePrimes(limit);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
generatePrimes(limit) {
|
|
48
|
+
const sieve = new Array(limit + 1).fill(true);
|
|
49
|
+
sieve[0] = sieve[1] = false;
|
|
50
|
+
|
|
51
|
+
for (let i = 2; i * i <= limit; i++) {
|
|
52
|
+
if (sieve[i]) {
|
|
53
|
+
for (let j = i * i; j <= limit; j += i) {
|
|
54
|
+
sieve[j] = false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (let i = 2; i <= limit; i++) {
|
|
60
|
+
if (sieve[i]) {
|
|
61
|
+
this.primes.push(i);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getNthPrime(n) {
|
|
67
|
+
if (n < this.primes.length) {
|
|
68
|
+
return this.primes[n];
|
|
69
|
+
}
|
|
70
|
+
let candidate = this.primes[this.primes.length - 1] + 1;
|
|
71
|
+
while (this.primes.length <= n) {
|
|
72
|
+
if (this.isPrime(candidate)) {
|
|
73
|
+
this.primes.push(candidate);
|
|
74
|
+
}
|
|
75
|
+
candidate++;
|
|
76
|
+
}
|
|
77
|
+
return this.primes[n];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
isPrime(n) {
|
|
81
|
+
if (n < 2) return false;
|
|
82
|
+
if (n === 2) return true;
|
|
83
|
+
if (n % 2 === 0) return false;
|
|
84
|
+
const sqrt = Math.sqrt(n);
|
|
85
|
+
for (let i = 3; i <= sqrt; i += 2) {
|
|
86
|
+
if (n % i === 0) return false;
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
93
|
+
// Symbol Database (Singleton)
|
|
94
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
95
|
+
|
|
96
|
+
let singletonInstance = null;
|
|
97
|
+
|
|
98
|
+
class SymbolDatabase {
|
|
99
|
+
constructor() {
|
|
100
|
+
// Singleton pattern - return existing instance if already created
|
|
101
|
+
if (singletonInstance) {
|
|
102
|
+
return singletonInstance;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
this.symbols = new Map();
|
|
106
|
+
this.primeToSymbol = new Map();
|
|
107
|
+
this.unicodeToSymbol = new Map();
|
|
108
|
+
this.categoryIndex = new Map();
|
|
109
|
+
this.tagIndex = new Map();
|
|
110
|
+
this.primeGenerator = new PrimeGenerator();
|
|
111
|
+
this.nextPrimeIndex = 0;
|
|
112
|
+
|
|
113
|
+
singletonInstance = this;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ─────────────────────────────────────────────────────────────────
|
|
117
|
+
// Symbol Registration
|
|
118
|
+
// ─────────────────────────────────────────────────────────────────
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Register a batch of symbols from a definition file
|
|
122
|
+
* @param {Array} symbolDefs - Array of symbol definitions
|
|
123
|
+
*/
|
|
124
|
+
registerSymbols(symbolDefs) {
|
|
125
|
+
for (const def of symbolDefs) {
|
|
126
|
+
this.registerSymbol(def);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Register a single symbol
|
|
132
|
+
* @param {Object} symbolDef - Symbol definition
|
|
133
|
+
* @returns {Object} - Registered symbol with prime
|
|
134
|
+
*/
|
|
135
|
+
registerSymbol(symbolDef) {
|
|
136
|
+
// Check for duplicate
|
|
137
|
+
if (this.symbols.has(symbolDef.id)) {
|
|
138
|
+
return this.symbols.get(symbolDef.id);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const prime = this.primeGenerator.getNthPrime(this.nextPrimeIndex++);
|
|
142
|
+
const symbol = {
|
|
143
|
+
...symbolDef,
|
|
144
|
+
prime,
|
|
145
|
+
category: symbolDef.category || SymbolCategory.ABSTRACT_CONCEPTS,
|
|
146
|
+
culturalTags: symbolDef.culturalTags || ['custom']
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
this.symbols.set(symbol.id, symbol);
|
|
150
|
+
this.primeToSymbol.set(prime, symbol);
|
|
151
|
+
|
|
152
|
+
// Handle compound unicode (multiple emoji)
|
|
153
|
+
if (symbol.unicode) {
|
|
154
|
+
this.unicodeToSymbol.set(symbol.unicode, symbol);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Category index
|
|
158
|
+
if (!this.categoryIndex.has(symbol.category)) {
|
|
159
|
+
this.categoryIndex.set(symbol.category, []);
|
|
160
|
+
}
|
|
161
|
+
this.categoryIndex.get(symbol.category).push(symbol);
|
|
162
|
+
|
|
163
|
+
// Tag index
|
|
164
|
+
for (const tag of symbol.culturalTags) {
|
|
165
|
+
if (!this.tagIndex.has(tag)) {
|
|
166
|
+
this.tagIndex.set(tag, []);
|
|
167
|
+
}
|
|
168
|
+
this.tagIndex.get(tag).push(symbol);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return symbol;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ─────────────────────────────────────────────────────────────────
|
|
175
|
+
// Lookup Methods
|
|
176
|
+
// ─────────────────────────────────────────────────────────────────
|
|
177
|
+
|
|
178
|
+
getSymbol(id) {
|
|
179
|
+
return this.symbols.get(id);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
getSymbolByPrime(prime) {
|
|
183
|
+
return this.primeToSymbol.get(prime);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
getSymbolByUnicode(unicode) {
|
|
187
|
+
return this.unicodeToSymbol.get(unicode);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
getSymbolsByCategory(category) {
|
|
191
|
+
return this.categoryIndex.get(category) || [];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
getSymbolsByTag(tag) {
|
|
195
|
+
return this.tagIndex.get(tag) || [];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
getAllSymbols() {
|
|
199
|
+
return Array.from(this.symbols.values());
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
getSymbolCount() {
|
|
203
|
+
return this.symbols.size;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
getAllCategories() {
|
|
207
|
+
return Array.from(this.categoryIndex.keys());
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
getAllTags() {
|
|
211
|
+
return Array.from(this.tagIndex.keys());
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ─────────────────────────────────────────────────────────────────
|
|
215
|
+
// Search Methods
|
|
216
|
+
// ─────────────────────────────────────────────────────────────────
|
|
217
|
+
|
|
218
|
+
search(query) {
|
|
219
|
+
const lowerQuery = query.toLowerCase();
|
|
220
|
+
return this.getAllSymbols().filter(symbol =>
|
|
221
|
+
symbol.meaning.toLowerCase().includes(lowerQuery) ||
|
|
222
|
+
symbol.culturalTags.some(tag => tag.toLowerCase().includes(lowerQuery)) ||
|
|
223
|
+
symbol.id.toLowerCase().includes(lowerQuery)
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
findByMeaning(text) {
|
|
228
|
+
const words = text.toLowerCase().split(/\s+/);
|
|
229
|
+
const results = [];
|
|
230
|
+
|
|
231
|
+
for (const symbol of this.symbols.values()) {
|
|
232
|
+
const meaningWords = symbol.meaning.toLowerCase().split(/\s+/);
|
|
233
|
+
const matches = words.filter(w => meaningWords.some(m => m.includes(w)));
|
|
234
|
+
if (matches.length > 0) {
|
|
235
|
+
results.push({ symbol, score: matches.length / words.length });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return results.sort((a, b) => b.score - a.score);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ─────────────────────────────────────────────────────────────────
|
|
243
|
+
// Encoding/Decoding
|
|
244
|
+
// ─────────────────────────────────────────────────────────────────
|
|
245
|
+
|
|
246
|
+
encode(symbolIds) {
|
|
247
|
+
let product = 1n;
|
|
248
|
+
for (const id of symbolIds) {
|
|
249
|
+
const symbol = this.symbols.get(id);
|
|
250
|
+
if (symbol) {
|
|
251
|
+
product *= BigInt(symbol.prime);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return product;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
decode(signature) {
|
|
258
|
+
const symbols = [];
|
|
259
|
+
let remaining = typeof signature === 'bigint' ? signature : BigInt(signature);
|
|
260
|
+
|
|
261
|
+
for (const [prime, symbol] of this.primeToSymbol) {
|
|
262
|
+
const bigPrime = BigInt(prime);
|
|
263
|
+
while (remaining % bigPrime === 0n) {
|
|
264
|
+
symbols.push(symbol);
|
|
265
|
+
remaining /= bigPrime;
|
|
266
|
+
}
|
|
267
|
+
if (remaining === 1n) break;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return symbols;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// ─────────────────────────────────────────────────────────────────
|
|
274
|
+
// Statistics
|
|
275
|
+
// ─────────────────────────────────────────────────────────────────
|
|
276
|
+
|
|
277
|
+
getStats() {
|
|
278
|
+
const stats = {
|
|
279
|
+
totalSymbols: this.symbols.size,
|
|
280
|
+
byCategory: {},
|
|
281
|
+
topTags: []
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
for (const [category, symbols] of this.categoryIndex) {
|
|
285
|
+
stats.byCategory[category] = symbols.length;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const tagCounts = [];
|
|
289
|
+
for (const [tag, symbols] of this.tagIndex) {
|
|
290
|
+
tagCounts.push({ tag, count: symbols.length });
|
|
291
|
+
}
|
|
292
|
+
stats.topTags = tagCounts.sort((a, b) => b.count - a.count).slice(0, 20);
|
|
293
|
+
|
|
294
|
+
return stats;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
module.exports = {
|
|
299
|
+
SymbolDatabase,
|
|
300
|
+
SymbolCategory,
|
|
301
|
+
PrimeGenerator
|
|
302
|
+
};
|