add meaning to sentence cloze

This commit is contained in:
polv committed 2022-05-01 19:52:28 +07:00
1 parent b4bc954057
commit cfadfd60a7
1 file changed
+35 -15
+35 -15
View File
@@ -433,6 +433,7 @@ export class WaniKani {
ja: string;
en: string;
}[];
meaning: string;
}
>();
vocabularies.map((v) => {
@@ -442,6 +443,10 @@ export class WaniKani {
sentenceMap.set(v.data.characters, {
...sent,
sentences: v.data.context_sentences,
meaning: v.data.meanings
.sort((m1, m2) => Number(m2.primary) - Number(m1.primary))
.map((m) => m.meaning)
.join('; '),
});
});
if (!sentenceMap.size) return;
@@ -476,23 +481,38 @@ export class WaniKani {
[fields.sentenceEn]: sent.en,
};
if (
fields.sentenceCloze &&
!n.fields[fields.sentenceCloze]?.value
) {
const clozeChar = '__';
let newSent = sent.sentences
.map(({ ja, en }) => `${ja}<br/>${en}`)
.join('<br/>')
.replace(cleanJa, clozeChar);
if (fields.sentenceCloze) {
let clozeSent = n.fields[fields.sentenceCloze]?.value || '';
cleanJa.split(/[\p{sc=Hiragana}]+/gu).map((c) => {
if (c) {
newSent = newSent.replace(c, clozeChar);
}
});
if (!clozeSent && sent.sentences.length) {
const clozeChar = '__';
let newSent = sent.sentences
.map(({ ja, en }) => `${ja}<br/>${en}`)
.join('<br/>')
.replace(cleanJa, clozeChar);
fieldUpdate[fields.sentenceCloze] = newSent;
cleanJa.split(/[\p{sc=Hiragana}]+/gu).map((c) => {
if (c) {
newSent = newSent.replace(c, clozeChar);
}
});
fieldUpdate[fields.sentenceCloze] = newSent;
clozeSent = newSent;
}
const notJa = '[^\\p{sc=Han}\\p{sc=Katakana}\\p{sc=Hiragana}]+';
if (
clozeSent &&
!new RegExp(
`(^${notJa}<br/?>|<br/?><br/?>${notJa}$)`,
'u',
).test(clozeSent)
) {
fieldUpdate[fields.sentenceCloze] =
sent.meaning + '<br><br>' + clozeSent;
}
}
notesToUpdate.push({