hanzi-chai 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/affine.d.ts +8 -0
  2. package/dist/affine.js +153 -0
  3. package/dist/assembly.d.ts +63 -0
  4. package/dist/assembly.js +286 -0
  5. package/dist/bezier.d.ts +74 -0
  6. package/dist/bezier.js +140 -0
  7. package/dist/classifier.d.ts +109 -0
  8. package/dist/classifier.js +108 -0
  9. package/dist/component.d.ts +115 -0
  10. package/dist/component.js +278 -0
  11. package/dist/compound.d.ts +64 -0
  12. package/dist/compound.js +652 -0
  13. package/dist/config.d.ts +236 -0
  14. package/dist/config.js +48 -0
  15. package/dist/data/cjk.txt +20902 -0
  16. package/dist/data/data/cjk.txt +20902 -0
  17. package/dist/data/data/dictionary.txt +69429 -0
  18. package/dist/data/data/frequency.txt +263137 -0
  19. package/dist/data/data/key_distribution.txt +46 -0
  20. package/dist/data/data/pair_equivalence.txt +2116 -0
  21. package/dist/data/data/repertoire.json.deflate +0 -0
  22. package/dist/data/data/tygf.txt +8105 -0
  23. package/dist/data/dictionary.txt +69429 -0
  24. package/dist/data/frequency.txt +263137 -0
  25. package/dist/data/key_distribution.txt +46 -0
  26. package/dist/data/pair_equivalence.txt +2116 -0
  27. package/dist/data/repertoire.json.deflate +0 -0
  28. package/dist/data/tygf.txt +8105 -0
  29. package/dist/data.d.ts +195 -0
  30. package/dist/data.js +18 -0
  31. package/dist/degenerator.d.ts +21 -0
  32. package/dist/degenerator.js +134 -0
  33. package/dist/element.d.ts +56 -0
  34. package/dist/element.js +225 -0
  35. package/dist/equivalence.d.ts +21 -0
  36. package/dist/equivalence.js +74 -0
  37. package/dist/index.d.ts +45 -0
  38. package/dist/index.js +126 -0
  39. package/dist/index.mjs +3553 -0
  40. package/dist/mathjs.d.ts +10 -0
  41. package/dist/mathjs.js +9 -0
  42. package/dist/repertoire.d.ts +75 -0
  43. package/dist/repertoire.js +406 -0
  44. package/dist/selector.d.ts +110 -0
  45. package/dist/selector.js +310 -0
  46. package/dist/topology.d.ts +41 -0
  47. package/dist/topology.js +209 -0
  48. package/dist/transformer.d.ts +18 -0
  49. package/dist/transformer.js +111 -0
  50. package/dist/utils.d.ts +107 -0
  51. package/dist/utils.js +546 -0
  52. package/package.json +34 -0
