# Wikipedia DYK Database - Build Process ## Overview This dataset is built using an automated 8-step pipeline that fetches DYK entries from Wikipedia, enriches them with metadata, and verifies data quality. ## Quick Start ```bash # Verify existing dataset python ingest/build_pipeline.py --verify-only # Rebuild from scratch python ingest/build_pipeline.py # List all pipeline steps python ingest/build_pipeline.py --list-steps ``` ## Build Pipeline Steps ### Step 1: Initialize Database Creates the DuckDB database schema. ```bash python ingest/ingest.py --init-only ``` ### Step 2: Ingest Historical Data Fetches all DYK entries from Wikipedia archives (2004-present). ```bash python ingest/ingest.py --full --slow-mode ``` - Uses rate limiting (3s delay between requests) - Caches HTML files in `cache/` directory - Takes ~2 hours for full historical fetch ### Step 3: Augment Categories Adds category metadata to all entries based on keyword matching. ```bash python ingest/augment_categories.py --all ``` Categories: Biography, Geography, Sports, Music, Film, History, etc. ### Step 4: Backfill Article Links Extracts Wikipedia article links from cached HTML files. ```bash python ingest/backfill_from_source_v2.py ``` ### Step 5: Backfill Red Links Extracts articles that didn't exist at time of DYK ("red links"). ```bash python ingest/backfill_redlinks.py ``` ### Step 6: Fix Image Markers Corrects `has_image` boolean to match `(pictured)`/`(shown)` in raw_text. ```bash python ingest/fix_image_markers.py ``` ### Step 7: Deduplicate Entries Removes duplicate entries based on date + content pairs. ```bash python ingest/deduplicate.py ``` ### Step 8: Quality Verification Runs comprehensive quality checks on the final dataset. ```bash python ingest/quality_review.py # or python ingest/verify_dataset.py ``` ## Pipeline Options ```bash # Dry run (show what would run) python ingest/build_pipeline.py --dry-run # Skip ingestion (use existing cached data) python ingest/build_pipeline.py --skip-ingest # Start from a specific step python ingest/build_pipeline.py --from-step 3 ``` ## Maintenance ### Weekly Update Fetch only the current month's new entries: ```bash python ingest/ingest.py --update ``` ### Monthly Refresh Fetch the last 3 months: ```bash python ingest/ingest.py --months 3 ``` After updating, run the remaining steps: ```bash python ingest/build_pipeline.py --skip-ingest --from-step 3 ``` ## Verification Checklist After building, verify: - [ ] All 9 verification checks pass - [ ] Total entries ~118,000 - [ ] Date range: 2004-03-01 to present - [ ] No NULL values in primary_article, source_url, categories, domain ```bash python ingest/verify_dataset.py --json ``` ## Output Files ``` wikipedia-dyk/ ├── data.duckdb # Main database (final output) ├── datapackage.json # Dataset metadata ├── schema.yaml # Schema documentation ├── README.md # User documentation ├── PROCESS.md # This file ├── requirements.txt # Python dependencies ├── cache/ # Cached HTML files │ └── YYYY_MM.html # Monthly archives ├── source/ # Alternative source files └── ingest/ # Build scripts ├── ingest.py ├── augment_categories.py ├── backfill_from_source_v2.py ├── backfill_redlinks.py ├── fix_image_markers.py ├── deduplicate.py ├── quality_review.py ├── verify_dataset.py └── build_pipeline.py ``` ## Dependencies ```bash pip install duckdb requests beautifulsoup4 ``` ## Quality Standards The dataset maintains 100% quality score by ensuring: 1. **Complete Coverage**: All fields populated 2. **No Duplicates**: Unique on date + content 3. **Valid JSON**: All article_links parseable 4. **Consistent Markers**: has_image matches raw_text 5. **Valid URLs**: All source_urls are valid Wikipedia archives ## Known Limitations 1. **Historical Formatting**: 13.3% use "...that" (no space) - historical format from 2004-2005 2. **Short Entries**: 12 entries have content <20 chars - legitimate short facts 3. **Red Links**: Some articles didn't exist at time of DYK - preserved with correct names ## Troubleshooting ### Database locked ```bash # Close all connections lsof data.duckdb # Delete lock file if needed rm -f data.duckdb.wal ``` ### Rate limited by Wikipedia ```bash # Use slow mode python ingest/ingest.py --full --slow-mode ``` ### Missing entries for a month ```bash # Re-fetch specific month python ingest/ingest.py --months 1 # or manually fetch ``` ## Last Updated 2026-03-22