MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / main

Function main

scripts/rubi/translate.ts:52–172  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50}
51
52function main(): void {
53 const argv = process.argv;
54 let rubi =
55 process.env.RUBI_HOME ??
56 path.join(os.homedir(), `dev/rubi/Rubi-${RUBI_VERSION}`);
57 // `--section` may be repeated to translate several chapters into one corpus
58 // (e.g. ch1 + ch4); the combined file list keeps each chapter's rules in
59 // their own files, so per-file rule order — Rubi's match priority — is
60 // preserved. No `--section` means the whole corpus.
61 const sections: string[] = [];
62 let out = 'data/rubi';
63 for (let i = 2; i < argv.length; i++) {
64 switch (argv[i]) {
65 case '--rubi':
66 rubi = argv[++i];
67 break;
68 case '--section':
69 sections.push(argv[++i]);
70 break;
71 case '--out':
72 out = argv[++i];
73 break;
74 default:
75 console.error(`unknown option ${argv[i]}`);
76 process.exit(2);
77 }
78 }
79
80 const rulesRoot = path.join(rubi, 'Rubi/IntegrationRules');
81 const files = (sections.length ? sections : [''])
82 .flatMap((s) => listRuleFiles(rulesRoot, s))
83 .sort();
84 console.log(`translating ${files.length} rule files from ${rulesRoot}`);
85
86 let totalRules = 0;
87 let totalErrors = 0;
88 const skipped: {
89 file: string;
90 index: number;
91 error: string;
92 source: string;
93 }[] = [];
94 const perFile: { file: string; rules: number; errors: number }[] = [];
95
96 for (const file of files) {
97 const { rules, errors } = extractRules(path.join(rulesRoot, file));
98 totalRules += rules.length;
99 totalErrors += errors.length;
100 for (const e of errors) skipped.push({ file, ...e });
101 perFile.push({ file, rules: rules.length, errors: errors.length });
102
103 const target = path.join(out, 'corpus', file.replace(/\.m$/, '.json'));
104 fs.mkdirSync(path.dirname(target), { recursive: true });
105 // Compact, one rule per line: diffable per-rule, small on disk.
106 fs.writeFileSync(
107 target,
108 `{"schemaVersion":1,"file":${JSON.stringify(file)},"rules":[\n` +
109 rules.map((r) => JSON.stringify(r)).join(',\n') +

Callers 1

translate.tsFile · 0.70

Calls 12

extractRulesFunction · 0.90
listRuleFilesFunction · 0.85
sha256DirFunction · 0.85
toFixedMethod · 0.80
errorMethod · 0.65
logMethod · 0.65
replaceMethod · 0.65
mapMethod · 0.65
sliceMethod · 0.65
setMethod · 0.65
getMethod · 0.65
entriesMethod · 0.65

Tested by

no test coverage detected