import * as path from 'https://deno.land/std@0.102.0/path/mod.ts'; Deno.chdir(path.dirname(path.fromFileUrl(Deno.mainModule))); import { ParseResult } from "./language/types.ts"; function prettyprintParseResult(input: ParseResult) { for (var token of input.tokens) { var out = ""; out += token.term_id; out += ": "; out += token.reading.map(r => r.text).reduce((a, b) => a + b); out += " ("; out += token.reading.map(r => r.ruby ? r.ruby : r.text).reduce((a, b) => a + b); out += ") "; out += token.tags.map(a => `[${a}]`).join(" "); console.log(out); } console.log(input.tokens.map(t => t.source).join(" ")); } import API from "./core/api.ts"; import YomikunDirectAPIClient from "./core/direct/client.ts"; import YomikunRemoteAPIServer from "./core/http/server.ts"; import YomikunRemoteAPIClient from "./core/http/client.ts"; async function apiTest(api: API) { prettyprintParseResult(await api.parseSentence("浮上したハイラル城の下にてゼルダ様達の捜索を行うこととなった")); console.log("-------------"); prettyprintParseResult(await api.parseSentence("浮上した城の様")); console.log("-------------"); prettyprintParseResult(await api.parseSentence("迷子になってしまった")); } // test 1 (direct api) await (async () => { var api = new YomikunDirectAPIClient(); await api.prepare(); console.log("Prepare direct api done"); await apiTest(api); })(); console.log("\n".repeat(2)); // test 2 (remote api) await (async () => { // default host = localhost:9400 var server = new YomikunRemoteAPIServer(); await server.prepare(); server.start(); var api = new YomikunRemoteAPIClient(); await api.prepare(); console.log("Prepare remote api done"); await apiTest(api); Deno.exit(0); })();