diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/furigana-html.ts | 4 | ||||
-rw-r--r-- | examples/reading-correction-break.ts | 6 | ||||
-rw-r--r-- | examples/sentence-word-lookup.ts | 18 | ||||
-rw-r--r-- | examples/user-ignore.ts | 36 |
4 files changed, 50 insertions, 14 deletions
diff --git a/examples/furigana-html.ts b/examples/furigana-html.ts index f0ff067..fa599ed 100644 --- a/examples/furigana-html.ts +++ b/examples/furigana-html.ts @@ -4,8 +4,8 @@ import DirectCoreClient from "../core/direct/client.ts"; // Create a direct (local) API instance var api = new Yomikun(new DirectCoreClient()); -// Excplicitly wait until everything is ready -// await api.ready; +// Explicitly wait until everything is ready (not required) +await api.ready; // This sentence does not contain all information until it is explicitly // fetched by the user. Each subclass instantiated from an API instance keeps a diff --git a/examples/reading-correction-break.ts b/examples/reading-correction-break.ts index 3f0359b..6761165 100644 --- a/examples/reading-correction-break.ts +++ b/examples/reading-correction-break.ts @@ -1,11 +1,13 @@ import Yomikun from "../api/yomikun.ts"; import DirectCoreClient from "../core/direct/client.ts"; +// WIP + // Create a direct (local) API instance var api = new Yomikun(new DirectCoreClient()); -// Excplicitly wait until everything is ready -// await api.ready; +// Explicitly wait until everything is ready (not required) +await api.ready; // index sentence (generates wrong readings) var sentence = await api.sentence("日本に来て一番驚いたことは自動販売機の多さだ。"); diff --git a/examples/sentence-word-lookup.ts b/examples/sentence-word-lookup.ts index d60ffbf..9ff9bdf 100644 --- a/examples/sentence-word-lookup.ts +++ b/examples/sentence-word-lookup.ts @@ -1,12 +1,11 @@ import Yomikun from "../api/yomikun.ts"; import DirectCoreClient from "../core/direct/client.ts"; -// import "../util/string.ts"; // Create a direct (local) API instance var api = new Yomikun(new DirectCoreClient()); -// Excplicitly wait until everything is ready -// await api.ready; +// Explicitly wait until everything is ready (not required) +await api.ready; // This sentence does not contain all information until it is explicitly // fetched by the user. Each subclass instantiated from an API instance keeps a @@ -14,15 +13,14 @@ var api = new Yomikun(new DirectCoreClient()); var sentence = await api.sentence("この紅茶は甘すぎる"); // Pick the word 紅茶 from the sentence in some different ways: -var word = sentence.words.find(w => w.writing == "紅茶"); // filter terms by writing (matches first only) -// var word = sentence.first("紅茶"); // reference substring (matches first only) -// var word = sentence.words[1]; // reference word index (depends on correct deconjugations/parsing) -console.log(word); +var word = sentence.words.find(w => w.written("紅茶"))!; // filter terms by writing (matches first only) +var word = sentence.first("紅茶")!; // reference substring (matches first only) +var word = sentence.words[1]; // reference word index (depends on correct deconjugations/parsing) // Fetch definitions for word -var glossary = await word?.glossary(); +var glossary = await word.glossary(); // Show some definitions -console.log(glossary?.dict("jmdict_eng")[0]); // print first definition from JMdict -// console.log(glossary.all()); // print all definitions +console.log(glossary.dict("jmdict_eng")[0]); // print first definition from JMdict +console.log(glossary.all()); // print all definitions 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); + |