diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-06-30 23:23:47 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-06-30 23:23:47 +0200 |
commit | 8ff39cbe6300ca479584fe7d85ff03a1f65bc9b0 (patch) | |
tree | c354294dbbeb6c86d5909955762326272664f07b /examples | |
parent | 722127ef4059020876f708b1d5406c04fd07b0da (diff) |
WIP move more stuff around + more broken examples
Diffstat (limited to 'examples')
-rw-r--r-- | examples/furigana-html.ts | 19 | ||||
-rw-r--r-- | examples/reading-correction-break.ts | 21 | ||||
-rw-r--r-- | examples/readme.md | 1 | ||||
-rw-r--r-- | examples/sentence-word-lookup.ts | 2 |
4 files changed, 42 insertions, 1 deletions
diff --git a/examples/furigana-html.ts b/examples/furigana-html.ts new file mode 100644 index 0000000..5f59b4f --- /dev/null +++ b/examples/furigana-html.ts @@ -0,0 +1,19 @@ +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()); + +// Excplicitly wait until everything is ready +// 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 +// reference to that API instance for fetching additional data. +var sentence = await api.sentence("日本に来て一番驚いたことは自動販売機の多さだ。"); + +// Copy the sentence verbatim but add furigana to each word's kanji +var furigana = sentence.furigana({ format: "HTML" }); + +console.log(furigana); + diff --git a/examples/reading-correction-break.ts b/examples/reading-correction-break.ts new file mode 100644 index 0000000..3f0359b --- /dev/null +++ b/examples/reading-correction-break.ts @@ -0,0 +1,21 @@ +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()); + +// Excplicitly wait until everything is ready +// await api.ready; + +// index sentence (generates wrong readings) +var sentence = await api.sentence("日本に来て一番驚いたことは自動販売機の多さだ。"); + +// generated reading (wrong) +console.log(sentence.furigana()); + +// insert parser break +sentence.break(sentence.at("漢字")); + +// generated reading (correct) +console.log(sentence.furigana()); + diff --git a/examples/readme.md b/examples/readme.md index 9eb8760..bc7fa9d 100644 --- a/examples/readme.md +++ b/examples/readme.md @@ -14,4 +14,5 @@ Examples (checked = working): - [ ] Login as root and import a dictionary from a local file - [ ] Series-specific search with a lot of jargon - [ ] Lookup kanji details of a word +- [ ] Choose alternate kanji reading for word diff --git a/examples/sentence-word-lookup.ts b/examples/sentence-word-lookup.ts index ff82853..6fd57bd 100644 --- a/examples/sentence-word-lookup.ts +++ b/examples/sentence-word-lookup.ts @@ -1,5 +1,6 @@ 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()); @@ -11,7 +12,6 @@ var api = new Yomikun(new DirectCoreClient()); // fetched by the user. Each subclass instantiated from an API instance keeps a // reference to that API instance for fetching additional data. var sentence = await api.sentence("この紅茶は甘すぎる"); -console.log(await sentence.test()); // 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) |