@sc-voice/tools 1.2.0 → 1.4.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.
- package/index.mjs +3 -0
- package/package.json +1 -1
- package/src/defines.mjs +2 -4
- package/src/math/fraction.mjs +8 -0
- package/src/text/logger.mjs +87 -0
- package/src/text/word-space.mjs +1 -1
- package/src/translate/deepl-adapter.mjs +1 -1
package/index.mjs
CHANGED
|
@@ -12,11 +12,14 @@ import { MerkleJson } from './src/text/merkle-json.mjs';
|
|
|
12
12
|
import { SuttaCentralId } from './src/text/sutta-central-id.mjs';
|
|
13
13
|
import { Unicode } from './src/text/unicode.mjs';
|
|
14
14
|
import { WordSpace } from './src/text/word-space.mjs';
|
|
15
|
+
import { LogEntry, Logger } from './src/text/logger.mjs';
|
|
15
16
|
|
|
16
17
|
export const Text = {
|
|
17
18
|
BilaraPath,
|
|
18
19
|
EbtDoc,
|
|
19
20
|
LegacyDoc,
|
|
21
|
+
LogEntry,
|
|
22
|
+
Logger,
|
|
20
23
|
MerkleJson,
|
|
21
24
|
SuttaCentralId,
|
|
22
25
|
Unicode,
|
package/package.json
CHANGED
package/src/defines.mjs
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
2
1
|
export const DBG = {
|
|
3
2
|
ALIGN_ALL: 0,
|
|
4
3
|
ALIGN_LINE: 0,
|
|
5
4
|
ML_DOC_VECTORS: 0, // 'mn8:3.4',
|
|
6
5
|
MN8_MOHAN: 0,
|
|
7
6
|
DEEPL_ADAPTER: 0,
|
|
8
|
-
DEEPL_MOCK: 0,
|
|
7
|
+
DEEPL_MOCK: 0, // use mock-deepl
|
|
9
8
|
DEEPL_MOCK_XLT: 0, // use mock translation
|
|
10
9
|
DEEPL_TEST_API: 0, // test with live DeepL API ($$$)
|
|
11
|
-
DEEPL_XLT: 0,
|
|
10
|
+
DEEPL_XLT: 0, // test live translation
|
|
12
11
|
WORD_MAP_TRANFORMER: 0,
|
|
13
12
|
};
|
|
14
|
-
|
package/src/math/fraction.mjs
CHANGED
|
@@ -41,10 +41,18 @@ export class Fraction {
|
|
|
41
41
|
return this.numerator;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
set n(value) {
|
|
45
|
+
this.numerator = Number(value);
|
|
46
|
+
}
|
|
47
|
+
|
|
44
48
|
get d() {
|
|
45
49
|
return this.denominator;
|
|
46
50
|
}
|
|
47
51
|
|
|
52
|
+
set d(value) {
|
|
53
|
+
this.denominator = Number(value);
|
|
54
|
+
}
|
|
55
|
+
|
|
48
56
|
get value() {
|
|
49
57
|
let { numerator, denominator } = this;
|
|
50
58
|
return numerator / denominator;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { DBG } from '../defines.mjs';
|
|
2
|
+
|
|
3
|
+
export class LogEntry {
|
|
4
|
+
constructor(opts = {}) {
|
|
5
|
+
let { level = 'info', text = '', ms } = opts;
|
|
6
|
+
Object.assign(this, { level, text, ms });
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static args2String(args) {
|
|
10
|
+
return args.reduce((a, arg) => {
|
|
11
|
+
if (a) {
|
|
12
|
+
a += ' ';
|
|
13
|
+
}
|
|
14
|
+
if (arg instanceof Array) {
|
|
15
|
+
a += JSON.stringify(arg);
|
|
16
|
+
} else if (typeof arg === 'object') {
|
|
17
|
+
a += '{';
|
|
18
|
+
Object.keys(arg).forEach((k, i) => {
|
|
19
|
+
if (i) {
|
|
20
|
+
a += ', ';
|
|
21
|
+
}
|
|
22
|
+
let ks = /[a-z0-9_$]+/i.test(k) ? k : `"${k}"`;
|
|
23
|
+
let v = arg[k];
|
|
24
|
+
a += ks + ':' + JSON.stringify(arg[k]);
|
|
25
|
+
});
|
|
26
|
+
a += '}';
|
|
27
|
+
} else {
|
|
28
|
+
a += arg;
|
|
29
|
+
}
|
|
30
|
+
return a;
|
|
31
|
+
}, '');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static fromArgs(level, args, ms) {
|
|
35
|
+
let entry = new LogEntry({
|
|
36
|
+
level,
|
|
37
|
+
text: LogEntry.args2String(args),
|
|
38
|
+
ms,
|
|
39
|
+
});
|
|
40
|
+
return entry;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class Logger {
|
|
45
|
+
constructor(opts = {}) {
|
|
46
|
+
let { history = [], sink = console, msBase = Date.now() } = opts;
|
|
47
|
+
Object.assign(this, {
|
|
48
|
+
history,
|
|
49
|
+
sink,
|
|
50
|
+
msBase,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
addEntry(level, args, fSink) {
|
|
55
|
+
const msg = 'l4r.addEntry;';
|
|
56
|
+
const dbg = DBG.L4R_ADD_ENTRY;
|
|
57
|
+
let { history, sink, msBase } = this;
|
|
58
|
+
let ms = Date.now() - msBase;
|
|
59
|
+
let entry = LogEntry.fromArgs(level, args, ms);
|
|
60
|
+
history.push(entry);
|
|
61
|
+
if (sink) {
|
|
62
|
+
dbg && console.log(msg, 'sink');
|
|
63
|
+
fSink.apply(sink, args);
|
|
64
|
+
}
|
|
65
|
+
return entry;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
debug(...args) {
|
|
69
|
+
return this.addEntry('D', args, this.sink.debug);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
info(...args) {
|
|
73
|
+
return this.addEntry('I', args, this.sink.info);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
log(...args) {
|
|
77
|
+
return this.addEntry('L', args, this.sink.log);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
warn(...args) {
|
|
81
|
+
return this.addEntry('W', args, this.sink.warn);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
error(...args) {
|
|
85
|
+
return this.addEntry('E', args, this.sink.error);
|
|
86
|
+
}
|
|
87
|
+
}
|
package/src/text/word-space.mjs
CHANGED
|
@@ -207,7 +207,7 @@ export class WordSpace {
|
|
|
207
207
|
|
|
208
208
|
// Golden Ratio fudge factor scales a count of 1 to ~0.8
|
|
209
209
|
// 1.6180339887498948482045868343656381177203091798057628621354
|
|
210
|
-
static normalizeVector(v, scale=1.618033988749895) {
|
|
210
|
+
static normalizeVector(v, scale = 1.618033988749895) {
|
|
211
211
|
let vNew = new Vector(v);
|
|
212
212
|
Object.entries(v).forEach((e) => {
|
|
213
213
|
let [key, value] = e;
|
|
@@ -307,7 +307,7 @@ export class DeepLAdapter {
|
|
|
307
307
|
let { translator } = this;
|
|
308
308
|
dbg && console.log(msg, '[1]deleting', id);
|
|
309
309
|
await translator.deleteGlossary(id);
|
|
310
|
-
dbg>1 && console.log(msg, '[2]deleted', id);
|
|
310
|
+
dbg > 1 && console.log(msg, '[2]deleted', id);
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
async listGlossaries() {
|