wikitongues-db 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Wikitongues Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,172 @@
1
+ # wikitongues-db
2
+
3
+ > A zero-dependency, in-memory database and search engine mapping ISO 639-3, BCP 47, Glottolog, autonyms, and dialects to curated Wikitongues video recordings. Published for **TypeScript / JavaScript (npm)**.
4
+
5
+ ---
6
+
7
+ ## Motivation & Context
8
+
9
+ [Wikitongues](https://wikitongues.org/) is a non-profit organization dedicated to language documentation, revitalization, and diversity. Over the past decade, they have built an archive of video recordings representing hundreds of languages and dialects across YouTube and Wikimedia Commons.
10
+
11
+ However, existing metadata across YouTube and Commons is heterogeneous, with free-text descriptions, unstructured notes, and no unified linguistic index.
12
+
13
+ **`wikitongues-db`** bridges this gap by providing:
14
+ 1. **A curated, deterministic dataset**: 863 normalized records across 460+ languages with structured speaker roles, dialects, geographic provenance, licensing, and transcript status.
15
+ 2. **Strict linguistic validation**: Verified against official **SIL ISO 639-3** tables, **BCP 47** tags, and **Glottolog** identifiers.
16
+ 3. **Multi-faceted resolution**: Instant matching by ISO code, BCP 47 tag, Glottocode, English canonical name, multilingual common name (e.g. `russe`, `espagnol`), native script autonym (`Qhichwa`, `Asụsụ Igbo`, `Русский`), or dialect variety (`Arbëresh`, `Gascon`, `Biscayan`).
17
+ 4. **Rich content types**: Covers oral histories (81%), spontaneous conversations (13%), sign languages (2.5%), readings/songs (1.5%), and fellowship documentaries.
18
+ 5. **Zero-dependency TypeScript client**: Embedded in-memory database with $O(1)$ inverted indices, fluent query builder, and full-text search engine.
19
+
20
+ ---
21
+
22
+ ## Architecture
23
+
24
+ ```
25
+ ┌─────────────────────────────────────────┐
26
+ │ Wikitongues YouTube & Commons │
27
+ └────────────────────┬────────────────────┘
28
+ │ (Curated Metadata)
29
+
30
+ ┌─────────────────────────────────────────┐
31
+ │ SIL ISO 639-3 & Glottolog Validator │ <-- Anti-hallucination safeguard
32
+ └────────────────────┬────────────────────┘
33
+ │ (Deterministic Indexing)
34
+
35
+ ┌─────────────────────────────────────────┐
36
+ │ wikitongues-db (Static JSON / DB) │
37
+ └────────────────────┬────────────────────┘
38
+
39
+
40
+ TypeScript (npm)
41
+ O(1) in-memory API
42
+ ```
43
+
44
+ ---
45
+
46
+ ## Dataset Overview
47
+
48
+ | Metric | Value |
49
+ | :--- | :--- |
50
+ | **Total Curated Videos** | `863` |
51
+ | **Unique Primary ISO 639-3 Languages** | `462` |
52
+ | **Unique BCP 47 Language Tags** | `515` |
53
+ | **Glottocode Resolution** | `466 / 863` (54.0%) |
54
+ | **Native Script Autonyms** | `820 / 863` (95.0%) |
55
+ | **Resolved Dialects / Varieties** | `266 / 863` (30.8%) |
56
+ | **Total Archival Duration** | `53h 54m 30s` (`194,070` seconds) |
57
+ | **Videos with Subtitles / Captions** | `275` |
58
+ | **Runtime Dependencies** | `0` |
59
+
60
+ ---
61
+
62
+ ## TypeScript & JavaScript API (npm)
63
+
64
+ The package is zero-dependency, works seamlessly across Node.js (CommonJS & ESM), Vite, Next.js, and browser environments, and embeds the curated normalized dataset directly (~1.1 MB uncompressed, ~160 KB gzipped).
65
+
66
+ ### Installation
67
+
68
+ ```bash
69
+ npm install wikitongues-db
70
+ # or
71
+ yarn add wikitongues-db
72
+ # or
73
+ pnpm add wikitongues-db
74
+ ```
75
+
76
+ ### 1. Basic Lookups & Smart Language Resolution
77
+
78
+ ```typescript
79
+ import { WikitonguesDB } from 'wikitongues-db';
80
+
81
+ // Initializes in-memory inverted indices across 863 curated recordings instantly
82
+ const db = new WikitonguesDB();
83
+
84
+ // 1. Smart Language Search (supports ISO 639-3, BCP 47, Glottolog, French/English aliases, autonyms)
85
+ const russianVids = db.findByLanguage('russe'); // or "Russian", "rus", "ru", "Русский", "russ1263"
86
+ const quechuaVids = db.findByLanguage('Qhichwa'); // by native autonym
87
+ const arbereshVids = db.findByLanguage('Arbëresh'); // by dialect
88
+
89
+ // 2. O(1) Indexed Lookups
90
+ const video = db.get('nXBPa_wb3dM'); // Lookup by YouTube ID
91
+ const basqueVids = db.getByIso('eus'); // Lookup by ISO 639-3
92
+ const peruVids = db.getByCountry('PE'); // Lookup by ISO 3166-1 alpha-2 or country name
93
+ ```
94
+
95
+ ### 2. Fluent Chainable Query Builder
96
+
97
+ ```typescript
98
+ const results = db
99
+ .query()
100
+ .language('Russian')
101
+ .country('RU')
102
+ .creativeCommonsOnly()
103
+ .withSubtitles()
104
+ .minDuration(60)
105
+ .maxDuration(600)
106
+ .orderBy('duration', true)
107
+ .limit(10)
108
+ .all();
109
+
110
+ console.log(`Found ${results.length} videos (${results.totalDurationFormatted})`);
111
+ for (const v of results) {
112
+ console.log(`- ${v.title} | ${v.url} | ${v.durationFormatted}`);
113
+ }
114
+ ```
115
+
116
+ ### 3. Full-Text Search with Relevance Scoring
117
+
118
+ ```typescript
119
+ const matches = db.search('dagestan caucasian oral history', 5);
120
+ for (const v of matches) {
121
+ console.log(v.title, v.primaryLanguage.name, v.url);
122
+ }
123
+ ```
124
+
125
+ ### 4. Rich `VideoCollection` Operations
126
+
127
+ ```typescript
128
+ const collection = db.getByCountry('PE');
129
+
130
+ // Aggregations
131
+ console.log(collection.totalDurationFormatted); // e.g. "1h 45m 12s"
132
+ console.log(collection.languages); // Unique primary Language objects
133
+ console.log(collection.speakerNames); // Array of speaker names
134
+ console.log(collection.urls); // Array of video URLs
135
+ console.log(collection.embedUrls); // Array of YouTube embed URLs
136
+
137
+ // Chained transformations
138
+ const ccSample = collection.filter((v) => v.isCreativeCommons).sample(3);
139
+
140
+ // Serializations
141
+ const jsonString = collection.toJSON();
142
+ const jsonlString = collection.toJSONL();
143
+ const csvString = collection.toCSV();
144
+ ```
145
+
146
+ ### 5. Direct Dataset Access
147
+
148
+ You can also directly import the raw normalized dataset without constructing a DB instance:
149
+
150
+ ```typescript
151
+ import dataset from 'wikitongues-db/data';
152
+ // or: import { dataset } from 'wikitongues-db';
153
+
154
+ console.log(`Loaded ${dataset.length} normalized records directly`);
155
+ ```
156
+
157
+ ---
158
+
159
+ ## Roadmap
160
+
161
+ - [x] **Phase 1 — Normalization & Semantic Validation**: Curate structured entities strictly against SIL ISO 639-3 and Glottolog tables.
162
+ - [x] **Phase 2 — Inverted Indexing & Smart Resolution**: $O(1)$ lookups, multilingual search, and query engine.
163
+ - [x] **Phase 3 — TypeScript (npm) Package**: Zero-dependency package with embedded dataset, dual ESM/CJS, and full TypeScript types.
164
+ - [ ] **Phase 4 — Rust (crates.io)**: High-performance, zero-alloc lookup engine.
165
+
166
+ ---
167
+
168
+ ## License & Attribution
169
+
170
+ All video contents and oral histories are recorded and owned by [Wikitongues](https://wikitongues.org/) and their respective speakers under Creative Commons licenses (primarily CC-BY-NC 4.0 / CC-BY 4.0).
171
+
172
+ This metadata repository and codebase are licensed under the MIT License.