From cc5689eaf4f7cfa158e31107906434da9aed62bf Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 29 Jun 2023 23:25:01 +0200 Subject: WIP examples + change `.prepare()` to `await .ready` --- examples/readme.md | 17 +++++++++++++++++ examples/sentence-word-lookup.ts | 23 +++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 examples/readme.md create mode 100644 examples/sentence-word-lookup.ts (limited to 'examples') diff --git a/examples/readme.md b/examples/readme.md new file mode 100644 index 0000000..9eb8760 --- /dev/null +++ b/examples/readme.md @@ -0,0 +1,17 @@ +# API Examples + +## **ALL OF THESE EXAMPLES ARE CURRENTLY NOT WORKING, AND ARE USED TO MODEL THE API UNTIL THEY WORK** + +~This folder contains API examples. These files show some common workflows +using the Yomikun API.~ + +Examples (checked = working): + +- [ ] Lookup a word in a sentence +- [ ] Get furigana in HTML for a sentence +- [ ] Correct the reading of a word (because of ambiguous word boundries) by inserting a break +- [ ] Login as a regular user and ignore an expression +- [ ] 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 + diff --git a/examples/sentence-word-lookup.ts b/examples/sentence-word-lookup.ts new file mode 100644 index 0000000..7f5331b --- /dev/null +++ b/examples/sentence-word-lookup.ts @@ -0,0 +1,23 @@ +import YomikunDirectAPIClient from "../core/direct/client.ts"; + +// Create a direct (local) API instance +var api = new YomikunDirectAPIClient(); +// 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 = api.sentence("この紅茶は甘すぎる"); + +// Pick the word 紅茶 from the sentence in some different ways: +// var word = sentence.at("紅茶"); // reference substring (matches first only) +// var word = sentence.terms[1]; // reference word index (depends on correct deconjugations/parsing) +var word = sentence.terms.find(t => t.writing == "紅茶"); // filter terms by writing (matches first only) + +// Fetch definitions for word +var glossary = word.glossary(); + + +// WIP + -- cgit v1.2.3