diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-07-06 18:23:02 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-07-06 18:23:02 +0200 |
commit | cd01df3747ff361fab819fd1d30fac1dba6240e1 (patch) | |
tree | 2333eee43667c5cae6d8cebf6cc67bb5fb5a718e /examples/sentence-word-lookup.ts | |
parent | cb78013884e3aa3b1e1a91722f5eeb78c62f6796 (diff) |
update tests and examples
Diffstat (limited to 'examples/sentence-word-lookup.ts')
-rw-r--r-- | examples/sentence-word-lookup.ts | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/examples/sentence-word-lookup.ts b/examples/sentence-word-lookup.ts index d60ffbf..9ff9bdf 100644 --- a/examples/sentence-word-lookup.ts +++ b/examples/sentence-word-lookup.ts @@ -1,12 +1,11 @@ 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()); -// Excplicitly wait until everything is ready -// await api.ready; +// Explicitly wait until everything is ready (not required) +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 @@ -14,15 +13,14 @@ var api = new Yomikun(new DirectCoreClient()); var sentence = await api.sentence("この紅茶は甘すぎる"); // 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) -// var word = sentence.first("紅茶"); // reference substring (matches first only) -// var word = sentence.words[1]; // reference word index (depends on correct deconjugations/parsing) -console.log(word); +var word = sentence.words.find(w => w.written("紅茶"))!; // 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 = await word?.glossary(); +var glossary = await word.glossary(); // Show some definitions -console.log(glossary?.dict("jmdict_eng")[0]); // print first definition from JMdict -// console.log(glossary.all()); // print all definitions +console.log(glossary.dict("jmdict_eng")[0]); // print first definition from JMdict +console.log(glossary.all()); // print all definitions |