ethnidata 2.0.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 NBD Database Team
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.
@@ -0,0 +1,12 @@
1
+ # Include package data
2
+ include README.md
3
+ include LICENSE
4
+ include requirements.txt
5
+
6
+ # Include database (if not too large)
7
+ recursive-include nbd *.db
8
+
9
+ # Exclude unnecessary files
10
+ global-exclude __pycache__
11
+ global-exclude *.py[co]
12
+ global-exclude .DS_Store
@@ -0,0 +1,257 @@
1
+ Metadata-Version: 2.4
2
+ Name: ethnidata
3
+ Version: 2.0.0
4
+ Summary: Predict nationality, ethnicity, gender, region, language and religion from names - 238 countries, 5 continents, 415K+ names, enhanced religious coverage
5
+ Author-email: Tefik Yavuz Oz <teyfikoz@example.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/teyfikoz/ethnidata
8
+ Project-URL: Documentation, https://github.com/teyfikoz/ethnidata#readme
9
+ Project-URL: Repository, https://github.com/teyfikoz/ethnidata.git
10
+ Project-URL: Issues, https://github.com/teyfikoz/ethnidata/issues
11
+ Keywords: names,nationality,ethnicity,demographics,prediction,NLP
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Requires-Python: >=3.8
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: pycountry>=22.3.5
26
+ Requires-Dist: unidecode>=1.3.6
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
29
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
30
+ Provides-Extra: build
31
+ Requires-Dist: requests>=2.31.0; extra == "build"
32
+ Requires-Dist: pandas>=2.0.0; extra == "build"
33
+ Requires-Dist: numpy>=1.24.0; extra == "build"
34
+ Requires-Dist: beautifulsoup4>=4.12.0; extra == "build"
35
+ Requires-Dist: lxml>=4.9.0; extra == "build"
36
+ Requires-Dist: tqdm>=4.65.0; extra == "build"
37
+ Requires-Dist: wikipedia-api>=0.6.0; extra == "build"
38
+ Requires-Dist: sqlalchemy>=2.0.0; extra == "build"
39
+ Dynamic: license-file
40
+
41
+ # EthniData - Ethnicity and Nationality Prediction
42
+
43
+ [![Python](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
44
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
45
+ [![PyPI version](https://badge.fury.io/py/ethnidata.svg)](https://badge.fury.io/py/ethnidata)
46
+
47
+ Predict **nationality**, **ethnicity**, and **demographics** from names using a comprehensive global database built from multiple authoritative sources.
48
+
49
+ ## 🌟 Features
50
+
51
+ - **190+ Countries** - Comprehensive coverage from Wikipedia/Wikidata
52
+ - **106 Countries** - Enhanced with names-dataset
53
+ - **120 Years** of Olympic athlete names
54
+ - **Multiple Sources** - Phone directories, census data, public records
55
+ - **Fast Predictions** - SQLite-based for instant lookups
56
+ - **Normalized Data** - Unicode-aware, case-insensitive matching
57
+ - **Ethnicity Support** - Where available in source data
58
+ - **Simple API** - Easy to use Python interface
59
+
60
+ ## 📊 Data Sources
61
+
62
+ 1. **Wikipedia/Wikidata** - 190+ countries, biographical data with ethnicity
63
+ 2. **names-dataset** - 106 countries, curated name lists
64
+ 3. **Olympics Dataset** - 120 years of athlete names (271,116 records)
65
+ 4. **Phone Directories** - Public domain name lists from multiple countries
66
+ 5. **Census Data** - US Census and other government open data
67
+
68
+ ## 🚀 Installation
69
+
70
+ ```bash
71
+ pip install ethnidata
72
+ ```
73
+
74
+ ## 📖 Usage
75
+
76
+ ### Basic Usage
77
+
78
+ ```python
79
+ from ethnidata import EthniData
80
+
81
+ # Initialize
82
+ ed = EthniData()
83
+
84
+ # Predict nationality from first name
85
+ result = ed.predict_nationality("Ahmet", name_type="first")
86
+ print(result)
87
+ # {
88
+ # 'name': 'ahmet',
89
+ # 'country': 'TUR',
90
+ # 'country_name': 'Turkey',
91
+ # 'confidence': 0.89,
92
+ # 'top_countries': [
93
+ # {'country': 'TUR', 'country_name': 'Turkey', 'probability': 0.89},
94
+ # {'country': 'DEU', 'country_name': 'Germany', 'probability': 0.07},
95
+ # ...
96
+ # ]
97
+ # }
98
+
99
+ # Predict from last name
100
+ result = ed.predict_nationality("Tanaka", name_type="last")
101
+ print(result['country']) # 'JPN'
102
+
103
+ # Predict from full name (combines both)
104
+ result = ed.predict_full_name("Wei", "Chen")
105
+ print(result['country']) # 'CHN'
106
+
107
+ # Predict ethnicity (when available)
108
+ result = ed.predict_ethnicity("Muhammad", name_type="first")
109
+ print(result)
110
+ # {
111
+ # 'name': 'muhammad',
112
+ # 'ethnicity': 'Arab',
113
+ # 'country': 'SAU',
114
+ # 'country_name': 'Saudi Arabia'
115
+ # }
116
+ ```
117
+
118
+ ### Advanced Usage
119
+
120
+ ```python
121
+ # Get top 10 predictions
122
+ result = ed.predict_nationality("Maria", name_type="first", top_n=10)
123
+
124
+ for country in result['top_countries']:
125
+ print(f"{country['country_name']}: {country['probability']:.2%}")
126
+ # Spain: 35.4%
127
+ # Italy: 28.2%
128
+ # Portugal: 15.1%
129
+ # ...
130
+
131
+ # Database statistics
132
+ stats = ed.get_stats()
133
+ print(stats)
134
+ # {
135
+ # 'total_first_names': 123456,
136
+ # 'total_last_names': 234567,
137
+ # 'countries_first': 195,
138
+ # 'countries_last': 198
139
+ # }
140
+ ```
141
+
142
+ ## 🏗️ Project Structure
143
+
144
+ ```
145
+ ethnidata/
146
+ ├── ethnidata/ # Main package
147
+ │ ├── __init__.py
148
+ │ ├── predictor.py # Core prediction logic
149
+ │ └── ethnidata.db # SQLite database
150
+ ├── scripts/ # Data collection scripts
151
+ │ ├── 1_fetch_names_dataset.py
152
+ │ ├── 2_fetch_wikipedia.py
153
+ │ ├── 3_fetch_olympics.py
154
+ │ ├── 4_fetch_phone_directories.py
155
+ │ ├── 5_merge_all_data.py
156
+ │ └── 6_create_database.py
157
+ ├── tests/ # Unit tests
158
+ ├── examples/ # Example scripts
159
+ ├── docs/ # Documentation
160
+ ├── setup.py
161
+ ├── pyproject.toml
162
+ └── README.md
163
+ ```
164
+
165
+ ## 🔬 Accuracy & Methodology
166
+
167
+ ### How it works
168
+
169
+ 1. **Name Normalization**: Names are lowercased and Unicode-normalized (e.g., "José" → "jose")
170
+ 2. **Database Lookup**: Queries SQLite database for matching names
171
+ 3. **Frequency-Based Scoring**: Countries are ranked by how often the name appears
172
+ 4. **Probability Calculation**: Frequencies are converted to probabilities
173
+ 5. **Full Name Combination**: First name (40%) + last name (60%) weights
174
+
175
+ ### Limitations
176
+
177
+ - **Bias**: Database reflects historical Olympic participation, Wikipedia coverage
178
+ - **Missing Names**: Rare or new names may not be in database
179
+ - **Ethnicity**: Only available where source data included it
180
+ - **Migration**: Doesn't account for diaspora or modern migration patterns
181
+ - **Multiple Origins**: Common names (e.g., "Ali", "Maria") exist in many cultures
182
+
183
+ ## 🛠️ Development
184
+
185
+ ### Build Database from Scratch
186
+
187
+ ```bash
188
+ git clone https://github.com/teyfikoz/ethnidata.git
189
+ cd ethnidata
190
+
191
+ # Install dependencies
192
+ pip install -r requirements.txt
193
+
194
+ # Fetch all data (takes 10-30 minutes)
195
+ cd scripts
196
+ python 1_fetch_names_dataset.py
197
+ python 2_fetch_wikipedia.py
198
+ python 3_fetch_olympics.py
199
+ python 4_fetch_phone_directories.py
200
+ python 5_merge_all_data.py
201
+ python 6_create_database.py
202
+ ```
203
+
204
+ ### Run Tests
205
+
206
+ ```bash
207
+ pip install -e ".[dev]"
208
+ pytest tests/ -v
209
+ ```
210
+
211
+ ## 📜 License
212
+
213
+ MIT License - see [LICENSE](LICENSE) file for details
214
+
215
+ ## 🤝 Contributing
216
+
217
+ Contributions welcome! Please:
218
+
219
+ 1. Fork the repository
220
+ 2. Create a feature branch
221
+ 3. Commit your changes
222
+ 4. Push to the branch
223
+ 5. Open a Pull Request
224
+
225
+ ## 📚 Citations
226
+
227
+ If you use this database in research, please cite:
228
+
229
+ ```bibtex
230
+ @software{ethnidata_2024,
231
+ title = {EthniData: Ethnicity and Nationality Prediction from Names},
232
+ author = {Oz, Tefik Yavuz},
233
+ year = {2024},
234
+ url = {https://github.com/teyfikoz/ethnidata}
235
+ }
236
+ ```
237
+
238
+ ### Data Source Citations
239
+
240
+ - **Olympics Data**: Randi Griffin (2018). 120 years of Olympic history. [Kaggle](https://www.kaggle.com/datasets/heesoo37/120-years-of-olympic-history-athletes-and-results)
241
+ - **names-dataset**: Philippe Remy (2021). [name-dataset](https://github.com/philipperemy/name-dataset)
242
+ - **Wikidata**: Wikimedia Foundation. [Wikidata](https://www.wikidata.org)
243
+
244
+ ## 🔗 Related Projects
245
+
246
+ - [ethnicolr](https://github.com/appeler/ethnicolr) - Ethnicity prediction using LSTM
247
+ - [name-dataset](https://github.com/philipperemy/name-dataset) - Name database (106 countries)
248
+ - [gender-guesser](https://github.com/lead-ratings/gender-guesser) - Gender prediction
249
+
250
+ ## 📧 Contact
251
+
252
+ - GitHub Issues: [Report bugs or request features](https://github.com/teyfikoz/ethnidata/issues)
253
+ - GitHub: [@teyfikoz](https://github.com/teyfikoz)
254
+
255
+ ---
256
+
257
+ **Built with ❤️ using open data**
@@ -0,0 +1,217 @@
1
+ # EthniData - Ethnicity and Nationality Prediction
2
+
3
+ [![Python](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![PyPI version](https://badge.fury.io/py/ethnidata.svg)](https://badge.fury.io/py/ethnidata)
6
+
7
+ Predict **nationality**, **ethnicity**, and **demographics** from names using a comprehensive global database built from multiple authoritative sources.
8
+
9
+ ## 🌟 Features
10
+
11
+ - **190+ Countries** - Comprehensive coverage from Wikipedia/Wikidata
12
+ - **106 Countries** - Enhanced with names-dataset
13
+ - **120 Years** of Olympic athlete names
14
+ - **Multiple Sources** - Phone directories, census data, public records
15
+ - **Fast Predictions** - SQLite-based for instant lookups
16
+ - **Normalized Data** - Unicode-aware, case-insensitive matching
17
+ - **Ethnicity Support** - Where available in source data
18
+ - **Simple API** - Easy to use Python interface
19
+
20
+ ## 📊 Data Sources
21
+
22
+ 1. **Wikipedia/Wikidata** - 190+ countries, biographical data with ethnicity
23
+ 2. **names-dataset** - 106 countries, curated name lists
24
+ 3. **Olympics Dataset** - 120 years of athlete names (271,116 records)
25
+ 4. **Phone Directories** - Public domain name lists from multiple countries
26
+ 5. **Census Data** - US Census and other government open data
27
+
28
+ ## 🚀 Installation
29
+
30
+ ```bash
31
+ pip install ethnidata
32
+ ```
33
+
34
+ ## 📖 Usage
35
+
36
+ ### Basic Usage
37
+
38
+ ```python
39
+ from ethnidata import EthniData
40
+
41
+ # Initialize
42
+ ed = EthniData()
43
+
44
+ # Predict nationality from first name
45
+ result = ed.predict_nationality("Ahmet", name_type="first")
46
+ print(result)
47
+ # {
48
+ # 'name': 'ahmet',
49
+ # 'country': 'TUR',
50
+ # 'country_name': 'Turkey',
51
+ # 'confidence': 0.89,
52
+ # 'top_countries': [
53
+ # {'country': 'TUR', 'country_name': 'Turkey', 'probability': 0.89},
54
+ # {'country': 'DEU', 'country_name': 'Germany', 'probability': 0.07},
55
+ # ...
56
+ # ]
57
+ # }
58
+
59
+ # Predict from last name
60
+ result = ed.predict_nationality("Tanaka", name_type="last")
61
+ print(result['country']) # 'JPN'
62
+
63
+ # Predict from full name (combines both)
64
+ result = ed.predict_full_name("Wei", "Chen")
65
+ print(result['country']) # 'CHN'
66
+
67
+ # Predict ethnicity (when available)
68
+ result = ed.predict_ethnicity("Muhammad", name_type="first")
69
+ print(result)
70
+ # {
71
+ # 'name': 'muhammad',
72
+ # 'ethnicity': 'Arab',
73
+ # 'country': 'SAU',
74
+ # 'country_name': 'Saudi Arabia'
75
+ # }
76
+ ```
77
+
78
+ ### Advanced Usage
79
+
80
+ ```python
81
+ # Get top 10 predictions
82
+ result = ed.predict_nationality("Maria", name_type="first", top_n=10)
83
+
84
+ for country in result['top_countries']:
85
+ print(f"{country['country_name']}: {country['probability']:.2%}")
86
+ # Spain: 35.4%
87
+ # Italy: 28.2%
88
+ # Portugal: 15.1%
89
+ # ...
90
+
91
+ # Database statistics
92
+ stats = ed.get_stats()
93
+ print(stats)
94
+ # {
95
+ # 'total_first_names': 123456,
96
+ # 'total_last_names': 234567,
97
+ # 'countries_first': 195,
98
+ # 'countries_last': 198
99
+ # }
100
+ ```
101
+
102
+ ## 🏗️ Project Structure
103
+
104
+ ```
105
+ ethnidata/
106
+ ├── ethnidata/ # Main package
107
+ │ ├── __init__.py
108
+ │ ├── predictor.py # Core prediction logic
109
+ │ └── ethnidata.db # SQLite database
110
+ ├── scripts/ # Data collection scripts
111
+ │ ├── 1_fetch_names_dataset.py
112
+ │ ├── 2_fetch_wikipedia.py
113
+ │ ├── 3_fetch_olympics.py
114
+ │ ├── 4_fetch_phone_directories.py
115
+ │ ├── 5_merge_all_data.py
116
+ │ └── 6_create_database.py
117
+ ├── tests/ # Unit tests
118
+ ├── examples/ # Example scripts
119
+ ├── docs/ # Documentation
120
+ ├── setup.py
121
+ ├── pyproject.toml
122
+ └── README.md
123
+ ```
124
+
125
+ ## 🔬 Accuracy & Methodology
126
+
127
+ ### How it works
128
+
129
+ 1. **Name Normalization**: Names are lowercased and Unicode-normalized (e.g., "José" → "jose")
130
+ 2. **Database Lookup**: Queries SQLite database for matching names
131
+ 3. **Frequency-Based Scoring**: Countries are ranked by how often the name appears
132
+ 4. **Probability Calculation**: Frequencies are converted to probabilities
133
+ 5. **Full Name Combination**: First name (40%) + last name (60%) weights
134
+
135
+ ### Limitations
136
+
137
+ - **Bias**: Database reflects historical Olympic participation, Wikipedia coverage
138
+ - **Missing Names**: Rare or new names may not be in database
139
+ - **Ethnicity**: Only available where source data included it
140
+ - **Migration**: Doesn't account for diaspora or modern migration patterns
141
+ - **Multiple Origins**: Common names (e.g., "Ali", "Maria") exist in many cultures
142
+
143
+ ## 🛠️ Development
144
+
145
+ ### Build Database from Scratch
146
+
147
+ ```bash
148
+ git clone https://github.com/teyfikoz/ethnidata.git
149
+ cd ethnidata
150
+
151
+ # Install dependencies
152
+ pip install -r requirements.txt
153
+
154
+ # Fetch all data (takes 10-30 minutes)
155
+ cd scripts
156
+ python 1_fetch_names_dataset.py
157
+ python 2_fetch_wikipedia.py
158
+ python 3_fetch_olympics.py
159
+ python 4_fetch_phone_directories.py
160
+ python 5_merge_all_data.py
161
+ python 6_create_database.py
162
+ ```
163
+
164
+ ### Run Tests
165
+
166
+ ```bash
167
+ pip install -e ".[dev]"
168
+ pytest tests/ -v
169
+ ```
170
+
171
+ ## 📜 License
172
+
173
+ MIT License - see [LICENSE](LICENSE) file for details
174
+
175
+ ## 🤝 Contributing
176
+
177
+ Contributions welcome! Please:
178
+
179
+ 1. Fork the repository
180
+ 2. Create a feature branch
181
+ 3. Commit your changes
182
+ 4. Push to the branch
183
+ 5. Open a Pull Request
184
+
185
+ ## 📚 Citations
186
+
187
+ If you use this database in research, please cite:
188
+
189
+ ```bibtex
190
+ @software{ethnidata_2024,
191
+ title = {EthniData: Ethnicity and Nationality Prediction from Names},
192
+ author = {Oz, Tefik Yavuz},
193
+ year = {2024},
194
+ url = {https://github.com/teyfikoz/ethnidata}
195
+ }
196
+ ```
197
+
198
+ ### Data Source Citations
199
+
200
+ - **Olympics Data**: Randi Griffin (2018). 120 years of Olympic history. [Kaggle](https://www.kaggle.com/datasets/heesoo37/120-years-of-olympic-history-athletes-and-results)
201
+ - **names-dataset**: Philippe Remy (2021). [name-dataset](https://github.com/philipperemy/name-dataset)
202
+ - **Wikidata**: Wikimedia Foundation. [Wikidata](https://www.wikidata.org)
203
+
204
+ ## 🔗 Related Projects
205
+
206
+ - [ethnicolr](https://github.com/appeler/ethnicolr) - Ethnicity prediction using LSTM
207
+ - [name-dataset](https://github.com/philipperemy/name-dataset) - Name database (106 countries)
208
+ - [gender-guesser](https://github.com/lead-ratings/gender-guesser) - Gender prediction
209
+
210
+ ## 📧 Contact
211
+
212
+ - GitHub Issues: [Report bugs or request features](https://github.com/teyfikoz/ethnidata/issues)
213
+ - GitHub: [@teyfikoz](https://github.com/teyfikoz)
214
+
215
+ ---
216
+
217
+ **Built with ❤️ using open data**
@@ -0,0 +1,59 @@
1
+ """
2
+ EthniData v2.0.0 - MASSIVE UPDATE! Global Demographics Prediction
3
+ Predict nationality, ethnicity, gender, region, language AND religion!
4
+
5
+ 🔥 NEW in v2.0.0 - MASSIVE DATABASE EXPANSION:
6
+ - 📊 **415K+ records** (88% increase from 220K)
7
+ - 🌍 **238 countries** (up from 165)
8
+ - 🗣️ **72 languages** (up from 46)
9
+ - 🕌 **Enhanced religious coverage** - More balanced distribution!
10
+ - Islam: 69K+ records (was 2.8K)
11
+ - Christianity: 122K+ records
12
+ - Hinduism: 3.9K+ records (was 171)
13
+ - Buddhism: 6.8K+ records (was 490)
14
+ - Judaism: 4.8K+ records (was 3.5K)
15
+ - 🌎 **Better regional balance**:
16
+ - Europe: 37.6% • Americas: 32.3%
17
+ - Asia: 14.1% • Africa: 13.4% • Oceania: 2.0%
18
+
19
+ Features:
20
+ - ✅ Nationality prediction (238 countries)
21
+ - ✅ Religion prediction (5 major religions)
22
+ - ✅ Gender prediction
23
+ - ✅ Region prediction (5 continents)
24
+ - ✅ Language prediction (72 languages)
25
+ - ✅ Ethnicity prediction
26
+ - ✅ Full name analysis
27
+
28
+ Usage:
29
+ from ethnidata import EthniData
30
+
31
+ ed = EthniData()
32
+
33
+ # Nationality
34
+ result = ed.predict_nationality("Ahmet")
35
+
36
+ # Religion
37
+ result = ed.predict_religion("Muhammad")
38
+
39
+ # Gender
40
+ result = ed.predict_gender("Emma")
41
+
42
+ # Region
43
+ result = ed.predict_region("Chen")
44
+
45
+ # Language
46
+ result = ed.predict_language("José")
47
+
48
+ # ALL at once
49
+ result = ed.predict_all("Maria")
50
+ # Returns: nationality, religion, gender, region, language, ethnicity
51
+ """
52
+
53
+ __version__ = "2.0.0"
54
+ __author__ = "Tefik Yavuz Oz"
55
+ __license__ = "MIT"
56
+
57
+ from .predictor import EthniData
58
+
59
+ __all__ = ["EthniData"]
Binary file