079project 6.0.0 → 8.0.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.
@@ -0,0 +1,256 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const workerpool = require('workerpool');
6
+ const csvParse = require('csv-parse/sync');
7
+ const crypto = require('crypto');
8
+
9
+ const safeRequire = (name) => {
10
+ try {
11
+ return require(name);
12
+ } catch (_err) {
13
+ return null;
14
+ }
15
+ };
16
+
17
+ const natural = safeRequire('natural');
18
+ const porterStemmer = natural?.PorterStemmer ?? null;
19
+
20
+ const lemmaCache = new Map();
21
+ const lemmaMTime = new Map();
22
+
23
+ const resolveLemmaPath = (lemmaCsvPath) => {
24
+ if (!lemmaCsvPath) {
25
+ return null;
26
+ }
27
+ if (path.isAbsolute(lemmaCsvPath)) {
28
+ return lemmaCsvPath;
29
+ }
30
+ return path.resolve(process.cwd(), lemmaCsvPath);
31
+ };
32
+
33
+ const loadLemmaMap = (lemmaCsvPath) => {
34
+ const resolvedPath = resolveLemmaPath(lemmaCsvPath);
35
+ if (!resolvedPath) {
36
+ return new Map();
37
+ }
38
+ try {
39
+ const stat = fs.statSync(resolvedPath);
40
+ const cached = lemmaCache.get(resolvedPath);
41
+ const cachedMTime = lemmaMTime.get(resolvedPath);
42
+ if (cached && cachedMTime && cachedMTime >= stat.mtimeMs) {
43
+ return cached;
44
+ }
45
+ const csvContent = fs.readFileSync(resolvedPath, 'utf8');
46
+ const records = csvParse.parse(csvContent, {
47
+ skip_empty_lines: true,
48
+ relax_column_count: true
49
+ });
50
+ const map = new Map();
51
+ for (const row of records) {
52
+ if (!Array.isArray(row)) {
53
+ continue;
54
+ }
55
+ const tokens = row
56
+ .map((item) => String(item || '').trim().toLowerCase())
57
+ .filter(Boolean);
58
+ if (!tokens.length) {
59
+ continue;
60
+ }
61
+ const base = tokens[0];
62
+ for (const token of tokens) {
63
+ map.set(token, base);
64
+ }
65
+ }
66
+ lemmaCache.set(resolvedPath, map);
67
+ lemmaMTime.set(resolvedPath, stat.mtimeMs);
68
+ return map;
69
+ } catch (_err) {
70
+ return new Map();
71
+ }
72
+ };
73
+
74
+ const normalizeWord = (word) => {
75
+ if (word == null) {
76
+ return '';
77
+ }
78
+ return String(word).trim().toLowerCase();
79
+ };
80
+
81
+ const lemmatizeToken = (word, lemmaMap) => {
82
+ const normalized = normalizeWord(word);
83
+ if (!normalized) {
84
+ return normalized;
85
+ }
86
+ const lemma = lemmaMap.get(normalized);
87
+ if (lemma) {
88
+ return lemma;
89
+ }
90
+ if (porterStemmer && porterStemmer.stem) {
91
+ return porterStemmer.stem(normalized);
92
+ }
93
+ return normalized;
94
+ };
95
+
96
+ const batchLemmatize = (sentences, lemmaCsvPath) => {
97
+ if (!Array.isArray(sentences)) {
98
+ return [];
99
+ }
100
+ const lemmaMap = loadLemmaMap(lemmaCsvPath);
101
+ return sentences.map((sentence) => {
102
+ if (!Array.isArray(sentence)) {
103
+ return [];
104
+ }
105
+ return sentence.map((word) => lemmatizeToken(word, lemmaMap));
106
+ });
107
+ };
108
+
109
+ const levenshtein = (a, b) => {
110
+ if (a === b) {
111
+ return 0;
112
+ }
113
+ const lenA = a.length;
114
+ const lenB = b.length;
115
+ if (lenA === 0) {
116
+ return lenB;
117
+ }
118
+ if (lenB === 0) {
119
+ return lenA;
120
+ }
121
+ const prev = new Array(lenB + 1);
122
+ const curr = new Array(lenB + 1);
123
+ for (let j = 0; j <= lenB; j++) {
124
+ prev[j] = j;
125
+ }
126
+ for (let i = 1; i <= lenA; i++) {
127
+ curr[0] = i;
128
+ const charA = a.charCodeAt(i - 1);
129
+ for (let j = 1; j <= lenB; j++) {
130
+ const charB = b.charCodeAt(j - 1);
131
+ const cost = charA === charB ? 0 : 1;
132
+ curr[j] = Math.min(
133
+ prev[j] + 1,
134
+ curr[j - 1] + 1,
135
+ prev[j - 1] + cost
136
+ );
137
+ }
138
+ for (let j = 0; j <= lenB; j++) {
139
+ prev[j] = curr[j];
140
+ }
141
+ }
142
+ return prev[lenB];
143
+ };
144
+
145
+ const uniqueWords = (words) => {
146
+ const seen = new Set();
147
+ const out = [];
148
+ for (const word of words) {
149
+ const normalized = normalizeWord(word);
150
+ if (!normalized || seen.has(normalized)) {
151
+ continue;
152
+ }
153
+ seen.add(normalized);
154
+ out.push(normalized);
155
+ }
156
+ return out;
157
+ };
158
+
159
+ const hashWord = (word) => {
160
+ return crypto.createHash('sha1').update(word).digest('hex');
161
+ };
162
+
163
+ const calcMemeDistance = ({ wordsA = [], wordsB = [] } = {}) => {
164
+ const normA = uniqueWords(wordsA);
165
+ const normB = uniqueWords(wordsB);
166
+ if (!normA.length && !normB.length) {
167
+ return { avgDist: 0, overlap: 0, jaccard: 0, memeHashes: [] };
168
+ }
169
+ const setA = new Set(normA);
170
+ const setB = new Set(normB);
171
+ let overlap = 0;
172
+ for (const word of setA) {
173
+ if (setB.has(word)) {
174
+ overlap += 1;
175
+ }
176
+ }
177
+ let totalDistance = 0;
178
+ if (!normA.length || !normB.length) {
179
+ totalDistance = normA.length + normB.length;
180
+ } else {
181
+ const accumulate = (source, target) => {
182
+ for (const word of source) {
183
+ let best = Infinity;
184
+ for (const candidate of target) {
185
+ if (word === candidate) {
186
+ best = 0;
187
+ break;
188
+ }
189
+ const dist = levenshtein(word, candidate);
190
+ const normalized = dist / Math.max(word.length, candidate.length, 1);
191
+ if (normalized < best) {
192
+ best = normalized;
193
+ }
194
+ }
195
+ totalDistance += Number.isFinite(best) ? best : 1;
196
+ }
197
+ };
198
+ accumulate(normA, normB);
199
+ accumulate(normB, normA);
200
+ }
201
+ const avgDist = (normA.length + normB.length) > 0
202
+ ? totalDistance / (normA.length + normB.length)
203
+ : 0;
204
+ const unionSize = new Set([...setA, ...setB]).size;
205
+ const jaccard = unionSize > 0 ? overlap / unionSize : 0;
206
+ const memeHashes = [
207
+ normA.map((word) => hashWord(word)),
208
+ normB.map((word) => hashWord(word))
209
+ ];
210
+ return { avgDist, overlap, jaccard, memeHashes };
211
+ };
212
+
213
+ const clonePoints = (pointsArr) => {
214
+ if (pointsArr instanceof Map) {
215
+ return clonePoints(Array.from(pointsArr.entries()));
216
+ }
217
+ if (!Array.isArray(pointsArr)) {
218
+ return [];
219
+ }
220
+ return pointsArr.map((entry) => {
221
+ const [key, value] = Array.isArray(entry)
222
+ ? entry
223
+ : [entry?.key, entry?.value];
224
+ if (key === undefined) {
225
+ return [undefined, undefined];
226
+ }
227
+ const connect = Array.isArray(value?.connect)
228
+ ? value.connect.map((item) => {
229
+ if (Array.isArray(item)) {
230
+ return [...item];
231
+ }
232
+ if (item && typeof item === 'object') {
233
+ return { ...item };
234
+ }
235
+ return item;
236
+ })
237
+ : [];
238
+ const cloned = {
239
+ pointID: value?.pointID ?? null,
240
+ connect
241
+ };
242
+ if (value?.meta && typeof value.meta === 'object') {
243
+ cloned.meta = { ...value.meta };
244
+ }
245
+ if (value?.vector && Array.isArray(value.vector)) {
246
+ cloned.vector = value.vector.slice();
247
+ }
248
+ return [key, cloned];
249
+ });
250
+ };
251
+
252
+ workerpool.worker({
253
+ calcMemeDistance,
254
+ clonePoints,
255
+ batchLemmatize
256
+ });
package/package.json CHANGED
@@ -1,16 +1,14 @@
1
1
  {
2
2
  "name": "079project",
3
- "version": "6.0.0",
4
- "description": "a GNN-GA BASED ai that might pass the turing test,which use little resources.its startpoint initialize it and you can start it as ```node mainStarter.cjs```",
3
+ "version": "8.0.0",
4
+ "description": "a matrix based ai that can performance well in little source of words,which use little resources.its startpoint initialize it and you can start it as the description in readme.md",
5
5
  "keywords": [
6
6
  "ai",
7
- "gat",
7
+ "matrix",
8
8
  "backend",
9
- "gnn",
9
+ "transformer",
10
10
  "artificial",
11
- "intelligence",
12
- "turing",
13
- "test"
11
+ "intelligence"
14
12
  ],
15
13
  "repository": {
16
14
  "type": "git",
@@ -19,12 +17,14 @@
19
17
  "license": "LGPL-3.0",
20
18
  "author": "mumu2009",
21
19
  "type": "commonjs",
22
- "main": "mainManager.cjs",
20
+ "main": "main.cjs",
23
21
  "directories": {
24
22
  "test": "tests"
25
23
  },
26
24
  "scripts": {
27
- "test": "echo \"Error: no test specified\" && exit 1"
25
+ "test": "echo \"Error: no test specified\" && exit 1",
26
+ "start:ai": "node .\\main.cjs",
27
+ "start:auth": "node .\\auth_frontend_server.cjs"
28
28
  },
29
29
  "dependencies": {
30
30
  "@redis/bloom": "^5.8.3",
@@ -33,35 +33,48 @@
33
33
  "@redis/search": "^5.8.3",
34
34
  "@tensorflow/tfjs": "^4.22.0",
35
35
  "@tensorflow/tfjs-layers": "^4.22.0",
36
- "axios": "^1.11.0",
37
- "body-parser": "^2.2.0",
36
+ "axios": "^1.13.2",
37
+ "bcryptjs": "^3.0.3",
38
+ "better-sqlite3": "^12.5.0",
39
+ "body-parser": "^2.2.1",
38
40
  "brainjs": "^0.7.4",
39
41
  "chalk": "^4.1.2",
42
+ "cheerio": "^1.1.2",
40
43
  "child_process": "^1.0.2",
44
+ "csv-parse": "^6.1.0",
41
45
  "debug": "^4.4.3",
42
46
  "ee-first": "^1.1.1",
43
47
  "electron": "^37.2.4",
44
48
  "encodeurl": "^2.0.0",
45
49
  "escape-html": "^1.0.3",
46
- "express": "^4.0.0",
50
+ "express": "^5.2.1",
47
51
  "follow-redirects": "^1.15.11",
48
52
  "forwarded": "^0.2.0",
49
53
  "ipaddr.js": "^2.3.0",
54
+ "jsonwebtoken": "^9.0.3",
50
55
  "lmdb": "^3.4.3",
56
+ "ml-kmeans": "^7.0.0",
57
+ "ml-matrix": "^6.12.1",
51
58
  "ms": "^2.1.3",
52
59
  "natural": "^8.1.0",
60
+ "numeric": "^1.2.6",
53
61
  "object-inspect": "^1.13.4",
54
62
  "on-finished": "^2.4.1",
55
63
  "parseurl": "^1.3.3",
64
+ "path-to-regexp": "^8.3.0",
65
+ "pdf-parse": "^2.4.5",
56
66
  "protobufjs": "^7.5.4",
57
67
  "puppeteer": "^24.26.1",
58
- "redis": "^5.8.3",
68
+ "redis": "^5.10.0",
69
+ "seedrandom": "^3.0.5",
59
70
  "side-channel": "^1.1.0",
60
71
  "statuses": "^2.0.2",
61
72
  "synaptic": "^1.1.4",
62
73
  "tensorflowjs": "^0.6.8",
63
74
  "umap-js": "^1.4.0",
64
- "workerpool": "^9.3.3"
75
+ "workerpool": "^10.0.1"
65
76
  },
66
- "devDependencies": {}
77
+ "devDependencies": {
78
+ "parcel-bundler": "^1.12.5"
79
+ }
67
80
  }