diff options
Diffstat (limited to 'examples/sentence-word-lookup.ts')
-rw-r--r-- | examples/sentence-word-lookup.ts | 23 |
1 files changed, 23 insertions, 0 deletions
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 + |