wikitongues-db 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/dist/index.d.mts CHANGED
@@ -1,20 +1,66 @@
1
- import { L as LanguageData, S as SpeakerData, P as ProvenanceData, T as TranscriptionData, R as RawMetadataData, V as VideoData, F as FilterOptions, a as LanguageSummary, C as CountrySummary, b as SpeakerSummary, D as DatasetStats } from './dataset-jRTVzgZX.mjs';
2
- export { d as dataset } from './dataset-jRTVzgZX.mjs';
1
+ import { R as ReferenceTables, a as ResolvedIso639_3, b as ResolvedGlottolog, c as ResolvedBcp47, S as StandardsData, d as ResolvedStandards, L as LanguageData, e as SpeakerData, P as ProvenanceData, T as TranscriptionData, f as RawMetadataData, V as VideoData, F as FilterOptions, g as LanguageSummary, C as CountrySummary, h as SpeakerSummary, D as DatasetStats } from './dataset-DNYcpFFZ.mjs';
2
+ export { G as GlottologEntry, I as IanaLanguageEntry, i as IanaSubtagEntry, j as IanaVariantEntry, k as Iso639_3Entry, l as dataset } from './dataset-DNYcpFFZ.mjs';
3
+
4
+ /**
5
+ * Deterministic hydration of the persisted ontological anchor keys
6
+ * (`standards: { iso639_3, glottocode, bcp47 }`) into fully resolved standard objects,
7
+ * joined against the bundled reference tables (src/generated/reference.json).
8
+ *
9
+ * Hydration is strict: any key that does not resolve, or that violates the curation rules
10
+ * (macrolanguage ISO code, Glottolog family node, malformed or unregistered BCP-47 tag),
11
+ * throws a HydrationError. A dataset that does not hydrate does not load.
12
+ */
13
+
14
+ declare class HydrationError extends Error {
15
+ readonly recordId: string;
16
+ readonly field: keyof StandardsData;
17
+ readonly code: string;
18
+ constructor(recordId: string, field: keyof StandardsData, code: string, reason: string);
19
+ }
20
+ declare class ReferenceHydrator {
21
+ readonly tables: ReferenceTables;
22
+ constructor(tables?: ReferenceTables);
23
+ resolveIso(code: string, recordId?: string): ResolvedIso639_3;
24
+ resolveGlottolog(code: string, recordId?: string): ResolvedGlottolog;
25
+ /**
26
+ * Parse and validate a tag of the form `language[-script][-region][-variant]*` (RFC 5646 §2.1).
27
+ * The primary subtag must be the ISO 639-1 code of `iso` when one exists, else `iso` itself.
28
+ */
29
+ resolveBcp47(tag: string, iso: ResolvedIso639_3, recordId?: string): ResolvedBcp47;
30
+ hydrate(standards: StandardsData, recordId?: string): ResolvedStandards;
31
+ }
3
32
 
4
33
  /**
5
34
  * Domain models for the high-level Wikitongues Database API.
6
35
  * Provides typed, immutable-friendly classes with rich helper methods.
7
36
  */
8
37
 
38
+ /**
39
+ * A language as recorded in a video: three independently resolved institutional standards
40
+ * plus the speaker's own claim, Wikitongues' editorial label and the autonym.
41
+ * Shared by `Video.primaryLanguage` and every entry of `Video.additionalLanguages`.
42
+ */
9
43
  declare class Language {
10
- readonly iso639_3: string;
11
- readonly bcp47: string;
12
- readonly name: string;
13
- readonly glottocode: string | null;
14
- readonly autonym: string | null;
15
- readonly dialect: string | null;
16
- constructor(data: Partial<LanguageData>);
17
- static fromDict(data: Partial<LanguageData>): Language;
44
+ readonly standards: ResolvedStandards;
45
+ readonly speakerClaim: string | null;
46
+ readonly wikitonguesClassification: string;
47
+ readonly wikitonguesLineage: string | null;
48
+ readonly autonym: string;
49
+ constructor(data: LanguageData, hydrator: ReferenceHydrator, recordId?: string);
50
+ static hydrate(data: LanguageData, hydrator: ReferenceHydrator, recordId?: string): Language;
51
+ /** ISO 639-3 code, e.g. "por". */
52
+ get iso639_3(): string;
53
+ /** BCP-47 tag, e.g. "pt-BR". */
54
+ get bcp47(): string;
55
+ /** Glottocode, e.g. "braz1246". */
56
+ get glottocode(): string;
57
+ /** Human-readable label: Wikitongues' own classification. */
58
+ get name(): string;
59
+ /**
60
+ * Every label under which this language can be searched, in priority order:
61
+ * Wikitongues classification, Glottolog node name, ISO reference name, autonym, speaker claim.
62
+ */
63
+ get labels(): string[];
18
64
  toDict(): LanguageData;
19
65
  }
