travelpurpose 0.1.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.
Files changed (38) hide show
  1. travelpurpose-0.1.0/LICENSE +21 -0
  2. travelpurpose-0.1.0/PKG-INFO +336 -0
  3. travelpurpose-0.1.0/README.md +284 -0
  4. travelpurpose-0.1.0/pyproject.toml +93 -0
  5. travelpurpose-0.1.0/setup.cfg +4 -0
  6. travelpurpose-0.1.0/tests/test_api.py +68 -0
  7. travelpurpose-0.1.0/tests/test_normalize.py +75 -0
  8. travelpurpose-0.1.0/tests/test_scoring.py +102 -0
  9. travelpurpose-0.1.0/travelpurpose/__init__.py +13 -0
  10. travelpurpose-0.1.0/travelpurpose/classifier.py +258 -0
  11. travelpurpose-0.1.0/travelpurpose/cli.py +214 -0
  12. travelpurpose-0.1.0/travelpurpose/data/cities.json +136 -0
  13. travelpurpose-0.1.0/travelpurpose/data/cities.parquet +0 -0
  14. travelpurpose-0.1.0/travelpurpose/data/wikidata_cities_cache.json +8138 -0
  15. travelpurpose-0.1.0/travelpurpose/ontology/mapping_nbd.yaml +81 -0
  16. travelpurpose-0.1.0/travelpurpose/ontology/ontology.yaml +319 -0
  17. travelpurpose-0.1.0/travelpurpose/tags.py +159 -0
  18. travelpurpose-0.1.0/travelpurpose/utils/__init__.py +15 -0
  19. travelpurpose-0.1.0/travelpurpose/utils/agoda.py +66 -0
  20. travelpurpose-0.1.0/travelpurpose/utils/booking.py +71 -0
  21. travelpurpose-0.1.0/travelpurpose/utils/geonames.py +272 -0
  22. travelpurpose-0.1.0/travelpurpose/utils/harvest.py +332 -0
  23. travelpurpose-0.1.0/travelpurpose/utils/io.py +244 -0
  24. travelpurpose-0.1.0/travelpurpose/utils/kayak.py +65 -0
  25. travelpurpose-0.1.0/travelpurpose/utils/normalize.py +330 -0
  26. travelpurpose-0.1.0/travelpurpose/utils/opentripmap.py +233 -0
  27. travelpurpose-0.1.0/travelpurpose/utils/restcountries.py +137 -0
  28. travelpurpose-0.1.0/travelpurpose/utils/scoring.py +229 -0
  29. travelpurpose-0.1.0/travelpurpose/utils/skyscanner.py +96 -0
  30. travelpurpose-0.1.0/travelpurpose/utils/tripdotcom.py +65 -0
  31. travelpurpose-0.1.0/travelpurpose/utils/trivago.py +65 -0
  32. travelpurpose-0.1.0/travelpurpose/utils/wikidata.py +280 -0
  33. travelpurpose-0.1.0/travelpurpose.egg-info/PKG-INFO +336 -0
  34. travelpurpose-0.1.0/travelpurpose.egg-info/SOURCES.txt +36 -0
  35. travelpurpose-0.1.0/travelpurpose.egg-info/dependency_links.txt +1 -0
  36. travelpurpose-0.1.0/travelpurpose.egg-info/entry_points.txt +2 -0
  37. travelpurpose-0.1.0/travelpurpose.egg-info/requires.txt +27 -0
  38. travelpurpose-0.1.0/travelpurpose.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Travel Purpose 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.
