aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-06-30 17:31:46 +0200
committerlonkaars <loek@pipeframe.xyz>2023-06-30 17:31:46 +0200
commit722127ef4059020876f708b1d5406c04fd07b0da (patch)
tree1a849e4c8eae688a9e51aaaaaff76d56ca79f171 /examples
parentcc5689eaf4f7cfa158e31107906434da9aed62bf (diff)
WIP user api
Diffstat (limited to 'examples')
-rw-r--r--examples/sentence-word-lookup.ts22
1 files changed, 13 insertions, 9 deletions
diff --git a/examples/sentence-word-lookup.ts b/examples/sentence-word-lookup.ts
index 7f5331b..ff82853 100644
--- a/examples/sentence-word-lookup.ts
+++ b/examples/sentence-word-lookup.ts
@@ -1,23 +1,27 @@
-import YomikunDirectAPIClient from "../core/direct/client.ts";
+import Yomikun from "../api/yomikun.ts";
+import DirectCoreClient from "../core/direct/client.ts";
// Create a direct (local) API instance
-var api = new YomikunDirectAPIClient();
+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 = api.sentence("この紅茶は甘すぎる");
+var sentence = await api.sentence("この紅茶は甘すぎる");
+console.log(await sentence.test());
// 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)
+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)
// Fetch definitions for word
-var glossary = word.glossary();
-
+var glossary = await word?.glossary();
-// WIP
+// Show some definitions
+console.log(glossary?.dict("jmdict_eng")[0]); // print first definition from JMdict
+// console.log(glossary.all()); // print all definitions