20
66
  declare class Speaker {
@@ -65,7 +111,7 @@ declare class Video {
65
111
  readonly provenance: Provenance;
66
112
  readonly transcription: Transcription;
67
113
  readonly rawMetadata: RawMetadata;
68
- constructor(data: Partial<VideoData>);
114
+ constructor(data: VideoData, hydrator?: ReferenceHydrator);
69
115
  /**
70
116
  * Returns the YouTube embed URL for iframe players.
71
117
  */
@@ -109,8 +155,9 @@ declare class Video {
109
155
  get countryCode(): string | null;
110
156
  get countryName(): string | null;
111
157
  /**
112
- * Check if video contains a language matching query (by ISO, BCP-47, Glottocode, Name, Autonym, or Dialect).
113
- * Case-insensitive.
158
+ * Check if video contains a language matching query (by ISO 639-3, BCP-47, Glottocode —
159
+ * including the parent language of a dialect node — or any label: Wikitongues classification,
160
+ * Glottolog name, ISO name, autonym, speaker claim). Case-insensitive.
114
161
  */
115
162
  hasLanguage(query: string): boolean;
116
163
  /**
@@ -129,7 +176,7 @@ declare class Video {
129
176
  * Serialize Video to JSON string.
130
177
  */
131
178
  toJSON(indent?: number): string;
132
- static fromDict(data: Partial<VideoData>): Video;
179
+ static fromDict(data: VideoData, hydrator?: ReferenceHydrator): Video;
133
180
  }
134
181
 
135
182
  /**
@@ -179,9 +226,10 @@ declare class VideoCollection implements Iterable<Video> {
179
226
  /**
180
227
  * Language Resolver module for Wikitongues Database.
181
228
  * Resolves natural language search queries (ISO 639-3, BCP 47, Glottocode, English canonical names,
182
- * multilingual common names like 'russe' / 'español', autonyms, and dialects)
229
+ * multilingual common names like 'russe' / 'español', autonyms, Glottolog / ISO names and speaker claims)
183
230
  * to matched language identifiers.
184
231
  */
232
+
185
233
  declare function normalizeText(text?: string | null): string;
186
234
  /**
187
235
  * Common international / multilingual aliases for popular and regional languages.
@@ -193,13 +241,16 @@ declare class LanguageResolver {
193
241
  glottoToIso: Map<string, string>;
194
242
  isoToGlotto: Map<string, string>;
195
243
  autonymToIso: Map<string, Set<string>>;
196
- dialectToIso: Map<string, Set<string>>;
244
+ /** Secondary labels (Glottolog node names, ISO reference names, speaker claims) → ISO codes. */
245
+ labelToIso: Map<string, Set<string>>;
197
246
  aliases: Map<string, string>;
198
247
  constructor();
248
+ private addToSet;
199
249
  /**
200
- * Dynamically register language metadata discovered from normalized records.
250
+ * Register a hydrated language from the dataset: its primary label (Wikitongues classification)
251
+ * goes to the name index; Glottolog / ISO names and the speaker claim to the secondary label index.
201
252
  */
202
- registerDatasetLanguage(iso639_3: string, bcp47: string, name: string, glottocode?: string | null, autonym?: string | null, dialect?: string | null): void;
253
+ registerDatasetLanguage(lang: Language): void;
203
254
  /**
204
255
  * Resolve a search string to matching ISO 639-3 codes (and direct identifiers).
205
256
  * Returns a set of matching ISO codes (or Glottocodes).
@@ -209,7 +260,7 @@ declare class LanguageResolver {
209
260
 
210
261
  /**
211
262
  * In-memory Inverted Index engine for Wikitongues Database.
212
- * Provides O(1) indexed lookups by ID, ISO 639-3, BCP 47, Glottocode, Country, Speaker, License, etc.
263
+ * Provides O(1) indexed lookups by ID, ISO 639-3, BCP 47, Glottocode (incl. parent language of dialects), Country, Speaker, License, etc.
213
264
  */
214
265
 
215
266
  declare class DatasetIndex {
@@ -304,12 +355,22 @@ declare class QueryBuilder {
304
355
  interface WikitonguesDBOptions {
305
356
  data?: (VideoData | Video)[];
306
357
  records?: (VideoData | Video)[];
358
+ /**
359
+ * Reference tables used to hydrate `standards`. Defaults to the bundled pruned tables
360
+ * (src/generated/reference.json); pass full tables when loading records outside the dataset.
361
+ */
362
+ reference?: ReferenceTables;
307
363
  }
308
364
  declare class WikitonguesDB {
309
365
  protected readonly _videos: Video[];
366
+ readonly hydrator: ReferenceHydrator;
310
367
  readonly resolver: LanguageResolver;
311
368
  readonly index: DatasetIndex;
312
369
  readonly searchEngine: SearchEngine;
370
+ /**
371
+ * Loads and hydrates every record. Throws HydrationError on the first record whose
372
+ * standards do not resolve against the reference tables (see CLASSIFICATION_RULES.md §3.1.1).
373
+ */
313
374
  constructor(options?: WikitonguesDBOptions);
314
375
  get length(): number;
315
376
  /**
@@ -337,7 +398,8 @@ declare class WikitonguesDB {
337
398
  */
338
399
  getByBcp47(tag: string): VideoCollection;
339
400
  /**
340
- * Lookup videos matching a Glottolog code in O(1) time.
401
+ * Lookup videos matching a Glottolog code in O(1) time. A language node also matches videos
402
+ * classified under one of its dialect nodes (e.g. `port1283` returns `braz1246` recordings).
341
403
  */
342
404
  getByGlottocode(glottocode: string): VideoCollection;
343
405
  /**
@@ -350,7 +412,8 @@ declare class WikitonguesDB {
350
412
  getBySpeaker(name: string): VideoCollection;
351
413
  /**
352
414
  * Intelligent language search: resolves natural names, multilingual aliases ('russe'),
353
- * ISO 639-3 ('rus'), BCP 47 ('ru'), autonyms ('Русский'), and dialects.
415
+ * ISO 639-3 ('rus'), BCP 47 ('ru'), Glottocodes, autonyms ('Русский'), Wikitongues
416
+ * classifications, Glottolog / ISO names and speaker claims.
354
417
  */
355
418
  findByLanguage(languageQuery: string, includeAdditional?: boolean): VideoCollection;
356
419
  /**
@@ -391,4 +454,4 @@ declare class WikitonguesDB {
391
454
  stats(): DatasetStats;
392
455
  }
393
456
 
394
- export { CountrySummary, DatasetIndex, DatasetStats, FilterOptions, Language, LanguageData, LanguageResolver, LanguageSummary, MULTILINGUAL_ALIASES, Provenance, ProvenanceData, QueryBuilder, RawMetadata, RawMetadataData, SearchEngine, Speaker, SpeakerData, SpeakerSummary, Transcription, TranscriptionData, Video, VideoCollection, VideoData, WikitonguesDB, type WikitonguesDBOptions, normalizeText };
457
+ export { CountrySummary, DatasetIndex, DatasetStats, FilterOptions, HydrationError, Language, LanguageData, LanguageResolver, LanguageSummary, MULTILINGUAL_ALIASES, Provenance, ProvenanceData, QueryBuilder, RawMetadata, RawMetadataData, ReferenceHydrator, ReferenceTables, ResolvedBcp47, ResolvedGlottolog, ResolvedIso639_3, ResolvedStandards, SearchEngine, Speaker, SpeakerData, SpeakerSummary, StandardsData, Transcription, TranscriptionData, Video, VideoCollection, VideoData, WikitonguesDB, type WikitonguesDBOptions, normalizeText };
package/dist/index.d.ts CHANGED
@@ -1,20 +1,66 @@
1
- import { L as LanguageData, S as SpeakerData, P as ProvenanceData, T as TranscriptionData, R as RawMetadataData, V as VideoData, F as FilterOptions, a as LanguageSummary, C as CountrySummary, b as SpeakerSummary, D as DatasetStats } from './dataset-jRTVzgZX.js';
2
- export { d as dataset } from './dataset-jRTVzgZX.js';
1
+ import { R as ReferenceTables, a as ResolvedIso639_3, b as ResolvedGlottolog, c as ResolvedBcp47, S as StandardsData, d as ResolvedStandards, L as LanguageData, e as SpeakerData, P as ProvenanceData, T as TranscriptionData, f as RawMetadataData, V as VideoData, F as FilterOptions, g as LanguageSummary, C as CountrySummary, h as SpeakerSummary, D as DatasetStats } from './dataset-DNYcpFFZ.js';
2
+ export { G as GlottologEntry, I as IanaLanguageEntry, i as IanaSubtagEntry, j as IanaVariantEntry, k as Iso639_3Entry, l as dataset } from './dataset-DNYcpFFZ.js';
3
+
4
+ /**
5
+ * Deterministic hydration of the persisted ontological anchor keys
6
+ * (`standards: { iso639_3, glottocode, bcp47 }`) into fully resolved standard objects,
7
+ * joined against the bundled reference tables (src/generated/reference.json).
8
+ *
9
+ * Hydration is strict: any key that does not resolve, or that violates the curation rules
10
+ * (macrolanguage ISO code, Glottolog family node, malformed or unregistered BCP-47 tag),
11
+ * throws a HydrationError. A dataset that does not hydrate does not load.
12
+ */
13
+
14
+ declare class HydrationError extends Error {
15
+ readonly recordId: string;
16
+ readonly field: keyof StandardsData;
17
+ readonly code: string;
18
+ constructor(recordId: string, field: keyof StandardsData, code: string, reason: string);
19
+ }
20
+ declare class ReferenceHydrator {
21
+ readonly tables: ReferenceTables;
22
+ constructor(tables?: ReferenceTables);
23
+ resolveIso(code: string, recordId?: string): ResolvedIso639_3;
24
+ resolveGlottolog(code: string, recordId?: string): ResolvedGlottolog;
25
+ /**
26
+ * Parse and validate a tag of the form `language[-script][-region][-variant]*` (RFC 5646 §2.1).
27
+ * The primary subtag must be the ISO 639-1 code of `iso` when one exists, else `iso` itself.
28
+ */
29
+ resolveBcp47(tag: string, iso: ResolvedIso639_3, recordId?: string): ResolvedBcp47;
30
+ hydrate(standards: StandardsData, recordId?: string): ResolvedStandards;
31
+ }
3
32
 
4
33
  /**
5
34
  * Domain models for the high-level Wikitongues Database API.
6
35
  * Provides typed, immutable-friendly classes with rich helper methods.
7
36
  */
8
37
 
38
+ /**
39
+ * A language as recorded in a video: three independently resolved institutional standards
40
+ * plus the speaker's own claim, Wikitongues' editorial label and the autonym.
41
+ * Shared by `Video.primaryLanguage` and every entry of `Video.additionalLanguages`.
42
+ */
9
43
  declare class Language {
10
- readonly iso639_3: string;
11
- readonly bcp47: string;
12
- readonly name: string;
13
- readonly glottocode: string | null;
14
- readonly autonym: string | null;
15
- readonly dialect: string | null;
16
- constructor(data: Partial<LanguageData>);
17
- static fromDict(data: Partial<LanguageData>): Language;
44
+ readonly standards: ResolvedStandards;
45
+ readonly speakerClaim: string | null;
46
+ readonly wikitonguesClassification: string;
47
+ readonly wikitonguesLineage: string | null;
48
+ readonly autonym: string;
49
+ constructor(data: LanguageData, hydrator: ReferenceHydrator, recordId?: string);
50
+ static hydrate(data: LanguageData, hydrator: ReferenceHydrator, recordId?: string): Language;
51
+ /** ISO 639-3 code, e.g. "por". */
52
+ get iso639_3(): string;
53
+ /** BCP-47 tag, e.g. "pt-BR". */
54
+ get bcp47(): string;
55
+ /** Glottocode, e.g. "braz1246". */
56
+ get glottocode(): string;
57
+ /** Human-readable label: Wikitongues' own classification. */
58
+ get name(): string;
59
+ /**
60
+ * Every label under which this language can be searched, in priority order:
61
+ * Wikitongues classification, Glottolog node name, ISO reference name, autonym, speaker claim.
62
+ */
63
+ get labels(): string[];
18
64
  toDict(): LanguageData;
19
65
  }
20
66
  declare class Speaker {
@@ -65,7 +111,7 @@ declare class Video {
65
111
  readonly provenance: Provenance;
66
112
  readonly transcription: Transcription;
67
113
  readonly rawMetadata: RawMetadata;
68
- constructor(data: Partial<VideoData>);
114
+ constructor(data: VideoData, hydrator?: ReferenceHydrator);
69
115
  /**
70
116
  * Returns the YouTube embed URL for iframe players.
71
117
  */
@@ -109,8 +155,9 @@ declare class Video {
109
155
  get countryCode(): string | null;
110
156
  get countryName(): string | null;
111
157
  /**
112
- * Check if video contains a language matching query (by ISO, BCP-47, Glottocode, Name, Autonym, or Dialect).
113
- * Case-insensitive.
158
+ * Check if video contains a language matching query (by ISO 639-3, BCP-47, Glottocode —
159
+ * including the parent language of a dialect node — or any label: Wikitongues classification,
160
+ * Glottolog name, ISO name, autonym, speaker claim). Case-insensitive.
114
161
  */
115
162
  hasLanguage(query: string): boolean;
116
163
  /**
@@ -129,7 +176,7 @@ declare class Video {
129
176
  * Serialize Video to JSON string.
130
177
  */
131
178
  toJSON(indent?: number): string;
132
- static fromDict(data: Partial<VideoData>): Video;
179
+ static fromDict(data: VideoData, hydrator?: ReferenceHydrator): Video;
133
180
  }
134
181
 
135
182
  /**
@@ -179,9 +226,10 @@ declare class VideoCollection implements Iterable<Video> {
179
226
  /**
180
227
  * Language Resolver module for Wikitongues Database.
181
228
  * Resolves natural language search queries (ISO 639-3, BCP 47, Glottocode, English canonical names,
182
- * multilingual common names like 'russe' / 'español', autonyms, and dialects)
229
+ * multilingual common names like 'russe' / 'español', autonyms, Glottolog / ISO names and speaker claims)
183
230
  * to matched language identifiers.
184
231
  */
232
+
185
233
  declare function normalizeText(text?: string | null): string;
186
234
  /**
187
235
  * Common international / multilingual aliases for popular and regional languages.
@@ -193,13 +241,16 @@ declare class LanguageResolver {
193
241
  glottoToIso: Map<string, string>;
194
242
  isoToGlotto: Map<string, string>;
195
243
  autonymToIso: Map<string, Set<string>>;
196
- dialectToIso: Map<string, Set<string>>;
244
+ /** Secondary labels (Glottolog node names, ISO reference names, speaker claims) → ISO codes. */
245
+ labelToIso: Map<string, Set<string>>;
197
246
  aliases: Map<string, string>;
198
247
  constructor();
248
+ private addToSet;
199
249
  /**
200
- * Dynamically register language metadata discovered from normalized records.
250
+ * Register a hydrated language from the dataset: its primary label (Wikitongues classification)
251
+ * goes to the name index; Glottolog / ISO names and the speaker claim to the secondary label index.
201
252
  */
202
- registerDatasetLanguage(iso639_3: string, bcp47: string, name: string, glottocode?: string | null, autonym?: string | null, dialect?: string | null): void;
253
+ registerDatasetLanguage(lang: Language): void;
203
254
  /**
204
255
  * Resolve a search string to matching ISO 639-3 codes (and direct identifiers).
205
256
  * Returns a set of matching ISO codes (or Glottocodes).
@@ -209,7 +260,7 @@ declare class LanguageResolver {
209
260
 
210
261
  /**
211
262
  * In-memory Inverted Index engine for Wikitongues Database.
212
- * Provides O(1) indexed lookups by ID, ISO 639-3, BCP 47, Glottocode, Country, Speaker, License, etc.
263
+ * Provides O(1) indexed lookups by ID, ISO 639-3, BCP 47, Glottocode (incl. parent language of dialects), Country, Speaker, License, etc.
213
264
  */
214
265
 
215
266
  declare class DatasetIndex {
@@ -304,12 +355,22 @@ declare class QueryBuilder {
304
355
  interface WikitonguesDBOptions {
305
356
  data?: (VideoData | Video)[];
306
357
  records?: (VideoData | Video)[];
358
+ /**
359
+ * Reference tables used to hydrate `standards`. Defaults to the bundled pruned tables
360
+ * (src/generated/reference.json); pass full tables when loading records outside the dataset.
361
+ */
362
+ reference?: ReferenceTables;
307
363
  }
308
364
  declare class WikitonguesDB {
309
365
  protected readonly _videos: Video[];
366
+ readonly hydrator: ReferenceHydrator;
310
367
  readonly resolver: LanguageResolver;
311
368
  readonly index: DatasetIndex;
312
369
  readonly searchEngine: SearchEngine;
370
+ /**
371
+ * Loads and hydrates every record. Throws HydrationError on the first record whose
372
+ * standards do not resolve against the reference tables (see CLASSIFICATION_RULES.md §3.1.1).
373
+ */
313
374
  constructor(options?: WikitonguesDBOptions);
314
375
  get length(): number;
315
376
  /**
@@ -337,7 +398,8 @@ declare class WikitonguesDB {
337
398
  */
338
399
  getByBcp47(tag: string): VideoCollection;
339
400
  /**
340
- * Lookup videos matching a Glottolog code in O(1) time.
401
+ * Lookup videos matching a Glottolog code in O(1) time. A language node also matches videos
402
+ * classified under one of its dialect nodes (e.g. `port1283` returns `braz1246` recordings).
341
403
  */
342
404
  getByGlottocode(glottocode: string): VideoCollection;
343
405
  /**
@@ -350,7 +412,8 @@ declare class WikitonguesDB {
350
412
  getBySpeaker(name: string): VideoCollection;
351
413
  /**
352
414
  * Intelligent language search: resolves natural names, multilingual aliases ('russe'),
353
- * ISO 639-3 ('rus'), BCP 47 ('ru'), autonyms ('Русский'), and dialects.
415
+ * ISO 639-3 ('rus'), BCP 47 ('ru'), Glottocodes, autonyms ('Русский'), Wikitongues
416
+ * classifications, Glottolog / ISO names and speaker claims.
354
417
  */
355
418
  findByLanguage(languageQuery: string, includeAdditional?: boolean): VideoCollection;
356
419
  /**
@@ -391,4 +454,4 @@ declare class WikitonguesDB {
391
454
  stats(): DatasetStats;
392
455
  }
393
456
 
394
- export { CountrySummary, DatasetIndex, DatasetStats, FilterOptions, Language, LanguageData, LanguageResolver, LanguageSummary, MULTILINGUAL_ALIASES, Provenance, ProvenanceData, QueryBuilder, RawMetadata, RawMetadataData, SearchEngine, Speaker, SpeakerData, SpeakerSummary, Transcription, TranscriptionData, Video, VideoCollection, VideoData, WikitonguesDB, type WikitonguesDBOptions, normalizeText };
457
+ export { CountrySummary, DatasetIndex, DatasetStats, FilterOptions, HydrationError, Language, LanguageData, LanguageResolver, LanguageSummary, MULTILINGUAL_ALIASES, Provenance, ProvenanceData, QueryBuilder, RawMetadata, RawMetadataData, ReferenceHydrator, ReferenceTables, ResolvedBcp47, ResolvedGlottolog, ResolvedIso639_3, ResolvedStandards, SearchEngine, Speaker, SpeakerData, SpeakerSummary, StandardsData, Transcription, TranscriptionData, Video, VideoCollection, VideoData, WikitonguesDB, type WikitonguesDBOptions, normalizeText };