cstr commited on
Commit
763f4c1
Β·
verified Β·
1 Parent(s): 710b859

Add comprehensive README

Browse files
Files changed (1) hide show
  1. README.md +411 -0
README.md ADDED
@@ -0,0 +1,411 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-sa-3.0
3
+ task_categories:
4
+ - text-retrieval
5
+ - text-generation
6
+ language:
7
+ - de
8
+ tags:
9
+ - wiktionary
10
+ - dictionary
11
+ - german
12
+ - linguistics
13
+ - morphology
14
+ - semantics
15
+ - normalized
16
+ size_categories:
17
+ - 100K<n<1M
18
+ ---
19
+
20
+ # German Wiktionary - Normalized SQLite Database
21
+
22
+ A fully normalized, production-ready SQLite database of German Wiktionary with complete linguistic information and optimized query performance.
23
+
24
+ ## 🎯 Key Features
25
+
26
+ - **βœ… Zero data loss**: All information from original Wiktionary preserved
27
+ - **⚑ Lightning-fast queries**: Comprehensive indexing (< 5ms typical queries)
28
+ - **πŸ” Full grammatical analysis**: Complete inflection paradigms, word forms, 185 unique grammatical tags
29
+ - **πŸ”— Semantic relations**: Synonyms, antonyms, derived/related terms
30
+ - **🌍 Multi-language**: Translations to 100+ languages
31
+ - **πŸ“± Mobile-ready**: Optimized for Flutter/Dart apps on all platforms
32
+ - **πŸ—£οΈ Pronunciation**: IPA, audio files, rhymes
33
+ - **πŸ“š Rich examples**: Usage examples with citations
34
+ - **πŸŽ“ Proper normalization**: Tags/topics/categories deduplicated (3NF)
35
+
36
+ ## πŸ“Š Database Statistics
37
+
38
+ - **Entries**: 970,801 German words
39
+ - **Word senses**: 3.1M+ definitions with glosses
40
+ - **Translations**: 1.1M+ translations
41
+ - **Word forms**: 6.1M+ inflected forms
42
+ - **Pronunciations**: 2.3M+ IPA/audio entries
43
+ - **Examples**: 427K+ usage examples
44
+ - **Unique tags**: 185 grammatical tags
45
+ - **Unique topics**: 58 domain topics
46
+ - **Unique categories**: 352 Wiktionary categories
47
+ - **File size**: ~3.6 GB (uncompressed), ~1.8 GB (compressed)
48
+
49
+ ## πŸ—οΈ Database Schema
50
+
51
+ ### Lookup Tables (Deduplicated)
52
+ - **tags**: Grammatical tags (nominative, plural, past, etc.)
53
+ - **topics**: Domain topics (biology, law, sports, etc.)
54
+ - **categories**: Wiktionary categories
55
+
56
+ ### Core Tables
57
+ - **entries**: Main word entries
58
+ - **senses**: Word senses/meanings
59
+ - **glosses**: Definitions for each sense
60
+ - **examples**: Usage examples with citations
61
+
62
+ ### Morphology
63
+ - **forms**: All inflected forms (declensions, conjugations)
64
+ - **form_tags**: Many-to-many: forms ↔ grammatical tags
65
+ - **hyphenations**: Syllable breaks
66
+
67
+ ### Phonology
68
+ - **sounds**: IPA pronunciations, audio URLs, rhymes
69
+ - **sound_tags**: Pronunciation variants
70
+
71
+ ### Semantics
72
+ - **synonyms**: Synonymous words
73
+ - **antonyms**: Opposite words
74
+ - **derived_terms**: Morphologically derived words
75
+ - **related_terms**: Semantically related words
76
+ - **synonym_tags/synonym_topics**: Synonym metadata
77
+
78
+ ### Translation
79
+ - **translations**: Translations to other languages
80
+ - **translation_tags**: Translation grammatical tags
81
+
82
+ ### Metadata
83
+ - **entry_tags**: Word-level tags
84
+ - **entry_categories**: Wiktionary categories
85
+ - **sense_tags/sense_topics/sense_categories**: Sense-level metadata
86
+
87
+ ## πŸ“– Usage
88
+
89
+ ### Download
90
+ ```python
91
+ from huggingface_hub import hf_hub_download
92
+ import sqlite3
93
+ import gzip
94
+ import shutil
95
+
96
+ # Download compressed database
97
+ db_gz_path = hf_hub_download(
98
+ repo_id="cstr/de-wiktionary-sqlite-normalized",
99
+ filename="de_wiktionary_normalized.db",
100
+ repo_type="dataset"
101
+ )
102
+
103
+ # Decompress if needed
104
+ if db_gz_path.endswith('.gz'):
105
+ db_path = db_gz_path[:-3]
106
+ with gzip.open(db_gz_path, 'rb') as f_in:
107
+ with open(db_path, 'wb') as f_out:
108
+ shutil.copyfileobj(f_in, f_out)
109
+ else:
110
+ db_path = db_gz_path
111
+
112
+ # Connect
113
+ conn = sqlite3.connect(db_path)
114
+ ```
115
+
116
+ ### Python Examples
117
+ ```python
118
+ import sqlite3
119
+
120
+ conn = sqlite3.connect('de_wiktionary_normalized.db')
121
+ cursor = conn.cursor()
122
+
123
+ # Example 1: Get all inflections with grammatical tags
124
+ cursor.execute('''
125
+ SELECT f.form_text, GROUP_CONCAT(t.tag, ', ') as tags
126
+ FROM entries e
127
+ JOIN forms f ON e.id = f.entry_id
128
+ LEFT JOIN form_tags ft ON f.id = ft.form_id
129
+ LEFT JOIN tags t ON ft.tag_id = t.id
130
+ WHERE e.word = ? AND e.lang = 'Deutsch'
131
+ GROUP BY f.id
132
+ ''', ('Haus',))
133
+
134
+ for form, tags in cursor.fetchall():
135
+ print(f"{form}: {tags}")
136
+
137
+ # Example 2: Get synonyms
138
+ cursor.execute('''
139
+ SELECT s.synonym_word
140
+ FROM entries e
141
+ JOIN synonyms s ON e.id = s.entry_id
142
+ WHERE e.word = ? AND e.lang = 'Deutsch'
143
+ ''', ('schnell',))
144
+
145
+ synonyms = [row[0] for row in cursor.fetchall()]
146
+ print(f"Synonyms: {synonyms}")
147
+
148
+ # Example 3: Get IPA pronunciation
149
+ cursor.execute('''
150
+ SELECT s.ipa
151
+ FROM entries e
152
+ JOIN sounds s ON e.id = s.entry_id
153
+ WHERE e.word = ? AND s.ipa IS NOT NULL
154
+ ''', ('Haus',))
155
+
156
+ print("IPA:", [row[0] for row in cursor.fetchall()])
157
+
158
+ # Example 4: Get definitions
159
+ cursor.execute('''
160
+ SELECT g.gloss_text
161
+ FROM entries e
162
+ JOIN senses se ON e.id = se.entry_id
163
+ JOIN glosses g ON se.id = g.sense_id
164
+ WHERE e.word = ? AND e.lang = 'Deutsch'
165
+ ''', ('Liebe',))
166
+
167
+ print("Definitions:")
168
+ for (gloss,) in cursor.fetchall():
169
+ print(f" - {gloss}")
170
+
171
+ # Example 5: Get English translations
172
+ cursor.execute('''
173
+ SELECT t.word
174
+ FROM entries e
175
+ JOIN translations t ON e.id = t.entry_id
176
+ WHERE e.word = ? AND t.lang_code = 'en'
177
+ ''', ('Hund',))
178
+
179
+ print("English:", [row[0] for row in cursor.fetchall()])
180
+
181
+ # Example 6: Find words by topic
182
+ cursor.execute('''
183
+ SELECT DISTINCT e.word
184
+ FROM entries e
185
+ JOIN senses s ON e.id = s.entry_id
186
+ JOIN sense_topics st ON s.id = st.sense_id
187
+ JOIN topics t ON st.topic_id = t.id
188
+ WHERE t.topic = 'biology'
189
+ LIMIT 20
190
+ ''')
191
+
192
+ print("Biology terms:", [row[0] for row in cursor.fetchall()])
193
+
194
+ # Example 7: Autocomplete search
195
+ cursor.execute('''
196
+ SELECT DISTINCT word
197
+ FROM entries
198
+ WHERE word LIKE ? AND lang = 'Deutsch'
199
+ ORDER BY word
200
+ LIMIT 10
201
+ ''', ('Sch%',))
202
+
203
+ print("Words starting with 'Sch':", [row[0] for row in cursor.fetchall()])
204
+
205
+ conn.close()
206
+ ```
207
+
208
+ ### Flutter/Dart
209
+ ```dart
210
+ import 'package:sqflite/sqflite.dart';
211
+ import 'package:http/http.dart' as http;
212
+ import 'package:path/path.dart';
213
+ import 'package:path_provider/path_provider.dart';
214
+ import 'dart:io';
215
+ import 'package:archive/archive_io.dart';
216
+
217
+ class WiktionaryDB {
218
+ static Database? _database;
219
+
220
+ Future<Database> get database async {
221
+ if (_database != null) return _database!;
222
+ _database = await initDB();
223
+ return _database!;
224
+ }
225
+
226
+ Future<Database> initDB() async {
227
+ final dir = await getApplicationDocumentsDirectory();
228
+ final dbPath = join(dir.path, 'de_wiktionary.db');
229
+
230
+ // Download and decompress on first run
231
+ if (!await File(dbPath).exists()) {
232
+ final url = 'https://huggingface.co/datasets/cstr/de-wiktionary-sqlite-normalized/resolve/main/de_wiktionary_normalized.db';
233
+
234
+ print('Downloading database...');
235
+ final response = await http.get(Uri.parse(url));
236
+
237
+ final gzPath = join(dir.path, 'de_wiktionary.db.gz');
238
+ await File(gzPath).writeAsBytes(response.bodyBytes);
239
+
240
+ print('Decompressing...');
241
+ final gzFile = File(gzPath);
242
+ final dbFile = File(dbPath);
243
+
244
+ // Decompress gzip
245
+ final bytes = gzFile.readAsBytesSync();
246
+ final archive = GZipDecoder().decodeBytes(bytes);
247
+ await dbFile.writeAsBytes(archive);
248
+
249
+ // Clean up
250
+ await gzFile.delete();
251
+ print('Database ready!');
252
+ }
253
+
254
+ return await openDatabase(dbPath, version: 1);
255
+ }
256
+
257
+ // Get word forms with grammatical tags
258
+ Future<List<Map<String, dynamic>>> getWordForms(String word) async {
259
+ final db = await database;
260
+ return await db.rawQuery('''
261
+ SELECT f.form_text, GROUP_CONCAT(t.tag, ', ') as tags
262
+ FROM entries e
263
+ JOIN forms f ON e.id = f.entry_id
264
+ LEFT JOIN form_tags ft ON f.id = ft.form_id
265
+ LEFT JOIN tags t ON ft.tag_id = t.id
266
+ WHERE e.word = ? AND e.lang = 'Deutsch'
267
+ GROUP BY f.id
268
+ ''', [word]);
269
+ }
270
+
271
+ // Get synonyms
272
+ Future<List<String>> getSynonyms(String word) async {
273
+ final db = await database;
274
+ final results = await db.rawQuery('''
275
+ SELECT s.synonym_word
276
+ FROM entries e
277
+ JOIN synonyms s ON e.id = s.entry_id
278
+ WHERE e.word = ? AND e.lang = 'Deutsch'
279
+ ''', [word]);
280
+ return results.map((r) => r['synonym_word'] as String).toList();
281
+ }
282
+
283
+ // Get IPA pronunciation
284
+ Future<List<String>> getIPA(String word) async {
285
+ final db = await database;
286
+ final results = await db.rawQuery('''
287
+ SELECT s.ipa
288
+ FROM entries e
289
+ JOIN sounds s ON e.id = s.entry_id
290
+ WHERE e.word = ? AND s.ipa IS NOT NULL
291
+ ''', [word]);
292
+ return results.map((r) => r['ipa'] as String).toList();
293
+ }
294
+
295
+ // Get definitions
296
+ Future<List<String>> getDefinitions(String word) async {
297
+ final db = await database;
298
+ final results = await db.rawQuery('''
299
+ SELECT g.gloss_text
300
+ FROM entries e
301
+ JOIN senses se ON e.id = se.entry_id
302
+ JOIN glosses g ON se.id = g.sense_id
303
+ WHERE e.word = ? AND e.lang = 'Deutsch'
304
+ ''', [word]);
305
+ return results.map((r) => r['gloss_text'] as String).toList();
306
+ }
307
+
308
+ // Autocomplete search
309
+ Future<List<String>> searchWords(String prefix) async {
310
+ final db = await database;
311
+ final results = await db.rawQuery('''
312
+ SELECT DISTINCT word
313
+ FROM entries
314
+ WHERE word LIKE ? AND lang = 'Deutsch'
315
+ ORDER BY word
316
+ LIMIT 20
317
+ ''', ['$prefix%']);
318
+ return results.map((r) => r['word'] as String).toList();
319
+ }
320
+ }
321
+ ```
322
+
323
+ ## πŸ” Example Queries
324
+
325
+ ### Get complete grammatical analysis
326
+ ```sql
327
+ SELECT
328
+ e.word,
329
+ f.form_text,
330
+ GROUP_CONCAT(DISTINCT t.tag) as grammatical_tags,
331
+ s.ipa
332
+ FROM entries e
333
+ JOIN forms f ON e.id = f.entry_id
334
+ LEFT JOIN form_tags ft ON f.id = ft.form_id
335
+ LEFT JOIN tags t ON ft.tag_id = t.id
336
+ LEFT JOIN sounds s ON e.id = s.entry_id
337
+ WHERE e.word = 'lieben'
338
+ GROUP BY f.id;
339
+ ```
340
+
341
+ ### Find words by grammatical features
342
+ ```sql
343
+ SELECT DISTINCT e.word
344
+ FROM entries e
345
+ JOIN forms f ON e.id = f.entry_id
346
+ JOIN form_tags ft ON f.id = ft.form_id
347
+ JOIN tags t ON ft.tag_id = t.id
348
+ WHERE t.tag = 'irregular' AND e.pos = 'verb'
349
+ LIMIT 100;
350
+ ```
351
+
352
+ ### Get words with semantic relationships
353
+ ```sql
354
+ SELECT
355
+ e.word,
356
+ s.synonym_word,
357
+ a.antonym_word
358
+ FROM entries e
359
+ LEFT JOIN synonyms s ON e.id = s.entry_id
360
+ LEFT JOIN antonyms a ON e.id = a.entry_id
361
+ WHERE e.word = 'gut';
362
+ ```
363
+
364
+ ## πŸ“± Platform Support
365
+
366
+ - **iOS**: βœ… Full support via sqflite
367
+ - **Android**: βœ… Full support via sqflite
368
+ - **Windows**: βœ… Via sqflite_common_ffi
369
+ - **macOS**: βœ… Via sqflite_common_ffi
370
+ - **Linux**: βœ… Via sqflite_common_ffi
371
+ - **Web**: ⚠️ Via sql.js (WASM)
372
+
373
+ ## πŸš€ Performance
374
+
375
+ Typical query times (modern hardware):
376
+ - Word lookup: < 1ms
377
+ - Get all forms: < 5ms
378
+ - Complex multi-table joins: < 20ms
379
+ - Autocomplete search: < 10ms
380
+
381
+ ## πŸ”— Source
382
+
383
+ Original data: [cstr/de-wiktionary-extracted](https://huggingface.co/datasets/cstr/de-wiktionary-extracted)
384
+
385
+ ## πŸ“œ License
386
+
387
+ CC-BY-SA 3.0 (same as source)
388
+
389
+ ## πŸ› οΈ Technical Details
390
+
391
+ - **SQLite Version**: 3.x compatible
392
+ - **Encoding**: UTF-8
393
+ - **Foreign Keys**: Enabled
394
+ - **Indexes**: 38 indexes for optimal performance
395
+ - **Normalization**: 3NF with deduplicated tags/topics/categories
396
+
397
+ ## πŸ“Š Schema Overview
398
+ ```
399
+ entries (970K rows)
400
+ β”œβ”€β”€ senses (3.1M) β†’ glosses (3.1M)
401
+ β”œβ”€β”€ forms (6.1M) β†’ form_tags (26M) β†’ tags (185)
402
+ β”œβ”€β”€ sounds (2.3M) β†’ sound_tags
403
+ β”œβ”€β”€ translations (1.1M) β†’ translation_tags
404
+ β”œβ”€β”€ synonyms (162K) β†’ synonym_tags
405
+ β”œβ”€β”€ antonyms
406
+ └── hyphenations (954K)
407
+ ```
408
+
409
+ ## 🀝 Contributing
410
+
411
+ Found an issue? Please report it on the source dataset repository.