aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/api.ts35
-rw-r--r--core/http/client.ts41
-rw-r--r--core/http/types.ts35
-rw-r--r--core/raw/api.ts30
4 files changed, 103 insertions, 38 deletions
diff --git a/core/api.ts b/core/api.ts
index 0720c8b..77195b2 100644
--- a/core/api.ts
+++ b/core/api.ts
@@ -1,6 +1,33 @@
-import { InputSentenceProps, ParseResult } from "../language/types.ts";
+import { SearchSentenceProps, SearchSentenceResult, SearchTermResult } from "../search/types.ts";
import { DeepPartial } from "../util/types.ts";
+/** @interface serach-related functions */
+export interface CoreSearch {
+ terms(term: string): Promise<Array<SearchTermResult>>;
+ sentence(sentence: string, optional?: DeepPartial<SearchSentenceProps>): Promise<SearchSentenceResult>;
+ // glossary: (input: string) => Promise<void>;
+};
+
+/** @interface user management */
+export interface CoreUser {
+ // TODO: list
+ // TODO: add
+ // TODO: remove
+ // TODO: get info
+};
+
+/** @interface dictionary/user data import functions */
+export interface CoreImport {
+ // TODO: import dictionary
+ // TODO: import user preferences
+};
+
+/** @interface dictionary/user data export functions */
+export interface CoreExport {
+ // TODO: export dictionary
+ // TODO: export user preferences
+};
+
/**
* @summary Core interface
*
@@ -12,7 +39,9 @@ export default abstract class Core {
/** @summary resolved when ready */
abstract ready: Promise<void>;
- /** @summary parse sentence */
- abstract parseSentence(input: string, options?: DeepPartial<InputSentenceProps>): Promise<ParseResult>;
+ abstract search: CoreSearch;
+ abstract user: CoreUser;
+ abstract import: CoreImport;
+ abstract export: CoreExport;
};
diff --git a/core/http/client.ts b/core/http/client.ts
index 6b4e1a3..80f77b3 100644
--- a/core/http/client.ts
+++ b/core/http/client.ts
@@ -1,10 +1,8 @@
-import { InputSentenceProps } from "../../language/types.ts";
import "../../util/array.ts";
-import { DeepPartial } from "../../util/types.ts";
-import Core from "../api.ts";
+import Core, { CoreExport, CoreImport, CoreSearch, CoreUser } from "../api.ts";
import { ConnectionProps, ConnectionPropsDefault } from "./props.ts";
-import { CoreRequest, CoreRequestParseSentence, CoreResponseParseSentence } from "./types.ts";
+import { CoreRequest, CoreRequestSearchSentence, CoreRequestSearchTerms, CoreResponseSearchSentence, CoreResponseSearchTerms } from "./types.ts";
/**
* @summary HTTP Core client
@@ -13,8 +11,9 @@ import { CoreRequest, CoreRequestParseSentence, CoreResponseParseSentence } from
* (de)serialization automatically.
*/
export default class RemoteCoreClient implements Core {
+ public ready: Promise<void> = Promise.resolve();
+
private props: ConnectionProps;
- ready: Promise<void> = Promise.resolve();
constructor(options?: ConnectionProps) {
this.props = { ...ConnectionPropsDefault, ...options };
@@ -32,13 +31,29 @@ export default class RemoteCoreClient implements Core {
return response.json();
}
- async parseSentence(input: string, options?: DeepPartial<InputSentenceProps>) {
- var request: CoreRequestParseSentence = {
- command: "parseSentence",
- options: { input, options, },
- };
- var { response } = await this.request(request) as CoreResponseParseSentence;
- return response;
- }
+ public search: CoreSearch = {
+ terms: async term => {
+ var request: CoreRequestSearchTerms = {
+ command: "search.terms",
+ options: { term, },
+ };
+ var { response } = await this.request(request) as CoreResponseSearchTerms;
+ return response;
+ },
+ sentence: async (sentence, optional?) => {
+ var request: CoreRequestSearchSentence = {
+ command: "search.sentence",
+ options: { sentence, optional, },
+ };
+ var { response } = await this.request(request) as CoreResponseSearchSentence;
+ return response;
+ },
+ };
+
+ public user: CoreUser = {};
+
+ public import: CoreImport = {};
+
+ public export: CoreExport = {};
}
diff --git a/core/http/types.ts b/core/http/types.ts
index 3d55a98..51c221a 100644
--- a/core/http/types.ts
+++ b/core/http/types.ts
@@ -1,4 +1,4 @@
-import { InputSentenceProps, ParseResult } from "../../language/types.ts";
+import { SearchTermResult, SearchSentenceResult, SearchSentenceProps } from "../../search/types.ts";
import { DeepPartial } from "../../util/types.ts";
export interface CoreRequest {
@@ -6,22 +6,33 @@ export interface CoreRequest {
options: any;
};
-export interface CoreRequestParseSentence extends CoreRequest {
- command: "parseSentence";
- options: {
- input: string;
- options?: DeepPartial<InputSentenceProps>;
- };
-};
-
export interface CoreResponse {
command: string;
response: any;
// final: boolean;
};
-export interface CoreResponseParseSentence extends CoreResponse {
- command: "parseSentence";
- response: ParseResult;
+export interface CoreRequestSearchSentence extends CoreRequest {
+ command: "search.sentence";
+ options: {
+ sentence: string;
+ optional?: DeepPartial<SearchSentenceProps>;
+ };
};
+export interface CoreResponseSearchSentence extends CoreResponse {
+ command: "search.sentence";
+ response: SearchSentenceResult;
+};
+
+export interface CoreRequestSearchTerms extends CoreRequest {
+ command: "search.terms";
+ options: {
+ term: string;
+ };
+};
+
+export interface CoreResponseSearchTerms extends CoreResponse {
+ command: "search.terms";
+ response: Array<SearchTermResult>;
+};
diff --git a/core/raw/api.ts b/core/raw/api.ts
index 593b932..6046a26 100644
--- a/core/raw/api.ts
+++ b/core/raw/api.ts
@@ -1,29 +1,39 @@
-import Core from "../api.ts";
-import Parser from "../../language/parser.ts";
+import Core, { CoreExport, CoreImport, CoreSearch, CoreUser } from "../api.ts";
import YomikunError from "../../util/error.ts";
-import { DeepPartial } from "../../util/types.ts";
-import { InputSentenceProps } from "../../language/types.ts";
+import Search from "../../search/search.ts";
/** @summary internal Core (DO NOT USE DIRECTLY) */
export default class RawCore implements Core {
- private parser: Parser;
public ready: Promise<void>;
+ private _search: Search;
+
constructor() {
if (this.constructor === RawCore) {
throw new YomikunError("RawCore instantiated! Use DirectCoreClient instead!");
}
- this.parser = new Parser();
+ this._search = new Search();
this.ready = new Promise(async resolve => {
- await this.parser.ready;
+ await this._search.ready;
resolve();
})
}
- async parseSentence(input: string, options?: DeepPartial<InputSentenceProps>) {
- return await this.parser.parse(input, options);
- }
+ public search: CoreSearch = {
+ terms: async term => {
+ return await this._search.terms(term);
+ },
+ sentence: async (sentence, optional?) => {
+ return await this._search.sentence(sentence, optional);
+ },
+ };
+
+ public user: CoreUser = {};
+
+ public import: CoreImport = {};
+
+ public export: CoreExport = {};
};