@@ -0,0 +1,236 @@
1
+ import type { Feature } from "./classifier.js";
2
+ import { serializerMap } from "./compound.js";
3
+ import type { Compound, PrimitiveRepertoire, Component, Reading, Identity } from "./data.js";
4
+ import type { CodableObject } from "./element.js";
5
+ import { type 变换器 } from "./transformer.js";
6
+ export interface Info {
7
+ name?: string;
8
+ author?: string;
9
+ version?: string;
10
+ description?: string;
11
+ }
12
+ export declare const characterSetSpecifiers: readonly ["minimal", "gb2312", "general", "basic", "extended", "supplement", "maximal", "custom"];
13
+ export type CharacterSetSpecifier = (typeof characterSetSpecifiers)[number];
14
+ export interface Data {
15
+ character_set?: CharacterSetSpecifier;
16
+ repertoire?: PrimitiveRepertoire;
17
+ glyph_customization?: CustomGlyph;
18
+ reading_customization?: CustomReadings;
19
+ tags?: string[];
20
+ transformers?: 变换器[];
21
+ }
22
+ export type CustomGlyph = Record<string, Component | Compound | Identity>;
23
+ export type CustomReadings = Record<string, Reading[]>;
24
+ export interface Analysis {
25
+ classifier?: Record<Feature, number>;
26
+ degenerator?: Degenerator;
27
+ selector?: Selector;
28
+ customize?: Record<string, string[]>;
29
+ dynamic_customize?: Record<string, string[][]>;
30
+ strong?: string[];
31
+ weak?: string[];
32
+ serializer?: keyof typeof serializerMap;
33
+ }
34
+ export interface Degenerator {
35
+ feature?: Record<Feature, Feature>;
36
+ no_cross?: boolean;
37
+ }
38
+ export type SieveName = "根少优先" | "连续笔顺" | "全符笔顺" | "能连不交" | "能散不连" | "同向笔画" | "取大优先" | "取小优先" | "结构完整" | "多强字根" | "少弱字根" | "非形近根";
39
+ export type Selector = SieveName[];
40
+ export type Algebra = Record<string, Rule[]>;
41
+ export type Rule = Transformation | Transliteration;
42
+ interface Transformation {
43
+ type: "xform";
44
+ from: string;
45
+ to: string;
46
+ }
47
+ interface Transliteration {
48
+ type: "xlit";
49
+ from: string;
50
+ to: string;
51
+ }
52
+ export interface Keyboard {
53
+ alphabet?: string;
54
+ mapping_type?: number;
55
+ mapping: Mapping;
56
+ mapping_space?: MappingSpace;
57
+ mapping_variables?: Record<string, MappingVariableRule>;
58
+ mapping_generators?: MappingGeneratorRule[];
59
+ grouping?: Record<string, string>;
60
+ }
61
+ export interface MappingVariableRule {
62
+ keys: string[];
63
+ }
64
+ export interface MappingGeneratorRule {
65
+ regex: string;
66
+ value: ValueDescription;
67
+ }
68
+ export type Element = string;
69
+ export type ElementWithIndex = {
70
+ element: string;
71
+ index: number;
72
+ };
73
+ export type Key = string | ElementWithIndex;
74
+ export type Value = null | string | Key[] | {
75
+ element: string;
76
+ };
77
+ export type VariableKey = {
78
+ variable: string;
79
+ };
80
+ export type GeneralizedKey = Key | VariableKey | null;
81
+ export declare function isVariableKey(key: GeneralizedKey): key is VariableKey;
82
+ export type GeneralizedValue = null | string | GeneralizedKey[] | {
83
+ element: string;
84
+ };
85
+ export declare function isMerge(value: GeneralizedValue): value is {
86
+ element: string;
87
+ };
88
+ export type Mapping = Record<Element, Exclude<Value, null>>;
89
+ export interface ValueDescription {
90
+ value: GeneralizedValue;
91
+ score: number;
92
+ condition?: {
93
+ element: string;
94
+ op: "是" | "不是";
95
+ value: Value;
96
+ }[];
97
+ }
98
+ export type MappingSpace = Record<Element, ValueDescription[]>;
99
+ export interface EncoderConfig {
100
+ max_length: number;
101
+ select_keys?: string[];
102
+ auto_select_length?: number;
103
+ auto_select_pattern?: string;
104
+ sources: Record<string, Source>;
105
+ conditions: Record<string, Condition>;
106
+ rules?: WordRule[];
107
+ short_code?: ShortCodeRule[];
108
+ priority_short_codes?: [string, string, number][];
109
+ }
110
+ export interface Source {
111
+ object: CodableObject | null;
112
+ index?: number;
113
+ next: string | null;
114
+ }
115
+ export declare const binaryOps: readonly ["是", "不是", "匹配", "不匹配", "编码匹配", "编码不匹配"];
116
+ export declare const unaryOps: readonly ["存在", "不存在"];
117
+ export declare const ops: Op[];
118
+ export type UnaryOp = (typeof unaryOps)[number];
119
+ export type BinaryOp = (typeof binaryOps)[number];
120
+ export type Op = UnaryOp | BinaryOp;
121
+ export interface UnaryCondition {
122
+ object: CodableObject;
123
+ operator: UnaryOp;
124
+ positive: string | null;
125
+ negative: string | null;
126
+ }
127
+ export interface BinaryCondition {
128
+ object: CodableObject;
129
+ operator: BinaryOp;
130
+ value: string;
131
+ positive: string | null;
132
+ negative: string | null;
133
+ }
134
+ export type Condition = UnaryCondition | BinaryCondition;
135
+ type LengthSpecifier = {
136
+ length_equal: number;
137
+ } | {
138
+ length_in_range: [number, number];
139
+ };
140
+ export declare const wordLengthArray: {
141
+ label: number;
142
+ value: number;
143
+ }[];
144
+ export type WordRule = {
145
+ formula: string;
146
+ } & LengthSpecifier;
147
+ export type ShortCodeRule = {
148
+ schemes: ShortCodeScheme[];
149
+ } & LengthSpecifier;
150
+ export interface ShortCodeScheme {
151
+ prefix: number;
152
+ count?: number;
153
+ select_keys?: string[];
154
+ }
155
+ export interface LevelWeights {
156
+ length: number;
157
+ frequency: number;
158
+ }
159
+ export type FingeringWeights = (number | null)[];
160
+ export interface TierWeights {
161
+ top?: number;
162
+ duplication?: number;
163
+ levels?: LevelWeights[];
164
+ fingering?: FingeringWeights;
165
+ }
166
+ export declare const fingeringLabels: string[];
167
+ export interface PartialWeights {
168
+ tiers?: TierWeights[];
169
+ duplication?: number;
170
+ key_distribution?: number;
171
+ pair_equivalence?: number;
172
+ extended_pair_equivalence?: number;
173
+ fingering?: FingeringWeights;
174
+ levels?: LevelWeights[];
175
+ }
176
+ export interface Objective {
177
+ characters_full?: PartialWeights;
178
+ characters_short?: PartialWeights;
179
+ words_full?: PartialWeights;
180
+ words_short?: PartialWeights;
181
+ regularization_strength?: number;
182
+ }
183
+ export type PartialWeightTypes = Exclude<keyof Objective, "regularization">;
184
+ export interface Optimization {
185
+ objective: Objective;
186
+ metaheuristic: Solver;
187
+ }
188
+ export declare const defaultOptimization: Optimization;
189
+ export interface Solver {
190
+ algorithm: "SimulatedAnnealing";
191
+ parameters?: {
192
+ t_max: number;
193
+ t_min: number;
194
+ steps: number;
195
+ };
196
+ report_after?: number;
197
+ search_method?: {
198
+ random_move: number;
199
+ random_swap: number;
200
+ random_full_key_swap: number;
201
+ };
202
+ update_interval?: number;
203
+ }
204
+ export type BoxConfig = {
205
+ style?: string;
206
+ } & ({
207
+ type: "key" | "uppercase";
208
+ } | {
209
+ type: "element";
210
+ match?: string;
211
+ } | {
212
+ type: "custom";
213
+ mapping?: string;
214
+ });
215
+ export interface DiagramConfig {
216
+ layout: {
217
+ keys: string[];
218
+ }[];
219
+ contents: BoxConfig[];
220
+ row_style?: string;
221
+ cell_style?: string;
222
+ }
223
+ export interface Config {
224
+ version?: string;
225
+ source: string | null;
226
+ info?: Info;
227
+ data?: Data;
228
+ analysis?: Analysis;
229
+ algebra?: Algebra;
230
+ form: Keyboard;
231
+ encoder: EncoderConfig;
232
+ optimization?: Optimization;
233
+ diagram?: DiagramConfig;
234
+ }
235
+ export type ExampleConfig = Required<Config>;
236
+ export {};
package/dist/config.js ADDED
@@ -0,0 +1,48 @@
1
+ // config.info end
2
+ // config.data begin
3
+ export const characterSetSpecifiers = [
4
+ "minimal",
5
+ "gb2312",
6
+ "general",
7
+ "basic",
8
+ "extended",
9
+ "supplement",
10
+ "maximal",
11
+ "custom",
12
+ ];
13
+ export function isVariableKey(key) {
14
+ return typeof key === "object" && key !== null && "variable" in key;
15
+ }
16
+ export function isMerge(value) {
17
+ return typeof value === "object" && value !== null && "element" in value;
18
+ }
19
+ export const binaryOps = [
20
+ "是",
21
+ "不是",
22
+ "匹配",
23
+ "不匹配",
24
+ "编码匹配",
25
+ "编码不匹配",
26
+ ];
27
+ export const unaryOps = ["存在", "不存在"];
28
+ export const ops = unaryOps.concat(...binaryOps);
29
+ export const wordLengthArray = [...Array(9).keys()].map((x) => ({
30
+ label: x + 1,
31
+ value: x + 1,
32
+ }));
33
+ export const fingeringLabels = [
34
+ "同手",
35
+ "大跨",
36
+ "小跨",
37
+ "干扰",
38
+ "错手",
39
+ "三连",
40
+ "备用",
41
+ "备用",
42
+ ];
43
+ export const defaultOptimization = {
44
+ objective: {},
45
+ metaheuristic: {
46
+ algorithm: "SimulatedAnnealing",
47
+ },
48
+ };