aboutsummaryrefslogtreecommitdiff
path: root/types
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-01-31 08:28:05 -0500
committerGitHub <noreply@github.com>2024-01-31 13:28:05 +0000
commit3e419aa562aab03ca20421aaf7e4d1a39194a5b4 (patch)
tree15e8bfe81fa5e3fae55e54802f14d94a7502a469 /types
parent6807b05e9bd41f013364fae0cbcce83cf1ed37b6 (diff)
Language transformer (#582)
* Set up new deinflection data file * Define types * Test * Add internal types * Set up loading for transforms * Add getPartOfSpeechFlags * Convert static methods * Add note * Add transform function * Update trace structure * Add a language tag to the language transform descriptor * Add clear function * Add function for multiple parts of speech * Clarify naming * Add getConditionFlagsFromConditionType * Add plural function * Replace usages of Deinflector * Update tests * Update config * Remove old * Rename * Rename files
Diffstat (limited to 'types')
-rw-r--r--types/ext/language-transformer-internal.d.ts (renamed from types/ext/deinflector.d.ts)40
-rw-r--r--types/ext/language-transformer.d.ts62
-rw-r--r--types/ext/offscreen.d.ts4
-rw-r--r--types/ext/translation-internal.d.ts19
4 files changed, 84 insertions, 41 deletions
diff --git a/types/ext/deinflector.d.ts b/types/ext/language-transformer-internal.d.ts
index 18d0f04a..cb0899e9 100644
--- a/types/ext/deinflector.d.ts
+++ b/types/ext/language-transformer-internal.d.ts
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2023-2024 Yomitan Authors
+ * Copyright (C) 2024 Yomitan Authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -15,29 +15,27 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import type * as TranslationInternal from './translation-internal';
-
-export type ReasonTypeRaw = 'v1' | 'v1d' | 'v1p' | 'v5' | 'vs' | 'vk' | 'vz' | 'adj-i' | 'iru';
+export type Transform = {
+ name: string;
+ rules: Rule[];
+};
-export type ReasonsRaw = {
- [reason: string]: ReasonRaw[];
+export type Rule = {
+ suffixIn: string;
+ suffixOut: string;
+ conditionsIn: number;
+ conditionsOut: number;
};
-export type ReasonRaw = {
- kanaIn: string;
- kanaOut: string;
- rulesIn: ReasonTypeRaw[];
- rulesOut: ReasonTypeRaw[];
+export type TransformedText = {
+ text: string;
+ conditions: number;
+ trace: Trace;
};
-export type ReasonVariant = [
- kanaIn: string,
- kanaOut: string,
- rulesIn: TranslationInternal.DeinflectionRuleFlags,
- rulesOut: TranslationInternal.DeinflectionRuleFlags,
-];
+export type Trace = TraceFrame[];
-export type Reason = [
- reason: string,
- variants: ReasonVariant[],
-];
+export type TraceFrame = {
+ transform: string;
+ ruleIndex: number;
+};
diff --git a/types/ext/language-transformer.d.ts b/types/ext/language-transformer.d.ts
new file mode 100644
index 00000000..08c7a3dc
--- /dev/null
+++ b/types/ext/language-transformer.d.ts
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2024 Yomitan Authors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+export type LanguageTransformDescriptor = {
+ language: string;
+ conditions: ConditionMapObject;
+ transforms: Transform[];
+};
+
+export type ConditionMapObject = {
+ [type: string]: Condition;
+};
+
+export type ConditionMapEntry = [type: string, condition: Condition];
+
+export type ConditionMapEntries = ConditionMapEntry[];
+
+export type Condition = {
+ name: string;
+ partsOfSpeech: string[];
+ i18n?: RuleI18n[];
+ subConditions?: string[];
+};
+
+export type RuleI18n = {
+ language: string;
+ name: string;
+};
+
+export type Transform = {
+ name: string;
+ description?: string;
+ i18n?: TransformI18n[];
+ rules: Rule[];
+};
+
+export type TransformI18n = {
+ language: string;
+ name: string;
+ description?: string;
+};
+
+export type Rule = {
+ suffixIn: string;
+ suffixOut: string;
+ conditionsIn: string[];
+ conditionsOut: string[];
+};
diff --git a/types/ext/offscreen.d.ts b/types/ext/offscreen.d.ts
index a721c1b9..443e0b64 100644
--- a/types/ext/offscreen.d.ts
+++ b/types/ext/offscreen.d.ts
@@ -15,7 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import type * as Deinflector from './deinflector';
import type * as Dictionary from './dictionary';
import type * as DictionaryDatabase from './dictionary-database';
import type * as DictionaryImporter from './dictionary-importer';
@@ -30,6 +29,7 @@ import type {
ApiReturn as BaseApiReturn,
ApiNames as BaseApiNames,
} from './api-map';
+import type {LanguageTransformDescriptor} from './language-transformer';
type ApiSurface = {
databasePrepareOffscreen: {
@@ -52,7 +52,7 @@ type ApiSurface = {
};
translatorPrepareOffscreen: {
params: {
- deinflectionReasons: Deinflector.ReasonsRaw;
+ descriptor: LanguageTransformDescriptor;
};
return: void;
};
diff --git a/types/ext/translation-internal.d.ts b/types/ext/translation-internal.d.ts
index ada611d9..82704c54 100644
--- a/types/ext/translation-internal.d.ts
+++ b/types/ext/translation-internal.d.ts
@@ -39,28 +39,11 @@ export type TextDeinflectionOptionsArrays = [
emphatic: [collapseEmphatic: boolean, collapseEmphaticFull: boolean][],
];
-export enum DeinflectionRuleFlags {
- None = 0x0,
- VerbIchidan = 0b00000001,
- VerbGodan = 0b00000010,
- VerbSuru = 0b00000100,
- VerbKuru = 0b00001000,
- VerbZuru = 0b00010000,
- AdjectiveI = 0b00100000,
- IruEndingIntermediate = 0b01000000,
-}
-
-export type Deinflection = {
- term: string;
- rules: DeinflectionRuleFlags;
- reasons: Dictionary.InflectionRuleChain;
-};
-
export type DatabaseDeinflection = {
originalText: string;
transformedText: string;
deinflectedText: string;
- rules: DeinflectionRuleFlags;
+ conditions: number;
inflectionRuleChainCandidates: Dictionary.InflectionRuleChainCandidate[];
databaseEntries: DictionaryDatabase.TermEntry[];
};