Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanVukovic99 committed Oct 9, 2024
1 parent da8312e commit e12baa5
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions 3-tidy-up.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,34 +142,8 @@ function handleLine(line) {
if(!pos) return;
const word = getCanonicalWordForm(parsedLine);
if (!word) return;
const readings = getReadings(word, parsedLine);

if (forms) {
forms.forEach((formData) => {
const { form } = formData;
let { tags } = formData;
if(!form) return;
if(!tags) return;
if(form === '-') return;
tags = tags.filter(tag => !redundantTags.includes(tag));
const isBlacklisted = tags.some(value => blacklistedTags.includes(value));
if (isBlacklisted) return;
const isIdentity = !tags.some(value => !identityTags.includes(value));
if (isIdentity) return;

const wordMap = automatedForms.get(word) || new Map();
const formMap = wordMap.get(form) || new Map();
formMap.get(pos) || formMap.set(pos, new Set());
wordMap.set(form, formMap);
automatedForms.set(word, wordMap);

const tagsSet = new Set((formMap.get(pos)));

tagsSet.add(sortTags(targetIso, tags).join(' '));

formMap.set(pos, similarSort(mergePersonTags(targetIso, Array.from(tagsSet))));
});
}
processForms(forms, word, pos);

const {senses} = parsedLine;
if (!senses) return;
Expand Down Expand Up @@ -213,7 +187,8 @@ function handleLine(line) {
});

if (sensesWithoutInflectionGlosses.length === 0) return;


const readings = getReadings(word, parsedLine);
initializeWordResult(word, readings, pos);

for (const ipaObj of ipa) {
Expand Down Expand Up @@ -256,6 +231,35 @@ function handleLine(line) {
}
}

function processForms(forms, word, pos) {
if (forms) {
forms.forEach((formData) => {
const { form } = formData;
let { tags } = formData;
if (!form) return;
if (!tags) return;
if (form === '-') return;
tags = tags.filter(tag => !redundantTags.includes(tag));
const isBlacklisted = tags.some(value => blacklistedTags.includes(value));
if (isBlacklisted) return;
const isIdentity = !tags.some(value => !identityTags.includes(value));
if (isIdentity) return;

const wordMap = automatedForms.get(word) || new Map();
const formMap = wordMap.get(form) || new Map();
formMap.get(pos) || formMap.set(pos, new Set());
wordMap.set(form, formMap);
automatedForms.set(word, wordMap);

const tagsSet = new Set((formMap.get(pos)));

tagsSet.add(sortTags(targetIso, tags).join(' '));

formMap.set(pos, similarSort(mergePersonTags(targetIso, Array.from(tagsSet))));
});
}
}

function saveSenseResult(word, readings, pos, currSense) {
for (const reading of readings) {
lemmaDict[word][reading][pos].senses.push(currSense);
Expand Down

0 comments on commit e12baa5

Please sign in to comment.