-
Notifications
You must be signed in to change notification settings - Fork 0
/
transcript.ts
71 lines (66 loc) · 2.08 KB
/
transcript.ts
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
import * as fs from "fs";
import * as path from "path";
(async () => {
const troparions = fs.readFileSync(path.resolve(__dirname, "tropare.csv"), {
encoding: "utf-8",
});
// Letters
// load letter substitution dictionary
const letterSubstitutionDictionary = fs.readFileSync(
path.resolve(__dirname, "transcript-dictionary-letters.txt"),
{
encoding: "utf-8",
}
);
const letterSubstitutionMap = new Map<string, string>();
for (const line of letterSubstitutionDictionary.split(/[\r\n]+/)) {
if (line.startsWith("#")) {
continue; //comments
}
const lineSplitted = line.split(" ");
letterSubstitutionMap.set(lineSplitted[0], lineSplitted[1]);
}
// substitute letters
let troparionLetterSubtituted = "";
for (let i = 0; i < troparions.length; i++) {
let character: string;
if (letterSubstitutionMap.has(troparions[i])) {
character = letterSubstitutionMap.get(troparions[i]) as string;
} else {
character = troparions[i];
}
troparionLetterSubtituted += character;
}
console.log(`>>> ${troparionLetterSubtituted}`);
// Groups
// load group substitution dictionary
const groupSubstitutionDictionary = fs.readFileSync(
path.resolve(__dirname, "transcript-dictionary-groups.txt"),
{
encoding: "utf-8",
}
);
const groupSubstitutionMap = new Map<string, string>();
for (const line of groupSubstitutionDictionary.split(/[\r\n]+/)) {
if (line.startsWith("#")) {
continue; //comments
}
const lineSplitted = line.split(" ");
groupSubstitutionMap.set(
lineSplitted[0],
lineSplitted[1] ? lineSplitted[1] : ""
);
}
let troparionGroupSubstituted = troparionLetterSubtituted;
// substitute groups
for (let [key, value] of groupSubstitutionMap) {
console.log(`Group: ${key} ${value}`);
troparionGroupSubstituted = troparionGroupSubstituted.replace(
new RegExp(key, "g"),
value
);
}
console.log(`>>> ${troparionGroupSubstituted}`);
const output = fs.createWriteStream("tropare-prepisane.csv");
output.write(troparionGroupSubstituted);
})();