forked from yomidevs/kaikki-to-yomitan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite-tests.js
80 lines (69 loc) · 2.75 KB
/
write-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const { execSync } = require('child_process');
const { readdirSync, existsSync, readFileSync, writeFileSync, mkdirSync } = require('fs');
const languages = JSON.parse(readFileSync('languages.json', 'utf8'));
for( const dir of ["./data/test/kaikki", "./data/test/tidy", "./data/test/temp/dict", "./data/test/temp/ipa"]){
if(!existsSync(dir)){
mkdirSync(dir, {recursive: true});
}
}
for (const {iso: sourceIso} of languages){
for (const {iso: targetIso} of languages){
const kaikkiFile = `data/test/kaikki/${sourceIso}-${targetIso}.json`;
if(!existsSync(kaikkiFile)){
continue;
}
for (const dir of [`data/test/dict/${sourceIso}/${targetIso}`, `data/test/ipa/${sourceIso}/${targetIso}`]){
if(!existsSync(dir)){
mkdirSync(dir, {recursive: true});
}
}
execSync(
"node 3-tidy-up.js",
{
env:{
...process.env,
kaikki_file: kaikkiFile,
source_iso: sourceIso,
target_iso: targetIso,
tidy_folder: `./data/test/tidy`
}
}
);
console.log(`Making yomitan for ${sourceIso}-${targetIso}`);
execSync(
"node 4-make-yomitan.js",
{
env:{
...process.env,
source_iso: sourceIso,
target_iso: targetIso,
DICT_NAME: 'test',
tidy_folder: `./data/test/tidy`,
temp_folder: `./data/test/temp`
}
}
);
prettifyFile(`data/test/tidy/${sourceIso}-${targetIso}-forms-0.json`);
prettifyFile(`data/test/tidy/${sourceIso}-${targetIso}-lemmas.json`);
const dictFiles = readdirSync(`data/test/temp/dict`);
for(const file of dictFiles){
if(file === `tag_bank_1.json` || /^term_bank_\d+\.json$/.test(file)){
outputFile = `data/test/dict/${sourceIso}/${targetIso}/${file}`;
execSync(`mv data/test/temp/dict/${file} ${outputFile}`);
prettifyFile(outputFile);
}
}
const ipaFiles = readdirSync(`data/test/temp/ipa`);
for(const file of ipaFiles){
if(file === `tag_bank_1.json` || file === 'term_meta_bank_1.json'){
outputFile = `data/test/ipa/${sourceIso}/${targetIso}/${file}`;
execSync(`mv data/test/temp/ipa/${file} ${outputFile}`);
prettifyFile(outputFile);
}
}
}
}
function prettifyFile(file){
const data = JSON.parse(readFileSync(file, 'utf8'));
writeFileSync(file, JSON.stringify(data, null, 2));
}