aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-06-29 23:25:01 +0200
committerlonkaars <loek@pipeframe.xyz>2023-06-29 23:25:01 +0200
commitcc5689eaf4f7cfa158e31107906434da9aed62bf (patch)
treef02bb5f0887a48de32b9b06b6500c158043f0c52 /examples
parentccd4760cc28082c2d7d9bbebd1a60fe7da65d121 (diff)
WIP examples + change `.prepare()` to `await .ready`
Diffstat (limited to 'examples')
-rw-r--r--examples/readme.md17
-rw-r--r--examples/sentence-word-lookup.ts23
2 files changed, 40 insertions, 0 deletions
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
+