aboutsummaryrefslogtreecommitdiff
path: root/types/ext/dictionary-data.d.ts
blob: 68752bbb2e7a46c0b96b4d0f5c65dffecbff9ba4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 * Copyright (C) 2023-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/>.
 */

import type * as StructuredContent from './structured-content';

export type IndexVersion = 1 | 2 | 3;

export type Index = {
    format?: IndexVersion;
    version?: IndexVersion;
    title: string;
    revision: string;
    sequenced?: boolean;
    author?: string;
    url?: string;
    description?: string;
    attribution?: string;
    sourceLanguage?: string;
    targetLanguage?: string;
    frequencyMode?: 'occurrence-based' | 'rank-based';
    tagMeta?: IndexTagMeta;
};

export type IndexTagMeta = {
    [name: string]: IndexTag;
};

export type IndexTag = {
    category: string;
    order: number;
    notes: string;
    score: number;
};

export type TermV1Array = TermV1[];

export type TermV1 = [
    expression: string,
    reading: string,
    definitionTags: string | null,
    rules: string,
    score: number,
    ...glossary: string[],
];

export type TermV3Array = TermV3[];

export type TermV3 = [
    expression: string,
    reading: string,
    definitionTags: string | null,
    rules: string,
    score: number,
    glossary: TermGlossary[],
    sequence: number,
    termTags: string,
];

export type KanjiV1Array = KanjiV1[];

export type KanjiV1 = [
    character: string,
    onyomi: string,
    kunyomi: string,
    tags: string,
    ...meanings: string[],
];

export type KanjiV3Array = KanjiV3[];

export type KanjiV3 = [
    character: string,
    onyomi: string,
    kunyomi: string,
    tags: string,
    meanings: string[],
    stats: {[name: string]: string},
];

export type TermGlossary = (
    TermGlossaryContent |
    TermGlossaryDeinflection
);

export type TermGlossaryContent = (
    TermGlossaryString |
    TermGlossaryText |
    TermGlossaryImage |
    TermGlossaryStructuredContent
);

export type TermGlossaryString = string;

export type TermGlossaryText = {type: 'text', text: string};

export type TermGlossaryImage = {type: 'image'} & TermImage;

export type TermGlossaryStructuredContent = {type: 'structured-content', content: StructuredContent.Content};

export type TermGlossaryDeinflection = [
    uninflected: string,
    inflectionRuleChain: string[],
];

export type TermImage = StructuredContent.ImageElementBase & {
    // Compatibility properties
    verticalAlign?: undefined;
    border?: undefined;
    borderRadius?: undefined;
    sizeUnits?: undefined;
};

export type TagArray = Tag[];

export type Tag = [
    name: string,
    category: string,
    order: number,
    notes: string,
    score: number,
];

export type GenericFrequencyData = string | number | {
    value: number;
    displayValue?: string;
    reading?: undefined; // Used for type disambiguation, field does not actually exist
};

export type TermMetaArray = TermMeta[];

export type TermMeta = TermMetaFrequency | TermMetaPitch | TermMetaPhonetic;

export type TermMetaFrequencyDataWithReading = {
    reading: string;
    frequency: GenericFrequencyData;
};

export type TermMetaFrequency = [
    expression: string,
    mode: 'freq',
    data: GenericFrequencyData | TermMetaFrequencyDataWithReading,
];

export type TermMetaPitchData = {
    reading: string;
    pitches: {
        position: number;
        nasal?: number | number[];
        devoice?: number | number[];
        tags?: string[];
    }[];
};

export type TermMetaPitch = [
    expression: string,
    mode: 'pitch',
    data: TermMetaPitchData,
];

export type TermMetaPhonetic = [
    expression: string,
    mode: 'ipa',
    data: TermMetaPhoneticData,
];

export type TermMetaPhoneticData = {
    reading: string;
    transcriptions: {
        ipa: string;
        tags?: string[];
    }[];
};

export type KanjiMetaArray = KanjiMeta[];

export type KanjiMeta = KanjiMetaFrequency;

export type KanjiMetaFrequency = [
    character: string,
    mode: 'freq',
    data: GenericFrequencyData,
];