Skip to content

Commit

Permalink
Speeding up lexicon loading.
Browse files Browse the repository at this point in the history
Lexicon is a json now.
  • Loading branch information
hellpanderrr committed May 18, 2024
1 parent 9f3f383 commit 8a3435e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 14 deletions.
2 changes: 1 addition & 1 deletion wiktionary_pron/scripts/lexicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async function loadLexicon(language) {
const lexiconFolder = "./utils/";
const wordPairsList = await loadFileFromZip(
lexiconFolder + languages[language],
"lexicon.txt",
"de_lexicon.json",
);

function process_lexicon(text) {
Expand Down
14 changes: 1 addition & 13 deletions wiktionary_pron/scripts/lexicon_loader_worker.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
self.onmessage = function (e) {
const splitAndAppend = (str, delim, count) => {
const index = str.indexOf(delim);
return [str.slice(0, index), str.slice(index + 1)];
};
const split = e.data.split(/\r?\n/);
const lines = [];

for (let index = 0; index < split.length; index++) {
const [text, ipa] = splitAndAppend(split[index], "\t", 1);
lines.push([text, ipa.split(" ").join("")]);
}

const dict = new Map(lines.reverse());
dict = new Map(JSON.parse(e.data));
self.postMessage(dict);
};
Binary file modified wiktionary_pron/utils/german_lexicon.zip
Binary file not shown.

0 comments on commit 8a3435e

Please sign in to comment.