-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
68 lines (64 loc) · 1.98 KB
/
build.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
'use strict'
const fs=require("fs");
const {pack_delta,pack,unpack_delta2d,unpack_delta, pack_delta2d}=require('pengine/packintarr');
const {createBuilder}=require("pengine/builder");
const {getSentenceBreak}=require('../cs0/sentencebreak');
const {NOTESEP,HEADSEP}=require('pengine/textutil')
const lang=process.argv[2]||'en';
const folder="./"+lang+"-books/";
const paranames_folder=lang+'-paranames/';
const booknames=['dn1','dn2','dn3',
'mn1','mn2','mn3','sn1','sn2','sn3','sn4','sn5',
'an1','an2','an3','an4','an5','an6','an7','an8','an9','an10','an11'
]
const getParaname=bk=>{
const out=[];
let ppn=-1.;
const fn=paranames_folder+bk+'.txt';
if (fs.existsSync(fn)) {
const lines=fs.readFileSync(fn,'utf8').split(/\r?\n/);
lines.forEach(line=>{
let [pn,text]=line.split('\t');
pn=parseInt(pn);
if (out[pn]) console.log('warning repeated pn',pn,bk,line);
out[pn]=text;
if (ppn>=pn) console.log('error pn',bk,line,ppn,pn)
})
}
for (let i=0;i<out.length;i++) {
if (typeof out[i]=='undefined') out[i]='';
}
return out.join('|');
}
const build=()=>{
let prevbk='';
const paranames=[];
const builder=createBuilder({name:"sc0"+lang});
booknames.forEach(bk=>{
const fn=folder+bk+".txt";
if (!fs.existsSync(fn))return;
const rawlines=fs.readFileSync(fn,'utf8').split(/\r?\n/);
for (var i=0;i<rawlines.length;i++) {
const content=rawlines[i];
if (prevbk&&bk!==prevbk){
builder.newpage(-1,0);
paranames.push( getParaname(prevbk) );
builder.addbook(prevbk);
}
prevbk=bk;
const at2=content.indexOf(HEADSEP);
const at4=content.indexOf(NOTESEP);
if (at2>-1 && parseInt(content) && at2!==at4) {
const paranum=parseInt(content.substr(0,at2));
builder.newpage(paranum,0,bk);
}
builder.addline(content);
}
})
paranames.push( getParaname(prevbk) );
builder.addbook(prevbk);
const sentencebreak=getSentenceBreak(builder,'sentencebreak.txt');
const payload=paranames;
builder.done(payload,{$sentencebreak:sentencebreak.join('\n')});
}
build();