-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdump-modern-cjk.js
54 lines (47 loc) · 1.43 KB
/
dump-modern-cjk.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
// compute augmented cjk containment
import {UNICODE} from './unicode-version.js';
import {readFileSync} from 'node:fs';
const SPEC = JSON.parse(readFileSync(new URL('./output/spec.json', import.meta.url))); // note: requires spec
let valid = new Set(SPEC.groups.flatMap(g => [...g.primary, ...g.secondary]));
let abbrs = [
'Hang', // Hangul
'Hira', // Hiragan
'Kana', // Katakana
'Hani', // Hana
];
let buckets = {};
for (let abbr0 of abbrs) {
let script0 = UNICODE.require_script(abbr0);
for (let cp of script0.map.keys()) {
if (!valid.has(cp)) continue;
for (let script of UNICODE.get_augmented_script_set(cp)) {
let key = script.abbr;
let bucket = buckets[key];
if (!bucket) {
buckets[key] = bucket = new Set();
}
bucket.add(cp);
}
}
}
buckets = Object.entries(buckets);
for (let [abbr, set] of buckets) {
console.log(`${abbr} (${set.size})`);
}
for (let i = 1; i < buckets.length; i++) {
let [abbr_i, set_i] = buckets[i];
for (let j = 0; j < i; j++) {
let [abbr_j, set_j] = buckets[j];
let i_j = [...set_i].every(x => set_j.has(x));
let j_i = [...set_j].every(x => set_i.has(x));
if (i_j && j_i) {
console.log(`${abbr_i} == ${abbr_j}`);
} else if (i_j) {
console.log(`${abbr_i} contains ${abbr_j}`);
} else if (j_i) {
console.log(`${abbr_j} contains ${abbr_i}`);
} else {
console.log(`${abbr_i} and ${abbr_j} are different`);
}
}
}