blob: d60ffbf3e294475bb67c0ed4f264e4cbea4b6a5d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
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;
// 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 = 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);
// Fetch definitions for word
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
|