glost 0.1.0 → 0.2.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.
- package/CHANGELOG.md +140 -0
- package/README.md +129 -15
- package/dist/example.d.ts +7 -7
- package/dist/example.js +68 -12
- package/dist/example.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/nodes.d.ts +119 -24
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +60 -55
- package/dist/nodes.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/dist/validators.d.ts +24 -24
- package/package.json +3 -7
- package/src/__tests__/README.md +20 -0
- package/src/__tests__/example.test.ts +43 -0
- package/src/{example.ts → __tests__/example.ts} +71 -71
- package/src/{mock-data.ts → __tests__/mock-data.ts} +117 -128
- package/src/index.ts +0 -1
- package/src/nodes.ts +144 -118
- package/src/types.ts +1 -1
- package/src/utils.ts +0 -1
- package/tsconfig.json +1 -1
- package/dist/mock-data.d.ts +0 -35
- package/dist/mock-data.d.ts.map +0 -1
- package/dist/mock-data.js +0 -494
- package/dist/mock-data.js.map +0 -1
package/src/nodes.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
LanguageCode,
|
|
3
|
-
LinguisticLevel,
|
|
4
3
|
LinguisticMetadata,
|
|
5
4
|
GLOSTExtras,
|
|
6
5
|
GLOSTParagraph,
|
|
@@ -15,22 +14,102 @@ import type {
|
|
|
15
14
|
TransliterationData,
|
|
16
15
|
} from "./types";
|
|
17
16
|
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Options Interfaces
|
|
19
|
+
// ============================================================================
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Options for creating a GLOST word node
|
|
23
|
+
*/
|
|
24
|
+
export interface CreateWordNodeOptions {
|
|
25
|
+
/** The text value of the word */
|
|
26
|
+
value: string;
|
|
27
|
+
/** Transcription data (IPA, romanization, etc.) */
|
|
28
|
+
transcription: TransliterationData;
|
|
29
|
+
/** Linguistic metadata (part of speech, etc.) */
|
|
30
|
+
metadata: LinguisticMetadata;
|
|
31
|
+
/** Language code (ISO-639-1, ISO-639-3, or BCP-47) */
|
|
32
|
+
lang?: LanguageCode;
|
|
33
|
+
/** Script system used */
|
|
34
|
+
script?: ScriptSystem;
|
|
35
|
+
/** Additional extension data */
|
|
36
|
+
extras?: GLOSTExtras;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Options for creating a GLOST sentence node
|
|
41
|
+
*/
|
|
42
|
+
export interface CreateSentenceNodeOptions {
|
|
43
|
+
/** The original text of the sentence */
|
|
44
|
+
originalText: string;
|
|
45
|
+
/** Language code */
|
|
46
|
+
lang: LanguageCode;
|
|
47
|
+
/** Script system used */
|
|
48
|
+
script: ScriptSystem;
|
|
49
|
+
/** Word nodes in the sentence */
|
|
50
|
+
children?: GLOSTWord[];
|
|
51
|
+
/** Optional transcription data */
|
|
52
|
+
transcription?: TransliterationData;
|
|
53
|
+
/** Additional extension data */
|
|
54
|
+
extras?: GLOSTExtras;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Options for creating a GLOST root node
|
|
59
|
+
*/
|
|
60
|
+
export interface CreateRootNodeOptions {
|
|
61
|
+
/** Language code */
|
|
62
|
+
lang: LanguageCode;
|
|
63
|
+
/** Script system used */
|
|
64
|
+
script: ScriptSystem;
|
|
65
|
+
/** Paragraph nodes */
|
|
66
|
+
children?: GLOSTParagraph[];
|
|
67
|
+
/** Document metadata */
|
|
68
|
+
metadata?: {
|
|
69
|
+
title?: string;
|
|
70
|
+
author?: string;
|
|
71
|
+
date?: string;
|
|
72
|
+
description?: string;
|
|
73
|
+
};
|
|
74
|
+
/** Additional extension data */
|
|
75
|
+
extras?: GLOSTExtras;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Options for creating a simple word node
|
|
80
|
+
*/
|
|
81
|
+
export interface CreateSimpleWordOptions {
|
|
82
|
+
/** The text value of the word */
|
|
83
|
+
text: string;
|
|
84
|
+
/** Transliteration text */
|
|
85
|
+
transliteration: string;
|
|
86
|
+
/** Transcription system (default: "ipa") */
|
|
87
|
+
system?: string;
|
|
88
|
+
/** Part of speech (default: "unknown") */
|
|
89
|
+
partOfSpeech?: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
18
93
|
// ============================================================================
|
|
19
94
|
// Node Factory Functions
|
|
20
95
|
// ============================================================================
|
|
21
96
|
|
|
22
97
|
/**
|
|
23
|
-
* Create
|
|
98
|
+
* Create a GLOST word node
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const word = createGLOSTWordNode({
|
|
103
|
+
* value: "hello",
|
|
104
|
+
* transcription: { ipa: { text: "həˈloʊ", system: "ipa" } },
|
|
105
|
+
* metadata: { partOfSpeech: "interjection" },
|
|
106
|
+
* lang: "en",
|
|
107
|
+
* script: "latin"
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
24
110
|
*/
|
|
25
|
-
export function createGLOSTWordNode(
|
|
26
|
-
value
|
|
27
|
-
transcription: TransliterationData,
|
|
28
|
-
metadata: LinguisticMetadata,
|
|
29
|
-
level: LinguisticLevel = "word",
|
|
30
|
-
lang?: LanguageCode,
|
|
31
|
-
script?: ScriptSystem,
|
|
32
|
-
extras?: GLOSTExtras,
|
|
33
|
-
): GLOSTWord {
|
|
111
|
+
export function createGLOSTWordNode(options: CreateWordNodeOptions): GLOSTWord {
|
|
112
|
+
const { value, transcription, metadata, lang, script, extras } = options;
|
|
34
113
|
return {
|
|
35
114
|
type: "WordNode",
|
|
36
115
|
lang,
|
|
@@ -43,16 +122,29 @@ export function createGLOSTWordNode(
|
|
|
43
122
|
}
|
|
44
123
|
|
|
45
124
|
/**
|
|
46
|
-
* Create
|
|
125
|
+
* Create a GLOST sentence node
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const sentence = createGLOSTSentenceNode({
|
|
130
|
+
* originalText: "Hello world",
|
|
131
|
+
* lang: "en",
|
|
132
|
+
* script: "latin",
|
|
133
|
+
* children: [wordNode1, wordNode2]
|
|
134
|
+
* });
|
|
135
|
+
* ```
|
|
47
136
|
*/
|
|
48
137
|
export function createGLOSTSentenceNode(
|
|
49
|
-
|
|
50
|
-
lang: LanguageCode,
|
|
51
|
-
script: ScriptSystem,
|
|
52
|
-
children: GLOSTWord[] = [],
|
|
53
|
-
transcription?: TransliterationData,
|
|
54
|
-
extras?: GLOSTExtras,
|
|
138
|
+
options: CreateSentenceNodeOptions,
|
|
55
139
|
): GLOSTSentence {
|
|
140
|
+
const {
|
|
141
|
+
originalText,
|
|
142
|
+
lang,
|
|
143
|
+
script,
|
|
144
|
+
children = [],
|
|
145
|
+
transcription,
|
|
146
|
+
extras,
|
|
147
|
+
} = options;
|
|
56
148
|
return {
|
|
57
149
|
type: "SentenceNode",
|
|
58
150
|
originalText,
|
|
@@ -65,7 +157,7 @@ export function createGLOSTSentenceNode(
|
|
|
65
157
|
}
|
|
66
158
|
|
|
67
159
|
/**
|
|
68
|
-
* Create
|
|
160
|
+
* Create a GLOST paragraph node
|
|
69
161
|
*/
|
|
70
162
|
export function createGLOSTParagraphNode(
|
|
71
163
|
children: GLOSTSentence[] = [],
|
|
@@ -73,7 +165,6 @@ export function createGLOSTParagraphNode(
|
|
|
73
165
|
): GLOSTParagraph {
|
|
74
166
|
return {
|
|
75
167
|
type: "ParagraphNode",
|
|
76
|
-
|
|
77
168
|
children,
|
|
78
169
|
position: undefined,
|
|
79
170
|
extras,
|
|
@@ -81,20 +172,20 @@ export function createGLOSTParagraphNode(
|
|
|
81
172
|
}
|
|
82
173
|
|
|
83
174
|
/**
|
|
84
|
-
* Create
|
|
175
|
+
* Create a GLOST root node
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const root = createGLOSTRootNode({
|
|
180
|
+
* lang: "en",
|
|
181
|
+
* script: "latin",
|
|
182
|
+
* children: [paragraphNode],
|
|
183
|
+
* metadata: { title: "My Document" }
|
|
184
|
+
* });
|
|
185
|
+
* ```
|
|
85
186
|
*/
|
|
86
|
-
export function createGLOSTRootNode(
|
|
87
|
-
lang
|
|
88
|
-
script: ScriptSystem,
|
|
89
|
-
children: GLOSTParagraph[] = [],
|
|
90
|
-
metadata?: {
|
|
91
|
-
title?: string;
|
|
92
|
-
author?: string;
|
|
93
|
-
date?: string;
|
|
94
|
-
description?: string;
|
|
95
|
-
},
|
|
96
|
-
extras?: GLOSTExtras,
|
|
97
|
-
): GLOSTRoot {
|
|
187
|
+
export function createGLOSTRootNode(options: CreateRootNodeOptions): GLOSTRoot {
|
|
188
|
+
const { lang, script, children = [], metadata, extras } = options;
|
|
98
189
|
return {
|
|
99
190
|
type: "RootNode",
|
|
100
191
|
lang,
|
|
@@ -112,14 +203,20 @@ export function createGLOSTRootNode(
|
|
|
112
203
|
|
|
113
204
|
/**
|
|
114
205
|
* Create a simple word node with basic transcription
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const word = createSimpleWord({
|
|
210
|
+
* text: "hello",
|
|
211
|
+
* transliteration: "həˈloʊ",
|
|
212
|
+
* system: "ipa",
|
|
213
|
+
* partOfSpeech: "interjection"
|
|
214
|
+
* });
|
|
215
|
+
* ```
|
|
115
216
|
*/
|
|
116
|
-
export function createSimpleWord(
|
|
117
|
-
text
|
|
118
|
-
|
|
119
|
-
system: string = "ipa",
|
|
120
|
-
partOfSpeech: string = "unknown",
|
|
121
|
-
level: LinguisticLevel = "word",
|
|
122
|
-
): GLOSTWord {
|
|
217
|
+
export function createSimpleWord(options: CreateSimpleWordOptions): GLOSTWord {
|
|
218
|
+
const { text, transliteration, system = "ipa", partOfSpeech = "unknown" } = options;
|
|
219
|
+
|
|
123
220
|
const transcription: TransliterationData = {
|
|
124
221
|
[system]: {
|
|
125
222
|
text: transliteration,
|
|
@@ -132,80 +229,9 @@ export function createSimpleWord(
|
|
|
132
229
|
partOfSpeech,
|
|
133
230
|
};
|
|
134
231
|
|
|
135
|
-
return createGLOSTWordNode(text, transcription, metadata
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Create a Thai word node with RTGS transcription
|
|
140
|
-
*/
|
|
141
|
-
export function createThaiWord(
|
|
142
|
-
text: string,
|
|
143
|
-
rtgs: string,
|
|
144
|
-
partOfSpeech: string = "unknown",
|
|
145
|
-
tone?: number,
|
|
146
|
-
syllables?: string[],
|
|
147
|
-
): GLOSTWord {
|
|
148
|
-
const transcription: TransliterationData = {
|
|
149
|
-
rtgs: {
|
|
150
|
-
text: rtgs,
|
|
151
|
-
system: "rtgs",
|
|
152
|
-
tone,
|
|
153
|
-
syllables: syllables || [text],
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const metadata: LinguisticMetadata = {
|
|
158
|
-
partOfSpeech,
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
return createGLOSTWordNode(
|
|
162
|
-
text,
|
|
163
|
-
transcription,
|
|
164
|
-
metadata,
|
|
165
|
-
"word",
|
|
166
|
-
"th",
|
|
167
|
-
"thai",
|
|
168
|
-
);
|
|
232
|
+
return createGLOSTWordNode({ value: text, transcription, metadata });
|
|
169
233
|
}
|
|
170
234
|
|
|
171
|
-
/**
|
|
172
|
-
* Create a Japanese word node with romaji transcription
|
|
173
|
-
*/
|
|
174
|
-
export function createJapaneseWord(
|
|
175
|
-
text: string,
|
|
176
|
-
romaji: string,
|
|
177
|
-
partOfSpeech: string = "unknown",
|
|
178
|
-
furigana?: string,
|
|
179
|
-
): GLOSTWord {
|
|
180
|
-
const transcription: TransliterationData = {
|
|
181
|
-
romaji: {
|
|
182
|
-
text: romaji,
|
|
183
|
-
system: "romaji",
|
|
184
|
-
syllables: [text],
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
if (furigana) {
|
|
189
|
-
transcription.furigana = {
|
|
190
|
-
text: furigana,
|
|
191
|
-
system: "furigana",
|
|
192
|
-
syllables: [text],
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const metadata: LinguisticMetadata = {
|
|
197
|
-
partOfSpeech,
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
return createGLOSTWordNode(
|
|
201
|
-
text,
|
|
202
|
-
transcription,
|
|
203
|
-
metadata,
|
|
204
|
-
"word",
|
|
205
|
-
"ja",
|
|
206
|
-
"mixed",
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
235
|
|
|
210
236
|
/**
|
|
211
237
|
* Create a sentence from an array of words
|
|
@@ -227,7 +253,7 @@ export function createSentenceFromWords(
|
|
|
227
253
|
return textNode ? textNode.value : "";
|
|
228
254
|
})
|
|
229
255
|
.join("");
|
|
230
|
-
return createGLOSTSentenceNode(text, lang, script, words);
|
|
256
|
+
return createGLOSTSentenceNode({ originalText: text, lang, script, children: words });
|
|
231
257
|
}
|
|
232
258
|
|
|
233
259
|
/**
|
|
@@ -253,7 +279,7 @@ export function createDocumentFromParagraphs(
|
|
|
253
279
|
description?: string;
|
|
254
280
|
},
|
|
255
281
|
): GLOSTRoot {
|
|
256
|
-
return createGLOSTRootNode(lang, script, paragraphs, metadata);
|
|
282
|
+
return createGLOSTRootNode({ lang, script, children: paragraphs, metadata });
|
|
257
283
|
}
|
|
258
284
|
|
|
259
285
|
// ============================================================================
|
|
@@ -261,7 +287,7 @@ export function createDocumentFromParagraphs(
|
|
|
261
287
|
// ============================================================================
|
|
262
288
|
|
|
263
289
|
/**
|
|
264
|
-
* Create
|
|
290
|
+
* Create a GLOST punctuation node
|
|
265
291
|
*/
|
|
266
292
|
export function createGLOSTPunctuationNode(value: string): GLOSTPunctuation {
|
|
267
293
|
return {
|
|
@@ -271,7 +297,7 @@ export function createGLOSTPunctuationNode(value: string): GLOSTPunctuation {
|
|
|
271
297
|
}
|
|
272
298
|
|
|
273
299
|
/**
|
|
274
|
-
* Create
|
|
300
|
+
* Create a GLOST whitespace node
|
|
275
301
|
*/
|
|
276
302
|
export function createGLOSTWhiteSpaceNode(value: string): GLOSTWhiteSpace {
|
|
277
303
|
return {
|
|
@@ -281,7 +307,7 @@ export function createGLOSTWhiteSpaceNode(value: string): GLOSTWhiteSpace {
|
|
|
281
307
|
}
|
|
282
308
|
|
|
283
309
|
/**
|
|
284
|
-
* Create
|
|
310
|
+
* Create a GLOST symbol node
|
|
285
311
|
*/
|
|
286
312
|
export function createGLOSTSymbolNode(value: string): GLOSTSymbol {
|
|
287
313
|
return {
|
|
@@ -291,7 +317,7 @@ export function createGLOSTSymbolNode(value: string): GLOSTSymbol {
|
|
|
291
317
|
}
|
|
292
318
|
|
|
293
319
|
/**
|
|
294
|
-
* Create
|
|
320
|
+
* Create a GLOST text node
|
|
295
321
|
*/
|
|
296
322
|
export function createGLOSTTextNode(value: string): GLOSTText {
|
|
297
323
|
return {
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Literal as NlcstLiteral,
|
|
1
|
+
import type { Literal as NlcstLiteral, Paragraph as NlcstParagraph, Punctuation as NlcstPunctuation, Root as NlcstRoot, Sentence as NlcstSentence, Source as NlcstSource, Symbol as NlcstSymbol, Text as NlcstText, WhiteSpace as NlcstWhiteSpace, Word as NlcstWord } from "nlcst";
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
package/src/utils.ts
CHANGED
package/tsconfig.json
CHANGED
package/dist/mock-data.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { GLOSTWord } from './types';
|
|
2
|
-
declare const thaiWordsWithExtras: GLOSTWord[];
|
|
3
|
-
declare const japaneseWordsWithExtras: GLOSTWord[];
|
|
4
|
-
declare const thaiSentenceWithExtras: import("./types").GLOSTSentence;
|
|
5
|
-
declare const japaneseSentenceWithExtras: import("./types").GLOSTSentence;
|
|
6
|
-
declare const thaiParagraphWithExtras: import("./types").GLOSTParagraph;
|
|
7
|
-
declare const japaneseParagraphWithExtras: import("./types").GLOSTParagraph;
|
|
8
|
-
export declare const thaiDocumentWithExtras: import("./types").GLOSTRoot;
|
|
9
|
-
export declare const japaneseDocumentWithExtras: import("./types").GLOSTRoot;
|
|
10
|
-
/**
|
|
11
|
-
* Get quick translation for a word in a specific language
|
|
12
|
-
*/
|
|
13
|
-
export declare function getQuickTranslation(word: GLOSTWord, targetLang: string): string | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* Get all available translations for a word
|
|
16
|
-
*/
|
|
17
|
-
export declare function getAllTranslations(word: GLOSTWord): Record<string, string>;
|
|
18
|
-
/**
|
|
19
|
-
* Get difficulty level for a word
|
|
20
|
-
*/
|
|
21
|
-
export declare function getDifficulty(word: GLOSTWord): string | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* Get cultural notes for a word
|
|
24
|
-
*/
|
|
25
|
-
export declare function getCulturalNotes(word: GLOSTWord): string | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* Get related words for a word
|
|
28
|
-
*/
|
|
29
|
-
export declare function getRelatedWords(word: GLOSTWord): string[];
|
|
30
|
-
/**
|
|
31
|
-
* Get example sentences for a word
|
|
32
|
-
*/
|
|
33
|
-
export declare function getExamples(word: GLOSTWord): string[];
|
|
34
|
-
export { thaiWordsWithExtras, japaneseWordsWithExtras, thaiSentenceWithExtras, japaneseSentenceWithExtras, thaiParagraphWithExtras, japaneseParagraphWithExtras };
|
|
35
|
-
//# sourceMappingURL=mock-data.d.ts.map
|
package/dist/mock-data.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mock-data.d.ts","sourceRoot":"","sources":["../src/mock-data.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,SAAS,EAAC,MAAM,SAAS,CAAC;AAM5B,QAAA,MAAM,mBAAmB,EAAE,SAAS,EAsPnC,CAAC;AAMF,QAAA,MAAM,uBAAuB,EAAE,SAAS,EAmQvC,CAAC;AAMF,QAAA,MAAM,sBAAsB,iCAK3B,CAAC;AAEF,QAAA,MAAM,0BAA0B,iCAK/B,CAAC;AAEF,QAAA,MAAM,uBAAuB,kCAAsD,CAAC;AACpF,QAAA,MAAM,2BAA2B,kCAA0D,CAAC;AAE5F,eAAO,MAAM,sBAAsB,6BAQlC,CAAC;AAEF,eAAO,MAAM,0BAA0B,6BAQtC,CAAC;AAMF;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE3F;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAW1E;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAEjE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAEpE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,EAAE,CAEzD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,EAAE,CAErD;AAMD,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,EACvB,2BAA2B,EAC5B,CAAC"}
|