aboutsummaryrefslogtreecommitdiff
path: root/examples/user-ignore.ts
blob: f15baed4387d7f119dc674b07a644967b6b2278b (plain)
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
import Yomikun from "../api/yomikun.ts";
import DirectCoreClient from "../core/direct/client.ts";

// Create a direct (local) API instance
var api = new Yomikun(new DirectCoreClient());

// Explicitly wait until everything is ready (not required)
await api.ready;

// Substitute user to gert (from default login root)
api.su("gert");

// Lookup sentence
var sentence = await api.sentence("浮上したハイラル城の下にてゼルダ様達の捜索を行うこととなった");

// Get reading for sentence
console.log(sentence.furigana());

// Freeze disables automatic updating of words after database mutations. It's
// used here because there are multiple sequential updates to the database.
await sentence.freeze();

// Ignore some expressions in JMdict (ignore applies to current user = gert in
// this case) (TODO: this only works on a fresh database)
await sentence.words.find(w => w.written("達") && w.read("だち"))?.ignore(); // wrong reading for this case
await sentence.at("の下に")?.ignore(); // expression のもとに
await sentence.forceUpdate(); // manual update to get last wrong term
await sentence.at("下に")?.ignore(); // expression したに

// TODO: 達(だち) should not have to be ignored, but scored lower following
// rendaku rules. <https://en.wikipedia.org/wiki/Rendaku>

// Unfreeze allows updates again and implicitly calls .update()
await sentence.unfreeze();

// Get new reading for sentence
console.log(sentence.furigana());