@polycode-projects/the-mechanical-code-talker 0.5.0 → 0.7.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.
@@ -30,8 +30,65 @@ import { createInterface } from "node:readline";
30
30
  import { SEED_TERMS, CANONICAL_RELS, FILTERED_RELS, bareEnTerm } from "./fetch-slice.mjs";
31
31
  import { loadMap } from "../../src/corpus/conceptnet.mjs";
32
32
 
33
- const MAX_BYTES = 1_400_000; // committed-slice budget (hard cap 1.5 MB)
34
- const SEEDS = new Set(SEED_TERMS);
33
+ const MAX_BYTES = 4_500_000; // committed-slice budget (hard cap 5 MB), grown for the ~40k tier-1 target
34
+
35
+ // Tier-1 growth seeds (2026-07-05): the original SEED_TERMS in fetch-slice.mjs
36
+ // stay the canonical ~90-term base; this list WIDENS the tech domain toward the
37
+ // ~40k-fact target without leaving the software/tech world — languages,
38
+ // frameworks, data structures, cloud/infra, protocols, tools, ML. Kept here (an
39
+ // owned maintainer file) rather than in fetch-slice.mjs so the API route's seed
40
+ // contract is untouched. Union with SEED_TERMS below.
41
+ const EXTRA_SEEDS = [
42
+ // programming languages & ecosystems
43
+ "python", "java", "javascript", "typescript", "ruby", "perl", "php", "golang",
44
+ "rust", "kotlin", "swift", "scala", "haskell", "lisp", "clojure", "erlang",
45
+ "fortran", "cobol", "pascal", "assembly", "sql", "html", "css", "json", "xml",
46
+ "yaml", "markdown", "bash", "powershell",
47
+ // paradigms & concepts
48
+ "programming", "coding", "recursion", "iteration", "inheritance",
49
+ "polymorphism", "abstraction", "encapsulation", "concurrency", "parallelism",
50
+ "multithreading", "asynchronous", "synchronization", "serialization",
51
+ "optimization", "refactoring", "debugging", "compilation", "runtime",
52
+ "object_oriented", "functional_programming", "computer_science",
53
+ "software_engineering", "computer_programming",
54
+ // data structures & algorithms
55
+ "hash", "hashtable", "tree", "graph", "list", "tuple", "dictionary", "heap",
56
+ "matrix", "vector", "node", "recursion", "sorting", "searching", "linked_list",
57
+ "binary_tree", "hash_table", "data_type", "datatype",
58
+ // frameworks, tools & platforms
59
+ "git", "github", "docker", "kubernetes", "jenkins", "react", "angular",
60
+ "nodejs", "django", "flask", "spring", "rails", "tensorflow", "pytorch",
61
+ "hadoop", "kafka", "redis", "mongodb", "mysql", "postgresql", "sqlite",
62
+ "elasticsearch", "apache", "nginx", "wordpress", "eclipse", "vim", "emacs",
63
+ // hardware & systems
64
+ "kernel", "driver", "register", "transistor", "semiconductor", "motherboard",
65
+ "microprocessor", "microcontroller", "gpu", "ram", "rom", "ssd", "firmware",
66
+ "bootloader", "filesystem", "partition", "peripheral", "microchip",
67
+ "circuit_board", "integrated_circuit", "hard_drive", "graphics_card",
68
+ // networking & protocols
69
+ "packet", "bandwidth", "latency", "router", "firewall", "gateway", "proxy",
70
+ "dns", "tcp", "ftp", "smtp", "ssh", "ssl", "vpn", "ethernet", "wifi",
71
+ "bluetooth", "socket", "port", "packet_switching", "ip_address",
72
+ // web & the net
73
+ "url", "cookie", "session", "webpage", "hyperlink", "frontend", "backend",
74
+ "webserver", "webservice", "hosting", "domain", "html5", "ajax",
75
+ // cloud, infra & devops
76
+ "cloud_computing", "container", "virtualization", "serverless",
77
+ "microservice", "deployment", "devops", "pipeline", "infrastructure",
78
+ "datacenter", "cluster", "scalability", "availability", "redundancy",
79
+ // security
80
+ "authentication", "authorization", "cryptography", "hashing", "firewall",
81
+ "malware", "virus", "vulnerability", "cybersecurity", "cipher",
82
+ // data & ml
83
+ "dataset", "database", "datastore", "query", "index", "schema", "transaction",
84
+ "neural_network", "deep_learning", "classification", "regression",
85
+ "clustering", "training", "inference", "algorithm", "computation",
86
+ "big_data", "data_mining", "data_science", "analytics",
87
+ // concurrency & os primitives
88
+ "semaphore", "mutex", "deadlock", "scheduler", "interrupt", "syscall",
89
+ "daemon", "multitasking", "buffer", "pipe",
90
+ ];
91
+ const SEEDS = new Set([...SEED_TERMS, ...EXTRA_SEEDS]);
35
92
  const termOf = (uri) => uri.slice("/c/en/".length);
36
93
 
