glost-core 0.5.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 +63 -0
- package/LICENSE +21 -0
- package/README.md +199 -0
- package/dist/__benchmarks__/document-creation.bench.d.ts +7 -0
- package/dist/__benchmarks__/document-creation.bench.d.ts.map +1 -0
- package/dist/__benchmarks__/document-creation.bench.js +71 -0
- package/dist/__benchmarks__/document-creation.bench.js.map +1 -0
- package/dist/__benchmarks__/traversal.bench.d.ts +7 -0
- package/dist/__benchmarks__/traversal.bench.d.ts.map +1 -0
- package/dist/__benchmarks__/traversal.bench.js +124 -0
- package/dist/__benchmarks__/traversal.bench.js.map +1 -0
- package/dist/cli/migrate.d.ts +8 -0
- package/dist/cli/migrate.d.ts.map +1 -0
- package/dist/cli/migrate.js +229 -0
- package/dist/cli/migrate.js.map +1 -0
- package/dist/errors.d.ts +168 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +300 -0
- package/dist/errors.js.map +1 -0
- package/dist/guards.d.ts +103 -0
- package/dist/guards.d.ts.map +1 -0
- package/dist/guards.js +264 -0
- package/dist/guards.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/nodes.d.ts +227 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +243 -0
- package/dist/nodes.js.map +1 -0
- package/dist/types.d.ts +442 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +51 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +247 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +564 -0
- package/dist/utils.js.map +1 -0
- package/dist/validators.d.ts +1876 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +302 -0
- package/dist/validators.js.map +1 -0
- package/package.json +73 -0
- package/src/__benchmarks__/document-creation.bench.ts +92 -0
- package/src/__benchmarks__/traversal.bench.ts +152 -0
- package/src/__tests__/README.md +20 -0
- package/src/__tests__/example.test.ts +43 -0
- package/src/__tests__/example.ts +186 -0
- package/src/__tests__/helpers.test.ts +178 -0
- package/src/__tests__/mock-data.ts +624 -0
- package/src/__tests__/performance.test.ts +317 -0
- package/src/__tests__/traversal.test.ts +170 -0
- package/src/cli/migrate.ts +294 -0
- package/src/errors.ts +394 -0
- package/src/guards.ts +341 -0
- package/src/index.ts +69 -0
- package/src/nodes.ts +409 -0
- package/src/types.ts +633 -0
- package/src/utils.ts +730 -0
- package/src/validators.ts +336 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,oDAAoD;AACpD,+EAA+E;AAe/E,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,IAAa;IACvC,OAAO,CACL,OAAO,IAAI,KAAK,QAAQ;QACxB,IAAI,KAAK,IAAI;QACb,MAAM,IAAI,IAAI;QACd,IAAI,CAAC,IAAI,KAAK,UAAU;QACxB,UAAU,IAAI,IAAI;QAClB,MAAM,IAAI,IAAI;QACd,QAAQ,IAAI,IAAI;QAChB,OAAO,IAAI,IAAI;QACf,UAAU,IAAI,IAAI;QAClB,eAAe,IAAI,IAAI;QACvB,QAAQ,IAAI,IAAI,CACjB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,IAAa;IAC3C,OAAO,CACL,OAAO,IAAI,KAAK,QAAQ;QACxB,IAAI,KAAK,IAAI;QACb,MAAM,IAAI,IAAI;QACd,IAAI,CAAC,IAAI,KAAK,cAAc;QAC5B,UAAU,IAAI,IAAI;QAClB,MAAM,IAAI,IAAI;QACd,QAAQ,IAAI,IAAI;QAChB,OAAO,IAAI,IAAI;QACf,UAAU,IAAI,IAAI,C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,CAAC;QACnB,iBAAiB,CAAC,IAAI,CAAC;QACvB,aAAa,CAAC,IAAI,CAAC,CACpB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,IAAe;IAC7C,OAAO,CACL,WAAW,CAAC,IAAI,CAAC;QACjB,eAAe,CAAC,IAAI,CAAC;QACrB,gBAAgB,CAAC,IAAI,CAAC;QACtB,WAAW,CAAC,IAAI,CAAC,CAClB,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./nodes.js";
|
|
3
|
+
export * from "./utils.js";
|
|
4
|
+
export * from "./validators.js";
|
|
5
|
+
export * from "./guards.js";
|
|
6
|
+
export * from "./errors.js";
|
|
7
|
+
export type { ParagraphLike } from "./utils.js";
|
|
8
|
+
export { getAllWords, getAllSentences, getAllParagraphs, getAllClauses, getAllPhrases, getAllSyllables, getAllCharacters, getWordsFromDocument, getFirstSentence, getWordsFromSentence, getWordsFromParagraph, findNodesByType, findWordsByLanguage, findWordsByTranscriptionSystem, isGLOSTWord, isGLOSTSentence, isGLOSTParagraph, isGLOSTRoot, isGLOSTClause, isGLOSTPhrase, isGLOSTSyllable, isGLOSTCharacter, getWordText, getWordTranscription, hasWordTranscription, getWordTranslation, getWordMeaning, getWordPartOfSpeech, getWordDifficulty, getSentenceTranslation, getGLOSTWordCount, adaptParagraphLikeToGLOST, parseLanguageTag, getBaseLanguage, areLanguagesCompatible, findBestLanguageMatch, getLanguageFallback, normalizeLanguageTag, isValidLanguageTag, } from "./utils.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAI5B,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,OAAO,EAEL,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EAGrB,eAAe,EACf,mBAAmB,EACnB,8BAA8B,EAG9B,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,EACf,gBAAgB,EAGhB,WAAW,EACX,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EAGjB,sBAAsB,EAGtB,iBAAiB,EACjB,yBAAyB,EAGzB,gBAAgB,EAChB,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// GLOST - Glossed Syntax Tree
|
|
2
|
+
// Extends nlcst for language learning with annotations
|
|
3
|
+
export * from "./types.js";
|
|
4
|
+
export * from "./nodes.js";
|
|
5
|
+
export * from "./utils.js";
|
|
6
|
+
export * from "./validators.js";
|
|
7
|
+
export * from "./guards.js";
|
|
8
|
+
export * from "./errors.js";
|
|
9
|
+
// Re-export key utilities for transcription components
|
|
10
|
+
export {
|
|
11
|
+
// Tree traversal
|
|
12
|
+
getAllWords, getAllSentences, getAllParagraphs, getAllClauses, getAllPhrases, getAllSyllables, getAllCharacters, getWordsFromDocument, getFirstSentence, getWordsFromSentence, getWordsFromParagraph,
|
|
13
|
+
// Node finding
|
|
14
|
+
findNodesByType, findWordsByLanguage, findWordsByTranscriptionSystem,
|
|
15
|
+
// Type guards (most are now exported via guards.ts)
|
|
16
|
+
isGLOSTWord, isGLOSTSentence, isGLOSTParagraph, isGLOSTRoot, isGLOSTClause, isGLOSTPhrase, isGLOSTSyllable, isGLOSTCharacter,
|
|
17
|
+
// Word utilities
|
|
18
|
+
getWordText, getWordTranscription, hasWordTranscription, getWordTranslation, getWordMeaning, getWordPartOfSpeech, getWordDifficulty,
|
|
19
|
+
// Sentence utilities
|
|
20
|
+
getSentenceTranslation,
|
|
21
|
+
// Content statistics utilities
|
|
22
|
+
getGLOSTWordCount, adaptParagraphLikeToGLOST,
|
|
23
|
+
// BCP-47 Language utilities
|
|
24
|
+
parseLanguageTag, getBaseLanguage, areLanguagesCompatible, findBestLanguageMatch, getLanguageFallback, normalizeLanguageTag, isValidLanguageTag, } from "./utils.js";
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,uDAAuD;AAEvD,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAM5B,uDAAuD;AACvD,OAAO;AACL,iBAAiB;AACjB,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB;AAErB,eAAe;AACf,eAAe,EACf,mBAAmB,EACnB,8BAA8B;AAE9B,oDAAoD;AACpD,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,EACf,gBAAgB;AAEhB,iBAAiB;AACjB,WAAW,EACX,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,iBAAiB;AAEjB,qBAAqB;AACrB,sBAAsB;AAEtB,+BAA+B;AAC/B,iBAAiB,EACjB,yBAAyB;AAEzB,4BAA4B;AAC5B,gBAAgB,EAChB,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
|
package/dist/nodes.d.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import type { LanguageCode, LinguisticMetadata, GLOSTExtras, GLOSTParagraph, GLOSTPunctuation, GLOSTRoot, GLOSTSentence, GLOSTSymbol, GLOSTText, GLOSTWhiteSpace, GLOSTWord, ScriptSystem, TransliterationData } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for creating a GLOST word node
|
|
4
|
+
*/
|
|
5
|
+
export interface CreateWordNodeOptions {
|
|
6
|
+
/** The text value of the word */
|
|
7
|
+
value: string;
|
|
8
|
+
/** Transcription data (IPA, romanization, etc.) - optional */
|
|
9
|
+
transcription?: TransliterationData;
|
|
10
|
+
/** Linguistic metadata (part of speech, etc.) - optional */
|
|
11
|
+
metadata?: LinguisticMetadata;
|
|
12
|
+
/** Language code (ISO-639-1, ISO-639-3, or BCP-47) */
|
|
13
|
+
lang?: LanguageCode;
|
|
14
|
+
/** Script system used */
|
|
15
|
+
script?: ScriptSystem;
|
|
16
|
+
/** Additional extension data */
|
|
17
|
+
extras?: GLOSTExtras;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Options for creating a GLOST sentence node
|
|
21
|
+
*/
|
|
22
|
+
export interface CreateSentenceNodeOptions {
|
|
23
|
+
/** The original text of the sentence */
|
|
24
|
+
originalText: string;
|
|
25
|
+
/** Language code */
|
|
26
|
+
lang: LanguageCode;
|
|
27
|
+
/** Script system used */
|
|
28
|
+
script: ScriptSystem;
|
|
29
|
+
/** Word nodes in the sentence */
|
|
30
|
+
children?: GLOSTWord[];
|
|
31
|
+
/** Optional transcription data */
|
|
32
|
+
transcription?: TransliterationData;
|
|
33
|
+
/** Additional extension data */
|
|
34
|
+
extras?: GLOSTExtras;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Options for creating a GLOST root node
|
|
38
|
+
*/
|
|
39
|
+
export interface CreateRootNodeOptions {
|
|
40
|
+
/** Language code */
|
|
41
|
+
lang: LanguageCode;
|
|
42
|
+
/** Script system used */
|
|
43
|
+
script: ScriptSystem;
|
|
44
|
+
/** Paragraph nodes */
|
|
45
|
+
children?: GLOSTParagraph[];
|
|
46
|
+
/** Document metadata */
|
|
47
|
+
metadata?: {
|
|
48
|
+
title?: string;
|
|
49
|
+
author?: string;
|
|
50
|
+
date?: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
};
|
|
53
|
+
/** Additional extension data */
|
|
54
|
+
extras?: GLOSTExtras;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Options for creating a simple word node
|
|
58
|
+
*/
|
|
59
|
+
export interface CreateSimpleWordOptions {
|
|
60
|
+
/** The text value of the word */
|
|
61
|
+
text: string;
|
|
62
|
+
/** Transliteration text */
|
|
63
|
+
transliteration: string;
|
|
64
|
+
/** Transcription system (default: "ipa") */
|
|
65
|
+
system?: string;
|
|
66
|
+
/** Part of speech (default: "unknown") */
|
|
67
|
+
partOfSpeech?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create a GLOST word node
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const word = createGLOSTWordNode({
|
|
75
|
+
* value: "hello",
|
|
76
|
+
* transcription: { ipa: { text: "həˈloʊ", system: "ipa" } },
|
|
77
|
+
* metadata: { partOfSpeech: "interjection" },
|
|
78
|
+
* lang: "en",
|
|
79
|
+
* script: "latin"
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function createGLOSTWordNode(options: CreateWordNodeOptions): GLOSTWord;
|
|
84
|
+
/**
|
|
85
|
+
* Create a GLOST sentence node
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const sentence = createGLOSTSentenceNode({
|
|
90
|
+
* originalText: "Hello world",
|
|
91
|
+
* lang: "en",
|
|
92
|
+
* script: "latin",
|
|
93
|
+
* children: [wordNode1, wordNode2]
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function createGLOSTSentenceNode(options: CreateSentenceNodeOptions): GLOSTSentence;
|
|
98
|
+
/**
|
|
99
|
+
* Create a GLOST paragraph node
|
|
100
|
+
*/
|
|
101
|
+
export declare function createGLOSTParagraphNode(children?: GLOSTSentence[], extras?: GLOSTExtras): GLOSTParagraph;
|
|
102
|
+
/**
|
|
103
|
+
* Create a GLOST root node
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const root = createGLOSTRootNode({
|
|
108
|
+
* lang: "en",
|
|
109
|
+
* script: "latin",
|
|
110
|
+
* children: [paragraphNode],
|
|
111
|
+
* metadata: { title: "My Document" }
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare function createGLOSTRootNode(options: CreateRootNodeOptions): GLOSTRoot;
|
|
116
|
+
/**
|
|
117
|
+
* Create a simple word node with basic transcription
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const word = createSimpleWord({
|
|
122
|
+
* text: "hello",
|
|
123
|
+
* transliteration: "həˈloʊ",
|
|
124
|
+
* system: "ipa",
|
|
125
|
+
* partOfSpeech: "interjection"
|
|
126
|
+
* });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare function createSimpleWord(options: CreateSimpleWordOptions): GLOSTWord;
|
|
130
|
+
/**
|
|
131
|
+
* Create a sentence from an array of words
|
|
132
|
+
*/
|
|
133
|
+
export declare function createSentenceFromWords(words: GLOSTWord[], lang: LanguageCode, script: ScriptSystem, originalText?: string): GLOSTSentence;
|
|
134
|
+
/**
|
|
135
|
+
* Create a paragraph from an array of sentences
|
|
136
|
+
*/
|
|
137
|
+
export declare function createParagraphFromSentences(sentences: GLOSTSentence[]): GLOSTParagraph;
|
|
138
|
+
/**
|
|
139
|
+
* Create a document from an array of paragraphs
|
|
140
|
+
*/
|
|
141
|
+
export declare function createDocumentFromParagraphs(paragraphs: GLOSTParagraph[], lang: LanguageCode, script: ScriptSystem, metadata?: {
|
|
142
|
+
title?: string;
|
|
143
|
+
author?: string;
|
|
144
|
+
date?: string;
|
|
145
|
+
description?: string;
|
|
146
|
+
}): GLOSTRoot;
|
|
147
|
+
/**
|
|
148
|
+
* Create a document from an array of sentences (simplified helper)
|
|
149
|
+
*
|
|
150
|
+
* Automatically wraps sentences in a paragraph for convenience.
|
|
151
|
+
* Useful when you don't need explicit paragraph structure.
|
|
152
|
+
*
|
|
153
|
+
* @param sentences - Array of sentences
|
|
154
|
+
* @param lang - Language code
|
|
155
|
+
* @param script - Script system (optional, will be inferred from lang if not provided)
|
|
156
|
+
* @param metadata - Optional document metadata
|
|
157
|
+
* @returns GLOST root document
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const sentences = [
|
|
162
|
+
* createSentenceFromWords([word1, word2], "th", "thai", "สวัสดี"),
|
|
163
|
+
* createSentenceFromWords([word3, word4], "th", "thai", "ขอบคุณ")
|
|
164
|
+
* ];
|
|
165
|
+
* const doc = createDocumentFromSentences(sentences, "th", "thai");
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export declare function createDocumentFromSentences(sentences: GLOSTSentence[], lang: LanguageCode, script: ScriptSystem, metadata?: {
|
|
169
|
+
title?: string;
|
|
170
|
+
author?: string;
|
|
171
|
+
date?: string;
|
|
172
|
+
description?: string;
|
|
173
|
+
}): GLOSTRoot;
|
|
174
|
+
/**
|
|
175
|
+
* Create a simple document from an array of words (simplified helper)
|
|
176
|
+
*
|
|
177
|
+
* Automatically creates sentence and paragraph wrappers for maximum convenience.
|
|
178
|
+
* Perfect for testing, quick prototypes, and simple use cases.
|
|
179
|
+
*
|
|
180
|
+
* @param words - Array of word nodes
|
|
181
|
+
* @param lang - Language code
|
|
182
|
+
* @param script - Script system (optional, will be inferred from lang if not provided)
|
|
183
|
+
* @param options - Optional configuration
|
|
184
|
+
* @param options.sentenceText - Original text of the sentence (will be auto-generated if not provided)
|
|
185
|
+
* @param options.metadata - Optional document metadata
|
|
186
|
+
* @returns GLOST root document
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* import { createSimpleDocument } from "glost";
|
|
191
|
+
* import { createThaiWord } from "glost-th";
|
|
192
|
+
*
|
|
193
|
+
* const words = [
|
|
194
|
+
* createThaiWord({ text: "สวัสดี" }),
|
|
195
|
+
* createThaiWord({ text: "ครับ" })
|
|
196
|
+
* ];
|
|
197
|
+
* const doc = createSimpleDocument(words, "th", "thai", {
|
|
198
|
+
* sentenceText: "สวัสดีครับ"
|
|
199
|
+
* });
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
export declare function createSimpleDocument(words: GLOSTWord[], lang: LanguageCode, script: ScriptSystem, options?: {
|
|
203
|
+
sentenceText?: string;
|
|
204
|
+
metadata?: {
|
|
205
|
+
title?: string;
|
|
206
|
+
author?: string;
|
|
207
|
+
date?: string;
|
|
208
|
+
description?: string;
|
|
209
|
+
};
|
|
210
|
+
}): GLOSTRoot;
|
|
211
|
+
/**
|
|
212
|
+
* Create a GLOST punctuation node
|
|
213
|
+
*/
|
|
214
|
+
export declare function createGLOSTPunctuationNode(value: string): GLOSTPunctuation;
|
|
215
|
+
/**
|
|
216
|
+
* Create a GLOST whitespace node
|
|
217
|
+
*/
|
|
218
|
+
export declare function createGLOSTWhiteSpaceNode(value: string): GLOSTWhiteSpace;
|
|
219
|
+
/**
|
|
220
|
+
* Create a GLOST symbol node
|
|
221
|
+
*/
|
|
222
|
+
export declare function createGLOSTSymbolNode(value: string): GLOSTSymbol;
|
|
223
|
+
/**
|
|
224
|
+
* Create a GLOST text node
|
|
225
|
+
*/
|
|
226
|
+
export declare function createGLOSTTextNode(value: string): GLOSTText;
|
|
227
|
+
//# sourceMappingURL=nodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,WAAW,EACX,SAAS,EACT,eAAe,EACf,SAAS,EACT,YAAY,EACZ,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAMpB;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,8DAA8D;IAC9D,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,sDAAsD;IACtD,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,yBAAyB;IACzB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,gCAAgC;IAChC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB;IACpB,IAAI,EAAE,YAAY,CAAC;IACnB,yBAAyB;IACzB,MAAM,EAAE,YAAY,CAAC;IACrB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAC;IACvB,kCAAkC;IAClC,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC,gCAAgC;IAChC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,oBAAoB;IACpB,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AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,CAKxE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAKhE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAK5D"}
|
package/dist/nodes.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Node Factory Functions
|
|
3
|
+
// ============================================================================
|
|
4
|
+
/**
|
|
5
|
+
* Create a GLOST word node
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const word = createGLOSTWordNode({
|
|
10
|
+
* value: "hello",
|
|
11
|
+
* transcription: { ipa: { text: "həˈloʊ", system: "ipa" } },
|
|
12
|
+
* metadata: { partOfSpeech: "interjection" },
|
|
13
|
+
* lang: "en",
|
|
14
|
+
* script: "latin"
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function createGLOSTWordNode(options) {
|
|
19
|
+
const { value, transcription, metadata, lang, script, extras } = options;
|
|
20
|
+
return {
|
|
21
|
+
type: "WordNode",
|
|
22
|
+
lang,
|
|
23
|
+
script,
|
|
24
|
+
transcription,
|
|
25
|
+
metadata,
|
|
26
|
+
extras,
|
|
27
|
+
children: [createGLOSTTextNode(value)],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a GLOST sentence node
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const sentence = createGLOSTSentenceNode({
|
|
36
|
+
* originalText: "Hello world",
|
|
37
|
+
* lang: "en",
|
|
38
|
+
* script: "latin",
|
|
39
|
+
* children: [wordNode1, wordNode2]
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function createGLOSTSentenceNode(options) {
|
|
44
|
+
const { originalText, lang, script, children = [], transcription, extras, } = options;
|
|
45
|
+
return {
|
|
46
|
+
type: "SentenceNode",
|
|
47
|
+
originalText,
|
|
48
|
+
lang,
|
|
49
|
+
script,
|
|
50
|
+
transcription,
|
|
51
|
+
children,
|
|
52
|
+
extras,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create a GLOST paragraph node
|
|
57
|
+
*/
|
|
58
|
+
export function createGLOSTParagraphNode(children = [], extras) {
|
|
59
|
+
return {
|
|
60
|
+
type: "ParagraphNode",
|
|
61
|
+
children,
|
|
62
|
+
position: undefined,
|
|
63
|
+
extras,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a GLOST root node
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const root = createGLOSTRootNode({
|
|
72
|
+
* lang: "en",
|
|
73
|
+
* script: "latin",
|
|
74
|
+
* children: [paragraphNode],
|
|
75
|
+
* metadata: { title: "My Document" }
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export function createGLOSTRootNode(options) {
|
|
80
|
+
const { lang, script, children = [], metadata, extras } = options;
|
|
81
|
+
return {
|
|
82
|
+
type: "RootNode",
|
|
83
|
+
lang,
|
|
84
|
+
script,
|
|
85
|
+
metadata,
|
|
86
|
+
children,
|
|
87
|
+
position: undefined,
|
|
88
|
+
extras,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// ============================================================================
|
|
92
|
+
// Helper Functions for Common Patterns
|
|
93
|
+
// ============================================================================
|
|
94
|
+
/**
|
|
95
|
+
* Create a simple word node with basic transcription
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const word = createSimpleWord({
|
|
100
|
+
* text: "hello",
|
|
101
|
+
* transliteration: "həˈloʊ",
|
|
102
|
+
* system: "ipa",
|
|
103
|
+
* partOfSpeech: "interjection"
|
|
104
|
+
* });
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export function createSimpleWord(options) {
|
|
108
|
+
const { text, transliteration, system = "ipa", partOfSpeech = "unknown" } = options;
|
|
109
|
+
const transcription = {
|
|
110
|
+
[system]: {
|
|
111
|
+
text: transliteration,
|
|
112
|
+
syllables: [text],
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
const metadata = {
|
|
116
|
+
partOfSpeech,
|
|
117
|
+
};
|
|
118
|
+
return createGLOSTWordNode({ value: text, transcription, metadata });
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Create a sentence from an array of words
|
|
122
|
+
*/
|
|
123
|
+
export function createSentenceFromWords(words, lang, script, originalText) {
|
|
124
|
+
const text = originalText ||
|
|
125
|
+
words
|
|
126
|
+
.map((w) => {
|
|
127
|
+
// Extract text from word's Text node children
|
|
128
|
+
const textNode = w.children.find((child) => child.type === "TextNode");
|
|
129
|
+
return textNode ? textNode.value : "";
|
|
130
|
+
})
|
|
131
|
+
.join("");
|
|
132
|
+
return createGLOSTSentenceNode({ originalText: text, lang, script, children: words });
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Create a paragraph from an array of sentences
|
|
136
|
+
*/
|
|
137
|
+
export function createParagraphFromSentences(sentences) {
|
|
138
|
+
return createGLOSTParagraphNode(sentences);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Create a document from an array of paragraphs
|
|
142
|
+
*/
|
|
143
|
+
export function createDocumentFromParagraphs(paragraphs, lang, script, metadata) {
|
|
144
|
+
return createGLOSTRootNode({ lang, script, children: paragraphs, metadata });
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Create a document from an array of sentences (simplified helper)
|
|
148
|
+
*
|
|
149
|
+
* Automatically wraps sentences in a paragraph for convenience.
|
|
150
|
+
* Useful when you don't need explicit paragraph structure.
|
|
151
|
+
*
|
|
152
|
+
* @param sentences - Array of sentences
|
|
153
|
+
* @param lang - Language code
|
|
154
|
+
* @param script - Script system (optional, will be inferred from lang if not provided)
|
|
155
|
+
* @param metadata - Optional document metadata
|
|
156
|
+
* @returns GLOST root document
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const sentences = [
|
|
161
|
+
* createSentenceFromWords([word1, word2], "th", "thai", "สวัสดี"),
|
|
162
|
+
* createSentenceFromWords([word3, word4], "th", "thai", "ขอบคุณ")
|
|
163
|
+
* ];
|
|
164
|
+
* const doc = createDocumentFromSentences(sentences, "th", "thai");
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export function createDocumentFromSentences(sentences, lang, script, metadata) {
|
|
168
|
+
const paragraph = createParagraphFromSentences(sentences);
|
|
169
|
+
return createDocumentFromParagraphs([paragraph], lang, script, metadata);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Create a simple document from an array of words (simplified helper)
|
|
173
|
+
*
|
|
174
|
+
* Automatically creates sentence and paragraph wrappers for maximum convenience.
|
|
175
|
+
* Perfect for testing, quick prototypes, and simple use cases.
|
|
176
|
+
*
|
|
177
|
+
* @param words - Array of word nodes
|
|
178
|
+
* @param lang - Language code
|
|
179
|
+
* @param script - Script system (optional, will be inferred from lang if not provided)
|
|
180
|
+
* @param options - Optional configuration
|
|
181
|
+
* @param options.sentenceText - Original text of the sentence (will be auto-generated if not provided)
|
|
182
|
+
* @param options.metadata - Optional document metadata
|
|
183
|
+
* @returns GLOST root document
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* import { createSimpleDocument } from "glost";
|
|
188
|
+
* import { createThaiWord } from "glost-th";
|
|
189
|
+
*
|
|
190
|
+
* const words = [
|
|
191
|
+
* createThaiWord({ text: "สวัสดี" }),
|
|
192
|
+
* createThaiWord({ text: "ครับ" })
|
|
193
|
+
* ];
|
|
194
|
+
* const doc = createSimpleDocument(words, "th", "thai", {
|
|
195
|
+
* sentenceText: "สวัสดีครับ"
|
|
196
|
+
* });
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
export function createSimpleDocument(words, lang, script, options) {
|
|
200
|
+
const sentence = createSentenceFromWords(words, lang, script, options?.sentenceText);
|
|
201
|
+
const paragraph = createParagraphFromSentences([sentence]);
|
|
202
|
+
return createDocumentFromParagraphs([paragraph], lang, script, options?.metadata);
|
|
203
|
+
}
|
|
204
|
+
// ============================================================================
|
|
205
|
+
// NLCST Node Factory Functions
|
|
206
|
+
// ============================================================================
|
|
207
|
+
/**
|
|
208
|
+
* Create a GLOST punctuation node
|
|
209
|
+
*/
|
|
210
|
+
export function createGLOSTPunctuationNode(value) {
|
|
211
|
+
return {
|
|
212
|
+
type: "PunctuationNode",
|
|
213
|
+
value,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Create a GLOST whitespace node
|
|
218
|
+
*/
|
|
219
|
+
export function createGLOSTWhiteSpaceNode(value) {
|
|
220
|
+
return {
|
|
221
|
+
type: "WhiteSpaceNode",
|
|
222
|
+
value,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Create a GLOST symbol node
|
|
227
|
+
*/
|
|
228
|
+
export function createGLOSTSymbolNode(value) {
|
|
229
|
+
return {
|
|
230
|
+
type: "SymbolNode",
|
|
231
|
+
value,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Create a GLOST text node
|
|
236
|
+
*/
|
|
237
|
+
export function createGLOSTTextNode(value) {
|
|
238
|
+
return {
|
|
239
|
+
type: "TextNode",
|
|
240
|
+
value,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AA4FA,+EAA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