@@ -0,0 +1,336 @@
1
+ Metadata-Version: 2.4
2
+ Name: travelpurpose
3
+ Version: 0.1.0
4
+ Summary: Production-grade library for classifying world cities by travel purpose using multi-source data
5
+ Author: Travel Purpose Contributors
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/teyfikoz/Travel_Purpose-City_Tags
8
+ Project-URL: Documentation, https://github.com/teyfikoz/Travel_Purpose-City_Tags#readme
9
+ Project-URL: Repository, https://github.com/teyfikoz/Travel_Purpose-City_Tags
10
+ Project-URL: Bug Tracker, https://github.com/teyfikoz/Travel_Purpose-City_Tags/issues
11
+ Keywords: travel,city,classification,tourism,purpose,tags,data-engineering
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: pandas>=2.0.0
26
+ Requires-Dist: numpy>=1.24.0
27
+ Requires-Dist: pyarrow>=12.0.0
28
+ Requires-Dist: pyyaml>=6.0
29
+ Requires-Dist: requests>=2.31.0
30
+ Requires-Dist: requests-cache>=1.1.0
31
+ Requires-Dist: beautifulsoup4>=4.12.0
32
+ Requires-Dist: lxml>=4.9.0
33
+ Requires-Dist: pydantic>=2.0.0
34
+ Requires-Dist: typer>=0.9.0
35
+ Requires-Dist: rich>=13.0.0
36
+ Requires-Dist: tqdm>=4.65.0
37
+ Requires-Dist: sentence-transformers>=2.2.0
38
+ Requires-Dist: scikit-learn>=1.3.0
39
+ Requires-Dist: openpyxl>=3.1.0
40
+ Requires-Dist: SPARQLWrapper>=2.0.0
41
+ Requires-Dist: urllib3>=2.0.0
42
+ Requires-Dist: playwright>=1.40.0
43
+ Provides-Extra: dev
44
+ Requires-Dist: pytest>=7.4.0; extra == "dev"
45
+ Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
46
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
47
+ Requires-Dist: mypy>=1.5.0; extra == "dev"
48
+ Requires-Dist: black>=23.0.0; extra == "dev"
49
+ Requires-Dist: jupyterlab>=4.0.0; extra == "dev"
50
+ Requires-Dist: notebook>=7.0.0; extra == "dev"
51
+ Dynamic: license-file
52
+
53
+ # TravelPurpose
54
+
55
+ [![PyPI version](https://badge.fury.io/py/travelpurpose.svg)](https://badge.fury.io/py/travelpurpose)
56
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
57
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
58
+
59
+ A production-grade Python library for classifying world cities by travel purpose using multi-source data from public travel platforms and knowledge bases.
60
+
61
+ ## Features
62
+
63
+ - **Multi-Label Classification**: Cities can have multiple travel purposes (e.g., Business + Culture + Transit)
64
+ - **Rich Ontology**: 12 main categories and 70+ subcategories covering all travel purposes
65
+ - **Multi-Source Data**: Integrates data from Wikidata, Booking.com, Agoda, Trivago, Kayak, Trip.com, and Skyscanner
66
+ - **Hybrid Classifier**: Combines rule-based and embedding-based approaches with confidence scoring
67
+ - **Python API & CLI**: Easy-to-use programmatic and command-line interfaces
68
+ - **Ethical Data Collection**: Fully compliant with ToS, respects robots.txt, implements rate limiting
69
+ - **Production Ready**: Comprehensive tests, CI/CD, type hints, logging, caching
70
+
71
+ ## Installation
72
+
73
+ ```bash
74
+ pip install travelpurpose
75
+ ```
76
+
77
+ ## Quick Start
78
+
79
+ ### Python API
80
+
81
+ ```python
82
+ from travelpurpose import predict_purpose, tags
83
+
84
+ # Predict travel purposes for a city
85
+ result = predict_purpose("Istanbul")
86
+ print(result)
87
+ # {
88
+ # 'main': ['Culture_Heritage', 'Transit_Gateway', 'Leisure'],
89
+ # 'sub': ['UNESCO_Site', 'Old_Town', 'Mega_Air_Hub', 'Gastronomy'],
90
+ # 'confidence': 0.86
91
+ # }
92
+
93
+ # Get raw tags from all sources
94
+ city_tags = tags("Antalya")
95
+ print(city_tags[:3])
96
+ # [
97
+ # {'tag': 'beachfront', 'source': 'booking', 'url': '...', 'ts': '...'},
98
+ # {'tag': 'resort', 'source': 'agoda', 'url': '...'},
99
+ # {'tag': 'all-inclusive', 'source': 'trivago', 'url': '...'}
100
+ # ]
101
+ ```
102
+
103
+ ### Command Line
104
+
105
+ ```bash
106
+ # Predict purposes for a city
107
+ tpurpose predict "Paris"
108
+
109
+ # Show raw tags
110
+ tpurpose show-tags "Dubai" --limit 20
111
+
112
+ # Search for cities
113
+ tpurpose find "turkey"
114
+
115
+ # Rebuild dataset (requires network access)
116
+ tpurpose rebuild --sample 100 --verbose
117
+ ```
118
+
119
+ ## Travel Purpose Ontology
120
+
121
+ ### Main Categories (12)
122
+
123
+ - **Business**: Finance hubs, tech centers, MICE destinations
124
+ - **Leisure**: City breaks, luxury, shopping, gastronomy
125
+ - **Culture_Heritage**: UNESCO sites, museums, old towns, architecture
126
+ - **Beach_Resort**: Beachfront, islands, diving, all-inclusive
127
+ - **Adventure_Nature**: Trekking, safari, desert, extreme sports
128
+ - **Family**: Theme parks, zoos, safe cities, kid-friendly
129
+ - **Medical_Health**: Medical tourism, wellness, spa, rehabilitation
130
+ - **Religious_Pilgrimage**: Islamic, Christian, Buddhist, Hindu pilgrimage sites
131
+ - **Winter_Snow**: Ski resorts, winter sports, aurora viewing
132
+ - **Nightlife_Entertainment**: Party districts, casinos, music festivals
133
+ - **Transit_Gateway**: Major airport hubs, connecting destinations
134
+ - **Seaman_Crew**: Crew change ports, maritime facilities
135
+
136
+ ### Subcategories (70+)
137
+
138
+ Each main category has 4-9 specialized subcategories. See `travelpurpose/ontology/ontology.yaml` for the complete taxonomy.
139
+
140
+ ## Data Sources
141
+
142
+ All data collection is **public, ToS-compliant, and ethical**:
143
+
144
+ ### Knowledge Bases
145
+ - **Wikidata**: Canonical city data, coordinates, population, UNESCO sites
146
+ - **Wikipedia**: City categories and cultural information
147
+
148
+ ### Travel Platforms (Public Data Only)
149
+ - **Booking.com**: Public structured data (JSON-LD), meta tags, city guides
150
+ - **Agoda**: Public landing pages, sitemaps, accommodation types
151
+ - **Trivago**: Public city pages, district information
152
+ - **Kayak**: Public city guides, travel information
153
+ - **Trip.com**: Public destination pages, attractions
154
+ - **Skyscanner**: Public autocomplete API for city normalization
155
+
156
+ ### Compliance Features
157
+ - Respects robots.txt
158
+ - Rate limiting (configurable, default 1.5s between requests)
159
+ - HTTP caching (24-hour TTL)
160
+ - Exponential backoff for retries
161
+ - No authentication, logins, or private APIs
162
+ - User-Agent identification
163
+ - Graceful degradation when sources are unavailable
164
+
165
+ ## Architecture
166
+
167
+ ### Data Pipeline
168
+
169
+ ```bash
170
+ python scripts/pipeline.py --min-population 100000 --sample 50
171
+ ```
172
+
173
+ The pipeline:
174
+ 1. Loads NBD.xlsx (if available) with existing city classifications
175
+ 2. Fetches canonical city data from Wikidata (cities >100K population)
176
+ 3. Harvests public tags from all sources
177
+ 4. Normalizes tags to English, handles Unicode city names
178
+ 5. Maps tags to ontology using fuzzy matching
179
+ 6. Merges with NBD purposes (if available)
180
+ 7. Classifies using hybrid rule-based + embedding approach
181
+ 8. Calculates confidence scores
182
+ 9. Exports to `travelpurpose/data/cities.{parquet,json}`
183
+
184
+ ### Classifier Design
185
+
186
+ **Hybrid Approach:**
187
+ 1. **Rule-Based** (deterministic): Strong tags directly map to categories
188
+ 2. **Tag Aggregation**: Weighted voting from multiple sources
189
+ 3. **Confidence Calibration**: Based on data quality and agreement
190
+
191
+ **Source Weights:**
192
+ - Wikidata/UNESCO: 1.5-2.0x (high authority)
193
+ - Booking.com/Agoda: 1.0x (standard)
194
+ - Trivago/Kayak/Trip.com: 0.9x
195
+ - Evidence type boosts: JSON-LD (1.2x), Meta (1.0x), Headings (0.8x)
196
+
197
+ ## Configuration
198
+
199
+ ### Rate Limiting
200
+
201
+ ```python
202
+ from travelpurpose.utils.harvest import HarvestConfig
203
+
204
+ config = HarvestConfig(
205
+ rate_limit=2.0, # 2 seconds between requests
206
+ timeout=15,
207
+ max_retries=3,
208
+ cache_ttl=86400, # 24 hours
209
+ )
210
+ ```
211
+
212
+ ### Extending the Ontology
213
+
214
+ Edit `travelpurpose/ontology/ontology.yaml`:
215
+
216
+ ```yaml
217
+ main_categories:
218
+ - Your_New_Category
219
+
220
+ subcategories:
221
+ Your_New_Category:
222
+ - Subcategory_One
223
+ - Subcategory_Two
224
+
225
+ tag_mappings:
226
+ your_mapping:
227
+ main: Your_New_Category
228
+ sub: [Subcategory_One]
229
+ keywords: ["keyword1", "keyword2"]
230
+ ```
231
+
232
+ ## Development
233
+
234
+ ### Setup
235
+
236
+ ```bash
237
+ git clone https://github.com/teyfikoz/Travel_Purpose-City_Tags.git
238
+ cd Travel_Purpose-City_Tags
239
+ pip install -e ".[dev]"
240
+ ```
241
+
242
+ ### Running Tests
243
+
244
+ ```bash
245
+ pytest
246
+ pytest --cov=travelpurpose --cov-report=term-missing
247
+ ```
248
+
249
+ ### Linting
250
+
251
+ ```bash
252
+ ruff check travelpurpose/
253
+ black travelpurpose/
254
+ ```
255
+
256
+ ### Building for PyPI
257
+
258
+ ```bash
259
+ python -m build
260
+ twine check dist/*
261
+ twine upload dist/*
262
+ ```
263
+
264
+ ## Examples
265
+
266
+ See `examples/` directory for Jupyter notebooks:
267
+ - `01_quickstart.ipynb`: Basic usage and API examples
268
+ - `02_training_and_rules.ipynb`: Advanced classification and ontology customization
269
+
270
+ ## Data Provenance & Ethics
271
+
272
+ ### Dataset Card
273
+
274
+ See `DATASET_CARD.md` for:
275
+ - Data sources and collection dates
276
+ - Sample sizes and coverage
277
+ - Limitations and biases
278
+ - Update frequency
279
+
280
+ ### Ethics & Privacy
281
+
282
+ - **No PII**: We collect no personal information
283
+ - **Public Data Only**: All sources are publicly accessible
284
+ - **ToS Compliance**: Strict adherence to platform terms of service
285
+ - **Transparency**: Full source attribution in tag metadata
286
+ - **Caching**: Reduces load on source platforms
287
+ - **Rate Limiting**: Prevents server overload
288
+
289
+ ## Citation
290
+
291
+ If you use TravelPurpose in research, please cite:
292
+
293
+ ```bibtex
294
+ @software{travelpurpose2025,
295
+ title = {TravelPurpose: City Travel Purpose Classification Library},
296
+ author = {Travel Purpose Contributors},
297
+ year = {2025},
298
+ url = {https://github.com/teyfikoz/Travel_Purpose-City_Tags}
299
+ }
300
+ ```
301
+
302
+ See `CITATION.cff` for more formats.
303
+
304
+ ## License
305
+
306
+ MIT License - see `LICENSE` file for details.
307
+
308
+ ## Contributing
309
+
310
+ We welcome contributions! See `CONTRIBUTING.md` for guidelines.
311
+
312
+ Key areas for contribution:
313
+ - Adding new data sources (must be public and ToS-compliant)
314
+ - Expanding the ontology with new categories
315
+ - Improving classification accuracy
316
+ - Adding support for more languages
317
+ - Documentation improvements
318
+
319
+ ## Support
320
+
321
+ - **Issues**: [GitHub Issues](https://github.com/teyfikoz/Travel_Purpose-City_Tags/issues)
322
+ - **Discussions**: [GitHub Discussions](https://github.com/teyfikoz/Travel_Purpose-City_Tags/discussions)
323
+
324
+ ## Changelog
325
+
326
+ See `CHANGELOG.md` for version history and updates.
327
+
328
+ ## Acknowledgments
329
+
330
+ - Wikidata and Wikipedia communities for open knowledge bases
331
+ - Travel platforms for providing public data
332
+ - Open source community for excellent Python libraries
333
+
334
+ ---
335
+
336
+ **Made with ❤️ for the travel and data science communities**
@@ -0,0 +1,284 @@
1
+ # TravelPurpose
2
+
3
+ [![PyPI version](https://badge.fury.io/py/travelpurpose.svg)](https://badge.fury.io/py/travelpurpose)
4
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ A production-grade Python library for classifying world cities by travel purpose using multi-source data from public travel platforms and knowledge bases.
8
+
9
+ ## Features
10
+
11
+ - **Multi-Label Classification**: Cities can have multiple travel purposes (e.g., Business + Culture + Transit)
12
+ - **Rich Ontology**: 12 main categories and 70+ subcategories covering all travel purposes
13
+ - **Multi-Source Data**: Integrates data from Wikidata, Booking.com, Agoda, Trivago, Kayak, Trip.com, and Skyscanner
14
+ - **Hybrid Classifier**: Combines rule-based and embedding-based approaches with confidence scoring
15
+ - **Python API & CLI**: Easy-to-use programmatic and command-line interfaces
16
+ - **Ethical Data Collection**: Fully compliant with ToS, respects robots.txt, implements rate limiting
17
+ - **Production Ready**: Comprehensive tests, CI/CD, type hints, logging, caching
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install travelpurpose
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ### Python API
28
+
29
+ ```python
30
+ from travelpurpose import predict_purpose, tags
31
+
32
+ # Predict travel purposes for a city
33
+ result = predict_purpose("Istanbul")
34
+ print(result)
35
+ # {
36
+ # 'main': ['Culture_Heritage', 'Transit_Gateway', 'Leisure'],
37
+ # 'sub': ['UNESCO_Site', 'Old_Town', 'Mega_Air_Hub', 'Gastronomy'],
38
+ # 'confidence': 0.86
39
+ # }
40
+
41
+ # Get raw tags from all sources
42
+ city_tags = tags("Antalya")
43
+ print(city_tags[:3])
44
+ # [
45
+ # {'tag': 'beachfront', 'source': 'booking', 'url': '...', 'ts': '...'},
46
+ # {'tag': 'resort', 'source': 'agoda', 'url': '...'},
47
+ # {'tag': 'all-inclusive', 'source': 'trivago', 'url': '...'}
48
+ # ]
49
+ ```
50
+
51
+ ### Command Line
52
+
53
+ ```bash
54
+ # Predict purposes for a city
55
+ tpurpose predict "Paris"
56
+
57
+ # Show raw tags
58
+ tpurpose show-tags "Dubai" --limit 20
59
+
60
+ # Search for cities
61
+ tpurpose find "turkey"
62
+
63
+ # Rebuild dataset (requires network access)
64
+ tpurpose rebuild --sample 100 --verbose
65
+ ```
66
+
67
+ ## Travel Purpose Ontology
68
+
69
+ ### Main Categories (12)
70
+
71
+ - **Business**: Finance hubs, tech centers, MICE destinations
72
+ - **Leisure**: City breaks, luxury, shopping, gastronomy
73
+ - **Culture_Heritage**: UNESCO sites, museums, old towns, architecture
74
+ - **Beach_Resort**: Beachfront, islands, diving, all-inclusive
75
+ - **Adventure_Nature**: Trekking, safari, desert, extreme sports
76
+ - **Family**: Theme parks, zoos, safe cities, kid-friendly
77
+ - **Medical_Health**: Medical tourism, wellness, spa, rehabilitation
78
+ - **Religious_Pilgrimage**: Islamic, Christian, Buddhist, Hindu pilgrimage sites
79
+ - **Winter_Snow**: Ski resorts, winter sports, aurora viewing
80
+ - **Nightlife_Entertainment**: Party districts, casinos, music festivals
81
+ - **Transit_Gateway**: Major airport hubs, connecting destinations
82
+ - **Seaman_Crew**: Crew change ports, maritime facilities
83
+
84
+ ### Subcategories (70+)
85
+
86
+ Each main category has 4-9 specialized subcategories. See `travelpurpose/ontology/ontology.yaml` for the complete taxonomy.
87
+
88
+ ## Data Sources
89
+
90
+ All data collection is **public, ToS-compliant, and ethical**:
91
+
92
+ ### Knowledge Bases
93
+ - **Wikidata**: Canonical city data, coordinates, population, UNESCO sites
94
+ - **Wikipedia**: City categories and cultural information
95
+
96
+ ### Travel Platforms (Public Data Only)
97
+ - **Booking.com**: Public structured data (JSON-LD), meta tags, city guides
98
+ - **Agoda**: Public landing pages, sitemaps, accommodation types
99
+ - **Trivago**: Public city pages, district information
100
+ - **Kayak**: Public city guides, travel information
101
+ - **Trip.com**: Public destination pages, attractions
102
+ - **Skyscanner**: Public autocomplete API for city normalization
103
+
104
+ ### Compliance Features
105
+ - Respects robots.txt
106
+ - Rate limiting (configurable, default 1.5s between requests)
107
+ - HTTP caching (24-hour TTL)
108
+ - Exponential backoff for retries
109
+ - No authentication, logins, or private APIs
110
+ - User-Agent identification
111
+ - Graceful degradation when sources are unavailable
112
+
113
+ ## Architecture
114
+
115
+ ### Data Pipeline
116
+
117
+ ```bash
118
+ python scripts/pipeline.py --min-population 100000 --sample 50
119
+ ```
120
+
121
+ The pipeline:
122
+ 1. Loads NBD.xlsx (if available) with existing city classifications
123
+ 2. Fetches canonical city data from Wikidata (cities >100K population)
124
+ 3. Harvests public tags from all sources
125
+ 4. Normalizes tags to English, handles Unicode city names
126
+ 5. Maps tags to ontology using fuzzy matching
127
+ 6. Merges with NBD purposes (if available)
128
+ 7. Classifies using hybrid rule-based + embedding approach
129
+ 8. Calculates confidence scores
130
+ 9. Exports to `travelpurpose/data/cities.{parquet,json}`
131
+
132
+ ### Classifier Design
133
+
134
+ **Hybrid Approach:**
135
+ 1. **Rule-Based** (deterministic): Strong tags directly map to categories
136
+ 2. **Tag Aggregation**: Weighted voting from multiple sources
137
+ 3. **Confidence Calibration**: Based on data quality and agreement
138
+
139
+ **Source Weights:**
140
+ - Wikidata/UNESCO: 1.5-2.0x (high authority)
141
+ - Booking.com/Agoda: 1.0x (standard)
142
+ - Trivago/Kayak/Trip.com: 0.9x
143
+ - Evidence type boosts: JSON-LD (1.2x), Meta (1.0x), Headings (0.8x)
144
+
145
+ ## Configuration
146
+
147
+ ### Rate Limiting
148
+
149
+ ```python
150
+ from travelpurpose.utils.harvest import HarvestConfig
151
+
152
+ config = HarvestConfig(
153
+ rate_limit=2.0, # 2 seconds between requests
154
+ timeout=15,
155
+ max_retries=3,
156
+ cache_ttl=86400, # 24 hours
157
+ )
158
+ ```
159
+
160
+ ### Extending the Ontology
161
+
162
+ Edit `travelpurpose/ontology/ontology.yaml`:
163
+
164
+ ```yaml
165
+ main_categories:
166
+ - Your_New_Category
167
+
168
+ subcategories:
169
+ Your_New_Category:
170
+ - Subcategory_One
171
+ - Subcategory_Two
172
+
173
+ tag_mappings:
174
+ your_mapping:
175
+ main: Your_New_Category
176
+ sub: [Subcategory_One]
177
+ keywords: ["keyword1", "keyword2"]
178
+ ```
179
+
180
+ ## Development
181
+
182
+ ### Setup
183
+
184
+ ```bash
185
+ git clone https://github.com/teyfikoz/Travel_Purpose-City_Tags.git
186
+ cd Travel_Purpose-City_Tags
187
+ pip install -e ".[dev]"
188
+ ```
189
+
190
+ ### Running Tests
191
+
192
+ ```bash
193
+ pytest
194
+ pytest --cov=travelpurpose --cov-report=term-missing
195
+ ```
196
+
197
+ ### Linting
198
+
199
+ ```bash
200
+ ruff check travelpurpose/
201
+ black travelpurpose/
202
+ ```
203
+
204
+ ### Building for PyPI
205
+
206
+ ```bash
207
+ python -m build
208
+ twine check dist/*
209
+ twine upload dist/*
210
+ ```
211
+
212
+ ## Examples
213
+
214
+ See `examples/` directory for Jupyter notebooks:
215
+ - `01_quickstart.ipynb`: Basic usage and API examples
216
+ - `02_training_and_rules.ipynb`: Advanced classification and ontology customization
217
+
218
+ ## Data Provenance & Ethics
219
+
220
+ ### Dataset Card
221
+
222
+ See `DATASET_CARD.md` for:
223
+ - Data sources and collection dates
224
+ - Sample sizes and coverage
225
+ - Limitations and biases
226
+ - Update frequency
227
+
228
+ ### Ethics & Privacy
229
+
230
+ - **No PII**: We collect no personal information
231
+ - **Public Data Only**: All sources are publicly accessible
232
+ - **ToS Compliance**: Strict adherence to platform terms of service
233
+ - **Transparency**: Full source attribution in tag metadata
234
+ - **Caching**: Reduces load on source platforms
235
+ - **Rate Limiting**: Prevents server overload
236
+
237
+ ## Citation
238
+
239
+ If you use TravelPurpose in research, please cite:
240
+
241
+ ```bibtex
242
+ @software{travelpurpose2025,
243
+ title = {TravelPurpose: City Travel Purpose Classification Library},
244
+ author = {Travel Purpose Contributors},
245
+ year = {2025},
246
+ url = {https://github.com/teyfikoz/Travel_Purpose-City_Tags}
247
+ }
248
+ ```
249
+
250
+ See `CITATION.cff` for more formats.
251
+
252
+ ## License
253
+
254
+ MIT License - see `LICENSE` file for details.
255
+
256
+ ## Contributing
257
+
258
+ We welcome contributions! See `CONTRIBUTING.md` for guidelines.
259
+
260
+ Key areas for contribution:
261
+ - Adding new data sources (must be public and ToS-compliant)
262
+ - Expanding the ontology with new categories
263
+ - Improving classification accuracy
264
+ - Adding support for more languages
265
+ - Documentation improvements
266
+
267
+ ## Support
268
+
269
+ - **Issues**: [GitHub Issues](https://github.com/teyfikoz/Travel_Purpose-City_Tags/issues)
270
+ - **Discussions**: [GitHub Discussions](https://github.com/teyfikoz/Travel_Purpose-City_Tags/discussions)
271
+
272
+ ## Changelog
273
+
274
+ See `CHANGELOG.md` for version history and updates.
275
+
276
+ ## Acknowledgments
277
+
278
+ - Wikidata and Wikipedia communities for open knowledge bases
279
+ - Travel platforms for providing public data
280
+ - Open source community for excellent Python libraries
281
+
282
+ ---
283
+
284
+ **Made with ❤️ for the travel and data science communities**