File size: 12,750 Bytes
89b9a60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# World Languages - Interactive Demo\n",
        "\n",
        "Explore **7,130 world languages** with geographic coordinates, speaker populations, and language family classification.\n",
        "\n",
        "**Dataset Highlights:**\n",
        "- Geographic coordinates for mapping\n",
        "- Speaker population estimates\n",
        "- Language family classification (Glottolog)\n",
        "- Bible translation status (Joshua Project)\n",
        "- ISO 639-3 codes as primary keys"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Setup"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Uncomment to install dependencies\n",
        "# !pip install pandas matplotlib seaborn folium"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import json\n",
        "import pandas as pd\n",
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "import seaborn as sns\n",
        "from collections import Counter\n",
        "import warnings\n",
        "warnings.filterwarnings('ignore')\n",
        "\n",
        "plt.style.use('seaborn-v0_8-darkgrid')\n",
        "sns.set_palette('husl')\n",
        "\n",
        "print('Libraries loaded')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 1. Load Dataset"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "with open('world_languages_integrated.json') as f:\n",
        "    data = json.load(f)\n",
        "\n",
        "print(f'Total languages: {len(data):,}')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Flatten the nested structure for analysis\n",
        "records = []\n",
        "for lang in data:\n",
        "    record = {\n",
        "        'iso_639_3': lang.get('iso_639_3'),\n",
        "        'name': lang.get('name'),\n",
        "        'family': lang.get('glottolog', {}).get('family_name', 'Unknown'),\n",
        "        'macroarea': lang.get('glottolog', {}).get('macroarea', 'Unknown'),\n",
        "        'latitude': lang.get('glottolog', {}).get('latitude'),\n",
        "        'longitude': lang.get('glottolog', {}).get('longitude'),\n",
        "        'glottocode': lang.get('glottolog', {}).get('glottocode'),\n",
        "        'speakers': lang.get('speaker_count', {}).get('count') if lang.get('speaker_count') else None,\n",
        "        'religion': lang.get('joshua_project', {}).get('primary_religion', ''),\n",
        "        'bible_status': lang.get('joshua_project', {}).get('bible_status', 0),\n",
        "    }\n",
        "    records.append(record)\n",
        "\n",
        "df = pd.DataFrame(records)\n",
        "df.head()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 2. Dataset Overview"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "print('Dataset Overview:')\n",
        "print('=' * 50)\n",
        "print(f'Total languages: {len(df):,}')\n",
        "print(f'With coordinates: {df[\"latitude\"].notna().sum():,} ({df[\"latitude\"].notna().sum()/len(df)*100:.1f}%)')\n",
        "print(f'With speaker counts: {df[\"speakers\"].notna().sum():,} ({df[\"speakers\"].notna().sum()/len(df)*100:.1f}%)')\n",
        "print(f'Unique families: {df[\"family\"].nunique()}')\n",
        "print(f'Unique macroareas: {df[\"macroarea\"].nunique()}')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 3. Language Family Distribution"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Top 15 language families\n",
        "family_counts = df['family'].value_counts().head(15)\n",
        "\n",
        "print('Top 15 Language Families:')\n",
        "print('=' * 50)\n",
        "for family, count in family_counts.items():\n",
        "    pct = count / len(df) * 100\n",
        "    bar = '|' * int(pct)\n",
        "    print(f'{family:30s} {count:5,} ({pct:5.1f}%) {bar}')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "fig, ax = plt.subplots(figsize=(12, 8))\n",
        "family_counts.plot(kind='barh', ax=ax, color='steelblue')\n",
        "ax.set_xlabel('Number of Languages', fontsize=12)\n",
        "ax.set_ylabel('Language Family', fontsize=12)\n",
        "ax.set_title('Top 15 Language Families', fontsize=14, fontweight='bold')\n",
        "ax.grid(axis='x', alpha=0.3)\n",
        "plt.tight_layout()\n",
        "plt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 4. Geographic Distribution"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Macroarea distribution\n",
        "macroarea_counts = df['macroarea'].value_counts()\n",
        "\n",
        "print('Languages by Macroarea:')\n",
        "print('=' * 50)\n",
        "for area, count in macroarea_counts.items():\n",
        "    pct = count / len(df) * 100\n",
        "    print(f'{area:20s} {count:5,} ({pct:5.1f}%)')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Plot languages on world map\n",
        "valid_coords = df[df['latitude'].notna() & df['longitude'].notna()]\n",
        "\n",
        "fig, ax = plt.subplots(figsize=(16, 8))\n",
        "scatter = ax.scatter(\n",
        "    valid_coords['longitude'],\n",
        "    valid_coords['latitude'],\n",
        "    c=pd.factorize(valid_coords['macroarea'])[0],\n",
        "    alpha=0.5,\n",
        "    s=5,\n",
        "    cmap='tab10'\n",
        ")\n",
        "ax.set_xlabel('Longitude', fontsize=12)\n",
        "ax.set_ylabel('Latitude', fontsize=12)\n",
        "ax.set_title('Global Distribution of Languages', fontsize=14, fontweight='bold')\n",
        "ax.grid(alpha=0.3)\n",
        "plt.tight_layout()\n",
        "plt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 5. Speaker Populations"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Top 20 languages by speakers\n",
        "with_speakers = df[df['speakers'].notna()].copy()\n",
        "top_speakers = with_speakers.nlargest(20, 'speakers')[['name', 'family', 'speakers']]\n",
        "\n",
        "print('Top 20 Languages by Speaker Count:')\n",
        "print('=' * 60)\n",
        "for idx, row in top_speakers.iterrows():\n",
        "    speakers_m = row['speakers'] / 1_000_000\n",
        "    print(f\"{row['name']:25s} {row['family']:25s} {speakers_m:8.1f}M\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Speaker distribution (log scale)\n",
        "fig, ax = plt.subplots(figsize=(12, 6))\n",
        "with_speakers['speakers'].apply(np.log10).hist(bins=50, ax=ax, color='teal', edgecolor='white')\n",
        "ax.set_xlabel('Speakers (log10 scale)', fontsize=12)\n",
        "ax.set_ylabel('Number of Languages', fontsize=12)\n",
        "ax.set_title('Distribution of Speaker Populations', fontsize=14, fontweight='bold')\n",
        "ax.set_xticks([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n",
        "ax.set_xticklabels(['1', '10', '100', '1K', '10K', '100K', '1M', '10M', '100M', '1B'])\n",
        "plt.tight_layout()\n",
        "plt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 6. Bible Translation Status"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Bible translation status\n",
        "bible_labels = {\n",
        "    0: 'Unspecified',\n",
        "    1: 'Translation Needed',\n",
        "    2: 'Translation Started',\n",
        "    3: 'Portions Available',\n",
        "    4: 'New Testament',\n",
        "    5: 'Complete Bible'\n",
        "}\n",
        "\n",
        "df['bible_label'] = df['bible_status'].map(bible_labels)\n",
        "bible_counts = df['bible_label'].value_counts()\n",
        "\n",
        "print('Bible Translation Status:')\n",
        "print('=' * 50)\n",
        "for status, count in bible_counts.items():\n",
        "    pct = count / len(df) * 100\n",
        "    print(f'{status:25s} {count:5,} ({pct:5.1f}%)')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 7. Interactive Map"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import folium\n",
        "from folium.plugins import MarkerCluster\n",
        "\n",
        "# Sample for performance\n",
        "sample = valid_coords.sample(min(1000, len(valid_coords)))\n",
        "\n",
        "m = folium.Map(location=[20, 0], zoom_start=2, tiles='CartoDB positron')\n",
        "marker_cluster = MarkerCluster().add_to(m)\n",
        "\n",
        "for idx, row in sample.iterrows():\n",
        "    popup = f\"<b>{row['name']}</b><br>Family: {row['family']}<br>Macroarea: {row['macroarea']}\"\n",
        "    folium.CircleMarker(\n",
        "        location=[row['latitude'], row['longitude']],\n",
        "        radius=4,\n",
        "        popup=popup,\n",
        "        color='steelblue',\n",
        "        fill=True,\n",
        "        fillOpacity=0.6\n",
        "    ).add_to(marker_cluster)\n",
        "\n",
        "m.save('languages_map.html')\n",
        "print('Map saved to languages_map.html')\n",
        "m"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 8. Query Examples"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Find all Indo-European languages\n",
        "indo_european = df[df['family'] == 'Indo-European']\n",
        "print(f'Indo-European languages: {len(indo_european):,}')\n",
        "print(indo_european[['name', 'macroarea', 'speakers']].head(10))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Find endangered languages (small speaker populations)\n",
        "endangered = df[(df['speakers'].notna()) & (df['speakers'] < 1000)]\n",
        "print(f'Languages with <1000 speakers: {len(endangered):,}')\n",
        "print(endangered[['name', 'family', 'speakers']].head(10))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Languages in Africa\n",
        "africa = df[df['macroarea'] == 'Africa']\n",
        "africa_families = africa['family'].value_counts().head(10)\n",
        "print(f'Languages in Africa: {len(africa):,}')\n",
        "print('\\nTop families in Africa:')\n",
        "print(africa_families)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Conclusion\n",
        "\n",
        "This notebook demonstrated:\n",
        "\n",
        "- Loading and exploring 7,130 world languages\n",
        "- Analyzing language family distributions\n",
        "- Mapping geographic distributions\n",
        "- Exploring speaker populations\n",
        "- Querying by region and attributes\n",
        "\n",
        "**Author**: Luke Steuber | luke@lukesteuber.com | @lukesteuber.com (Bluesky)"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.10.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}