diff options
-rw-r--r-- | core/http/client.ts | 13 | ||||
-rw-r--r-- | core/http/server.ts | 13 | ||||
-rw-r--r-- | core/http/types.ts | 12 | ||||
-rw-r--r-- | db/dict/deinflections.sql | 1 | ||||
-rw-r--r-- | test/deinflection/cases.ts | 1 |
5 files changed, 37 insertions, 3 deletions
diff --git a/core/http/client.ts b/core/http/client.ts index 80f77b3..36f361b 100644 --- a/core/http/client.ts +++ b/core/http/client.ts @@ -2,7 +2,7 @@ import "../../util/array.ts"; import Core, { CoreExport, CoreImport, CoreSearch, CoreUser } from "../api.ts"; import { ConnectionProps, ConnectionPropsDefault } from "./props.ts"; -import { CoreRequest, CoreRequestSearchSentence, CoreRequestSearchTerms, CoreResponseSearchSentence, CoreResponseSearchTerms } from "./types.ts"; +import { CoreRequest, CoreRequestSearchSentence, CoreRequestSearchTerms, CoreRequestUserTermPriority, CoreResponseSearchSentence, CoreResponseSearchTerms, CoreResponseUserTermPriority } from "./types.ts"; /** * @summary HTTP Core client @@ -50,7 +50,16 @@ export default class RemoteCoreClient implements Core { }, }; - public user: CoreUser = {}; + public user: CoreUser = { + termPriority: async (userID, expression, reading, priority) => { + var request: CoreRequestUserTermPriority = { + command: "user.termPriority", + options: { userID, expression, reading, priority, }, + }; + var { response } = await this.request(request) as CoreResponseUserTermPriority; + return response; + }, + }; public import: CoreImport = {}; diff --git a/core/http/server.ts b/core/http/server.ts index 7e77e19..0518289 100644 --- a/core/http/server.ts +++ b/core/http/server.ts @@ -4,7 +4,7 @@ import "../../util/string.ts"; import RawCore from "../raw/api.ts"; import { ConnectionProps, ConnectionPropsDefault } from "./props.ts"; -import { CoreRequest, CoreRequestSearchSentence, CoreRequestSearchTerms, CoreResponseSearchSentence, CoreResponseSearchTerms } from "./types.ts"; +import { CoreRequest, CoreRequestSearchSentence, CoreRequestSearchTerms, CoreRequestUserTermPriority, CoreResponseSearchSentence, CoreResponseSearchTerms, CoreResponseUserTermPriority } from "./types.ts"; export default class RemoteCoreServer extends RawCore { @@ -27,6 +27,17 @@ export default class RemoteCoreServer extends RawCore { response: await this.search.sentence(sentence, optional), } as CoreResponseSearchSentence)); }, + "user.termPriority": async _req => { + var req = _req as CoreRequestUserTermPriority; + var ok = true; + ok = ok && (typeof req.options?.userID === "number"); + ok = ok && !!(req.options?.expression); + ok = ok && !!(req.options?.reading); + ok = ok && (typeof req.options?.priority === "number"); + if (!ok) return new Response("", { status: 404 }); + await this.user.termPriority(req.options!.userID, req.options!.expression, req.options!.reading, req.options!.priority); + return new Response(JSON.stringify({} as CoreResponseUserTermPriority)); + }, }; constructor(options?: ConnectionProps) { diff --git a/core/http/types.ts b/core/http/types.ts index 9edc2dc..5ea445e 100644 --- a/core/http/types.ts +++ b/core/http/types.ts @@ -33,3 +33,15 @@ export interface CoreRequestSearchTerms extends CoreRequest { export interface CoreResponseSearchTerms extends CoreResponse { response: Array<SearchTermResult>; }; + +export interface CoreRequestUserTermPriority extends CoreRequest { + command: "user.termPriority"; + options: { + userID: number; + expression: string; + reading: string; + priority: number; + }; +}; + +export interface CoreResponseUserTermPriority extends CoreResponse { }; diff --git a/db/dict/deinflections.sql b/db/dict/deinflections.sql index da97d51..7472122 100644 --- a/db/dict/deinflections.sql +++ b/db/dict/deinflections.sql @@ -158,6 +158,7 @@ insert into deinflection_temp values -- obligation <https://guidetojapanese.org/learn/grammar/must> -- TODO: manually write these out instead of splitting particle and suffix ('infl:negative infl:must tmp:infl:must:res', 'だめ', '', 'a', 'ot'), -- built-in negative because だめ can't be deconjugated + ('infl:negative infl:must tmp:infl:must:res', 'ダメ', '', 'a', 'ot'), -- same as above but for katakana ('infl:must tmp:infl:must:res', 'いける', '', 'ru', 'ot'), -- はいけない -> positive (stored this way because obligatory could be in past) ('infl:must tmp:infl:must:res', 'なる', '', 'u', 'ot'), -- はならない -> positive ('tmp:infl:must:prt infl:must', 'は', '', 'ot', 'nt'), -- removes particle (negative -te + は + だめ/いけない/ならない) diff --git a/test/deinflection/cases.ts b/test/deinflection/cases.ts index 504c9e2..6cf2b18 100644 --- a/test/deinflection/cases.ts +++ b/test/deinflection/cases.ts @@ -78,6 +78,7 @@ export default [ { input: "見極めなければならない", mustHave: [ Inflection.Obligatory, Inflection.Affirmative ], mustNotHave: [ Inflection.Conditional.Ba, Inflection.Negative ] }, { input: "ならなきゃいけない", mustHave: [ Inflection.Obligatory, Inflection.Affirmative ], mustNotHave: [ Inflection.Conditional.Ba, Inflection.Negative ] }, { input: "探さなくては", mustHave: [ Inflection.Obligatory, Inflection.Affirmative ], mustNotHave: [ Inflection.Suffix.Te, Inflection.Negative ] }, + { input: "出ちゃダメ", mustHave: [ Inflection.Obligatory, Inflection.Negative ], mustNotHave: [ Inflection.Suffix.Te, Inflection.Affirmative ] }, // TODO: りゃ for いることは // TODO: じゃ for では // and more! |