37
94
  const byKey = new Map(); // "start rel end" -> row
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env node
2
+ // quality-filter.mjs — a SECOND-PASS noise filter over corpus/conceptnet/slice.jsonl.
3
+ // NOT part of the product path — a maintainer tool, run by hand, result committed.
4
+ //
5
+ // The committed slice is stream-filtered from the ConceptNet dump by
6
+ // filter-dump.mjs (tech-domain seed match + canonical relations + budget). That
7
+ // pass keeps the DATA honest but not the SEMANTICS: ConceptNet's crowd-sourced
8
+ // "Verbosity"/Open-Mind rows leave sentence-fragment "concepts" and opinion
9
+ // axioms in the slice that read as nonsense once they become memory facts —
10
+ // e.g. "a computer is a kind of dumb", "a class is a kind of elegance",
11
+ // "mouse AtLocation taloned_grip_of_owl", "2 is a kind of software".
12
+ //
13
+ // This pass removes exactly those, by term/relation shape only (never by hand
14
+ // per row), so it is reproducible:
15
+ //
16
+ // node corpus/conceptnet/quality-filter.mjs < corpus/conceptnet/slice.jsonl > slice.clean.jsonl
17
+ // # or in place (what produced the committed clean slice):
18
+ // node corpus/conceptnet/quality-filter.mjs --in-place corpus/conceptnet/slice.jsonl
19
+ //
20
+ // Cut rules (a row is DROPPED when ANY applies):
21
+ // 1. numeric endpoint — start/end bare term is all digits ("2", "1000")
22
+ // 2. single-char endpoint — bare term length <= 1 ("a", "r", "m")
23
+ // 3. sentence fragment — bare term is >= 4 underscore-words on EITHER
24
+ // endpoint ("taloned_grip_of_owl",
25
+ // "worlds_largest_interconnected_network_of_networks")
26
+ // 4. definitional phrase — /r/DefinedAs whose object is >= 3 words
27
+ // (real DefinedAs is a synonym: cpu->processor)
28
+ // 5. opinion object — /r/IsA or /r/DefinedAs whose object is one of a
29
+ // small, evidence-based OPINION set (adjectives /
30
+ // value words that never name a class)
31
+ //
32
+ // Rules 1-3 apply to every relation (they only ever remove junk); 4-5 are the
33
+ // definitional band the sims flagged. Stats land on stderr; JSONL on stdout.
34
+
35
+ import { readFile, writeFile } from "node:fs/promises";
36
+ import { createInterface } from "node:readline";
37
+
38
+ const bareTerm = (uri) => String(uri || "").replace(/^\/c\/en\//, "");
39
+ const words = (t) => t.split("_").filter(Boolean).length;
40
+
41
+ // Evidence-based: the only 1-word IsA/DefinedAs objects in the committed slice
42
+ // that are opinions/adjectives rather than classes. Kept explicit (not a POS
43
+ // heuristic) so it never cuts a legitimate abstract class like "abstraction",
44
+ // "cognition" or "relation".
45
+ export const OPINION_OBJECTS = new Set([
46
+ "elegance", "evil", "gloom", "unreality", "universalism", "dumb", "free", "junk",
47
+ ]);
48
+
49
+ /** Why this row is noise, or null to keep it. Pure function of the row shape. */
50
+ export function cutReason(row) {
51
+ const s = bareTerm(row.start);
52
+ const e = bareTerm(row.end);
53
+ for (const t of [s, e]) {
54
+ if (/^\d+$/.test(t)) return "numeric-endpoint";
55
+ if (t.length <= 1) return "single-char-endpoint";
56
+ if (words(t) >= 4) return "sentence-fragment";
57
+ }
58
+ if (row.rel === "/r/DefinedAs" && words(e) >= 3) return "definitional-phrase";
59
+ if ((row.rel === "/r/IsA" || row.rel === "/r/DefinedAs") && OPINION_OBJECTS.has(e)) return "opinion-object";
60
+ return null;
61
+ }
62
+
63
+ async function readLines(stream) {
64
+ const rl = createInterface({ input: stream, crlfDelay: Infinity });
65
+ const rows = [];
66
+ for await (const raw of rl) {
67
+ const line = raw.trim();
68
+ if (line) rows.push(JSON.parse(line));
69
+ }
70
+ return rows;
71
+ }
72
+
73
+ const isMain = process.argv[1] && import.meta.url === new URL(`file://${process.argv[1]}`).href;
74
+ if (isMain) {
75
+ const inPlace = process.argv.includes("--in-place");
76
+ const fileArg = process.argv.slice(2).find((a) => !a.startsWith("--"));
77
+ const rows = inPlace
78
+ ? (await readFile(fileArg, "utf8")).split("\n").filter((l) => l.trim()).map((l) => JSON.parse(l))
79
+ : await readLines(process.stdin);
80
+
81
+ const byReason = new Map();
82
+ const kept = [];
83
+ for (const row of rows) {
84
+ const reason = cutReason(row);
85
+ if (reason) { byReason.set(reason, (byReason.get(reason) || 0) + 1); continue; }
86
+ kept.push(row);
87
+ }
88
+ const text = kept.map((r) => JSON.stringify(r)).join("\n") + "\n";
89
+ if (inPlace) await writeFile(fileArg, text);
90
+ else process.stdout.write(text);
91
+
92
+ const cut = rows.length - kept.length;
93
+ console.error(`quality-filter: ${rows.length} rows in, ${kept.length} kept, ${cut} cut (${text.length} bytes out)`);
94
+ for (const [reason, n] of [...byReason.entries()].sort((a, b) => b[1] - a[1])) console.error(` ${reason}: ${n}`);
95
+ }