aboutsummaryrefslogtreecommitdiff
path: root/examples/user-ignore.ts
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-07-06 18:23:02 +0200
committerlonkaars <loek@pipeframe.xyz>2023-07-06 18:23:02 +0200
commitcd01df3747ff361fab819fd1d30fac1dba6240e1 (patch)
tree2333eee43667c5cae6d8cebf6cc67bb5fb5a718e /examples/user-ignore.ts
parentcb78013884e3aa3b1e1a91722f5eeb78c62f6796 (diff)
update tests and examples
Diffstat (limited to 'examples/user-ignore.ts')
-rw-r--r--examples/user-ignore.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/examples/user-ignore.ts b/examples/user-ignore.ts
new file mode 100644
index 0000000..d0abbe3
--- /dev/null
+++ b/examples/user-ignore.ts
@@ -0,0 +1,36 @@
+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("浮上したハイラル城の下にてゼルダ様達の捜索を行うこととなった");
+
+// Freeze disables automatic updating of words after database mutations. It's
+// used here because there are multiple sequential updates to the database.
+sentence.freeze();
+
+// Ignore some expressions in JMdict (ignore applies to current user = gert in
+// this case)
+sentence.words.find(w => w.written("達") && w.read("だち"))?.ignore(); // wrong reading for this case
+sentence.at("の下に").ignore(); // expression のもとに
+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()
+sentence.unfreeze();
+
+// Get new reading for sentence
+var furigana = sentence.furigana();
+
+console.log(furigana);
+