Faza 1 complete: bilingual+enrichment plumbing, UI/filters, frozen DB

Extraction finished (575/588 chunks; 6 content-filter-blocked, 7 await
re-extraction). DB rebuilt and frozen at 9418 activities — content_keys
are now stable for the enrichment overlay.

Part A (plumbing + UI):
- database.py: name_ro/description_ro/rules_ro/variations_ro, indoor_outdoor,
  space_needed, estimated_fields, source_id/source_ids/chunk_key columns;
  FTS5 indexes the 4 *_ro columns across CREATE + all 3 triggers; new equality
  filters + category counts for both axes.
- activity.py: new fields + bilingual display helpers (get_display_*,
  is_estimated, axis displays).
- config_taxonomy.py: INDOOR_OUTDOOR/SPACE_NEEDED enums + normalizers
  (None on unrecognised, no fabrication).
- search.py / routes.py / config.py / templates / css: new dropdowns,
  RO-primary rendering with "(estimat)" markers and collapsible original
  text, and a /source/<id> download route shipped DARK behind
  SOURCE_DOWNLOAD_ENABLED (copyright opt-in).
- build_database.py: source_id/chunk_key in dict_to_activity; merge_cluster
  unions source_ids without touching enrichment fields.

Part B (enrichment pipeline, built not yet run):
- build_database.py: load_enrichment + apply_enrichment (post-dedup, keyed on
  content_key) + --enrichment CLI + stated-vs-estimated QA.
- run_enrichment.py (resumable, --source/--limit pilot scoping, --collect),
  ENRICHMENT_PROMPT.md.

Repair: scripts/repair_extractions.py fixes the subagents' systematic
unescaped-ASCII-quote bug with a faithful char-scanner (escapes, never
truncates) + schema validation + a strictly-more-text guard. json_repair was
tried first, truncated silently, and is NOT used. build_database has no repair
dependency.

Tests: tests/test_enrichment.py added; 99 pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude Agent
2026-05-29 18:10:13 +00:00
parent 46d9592a55
commit bcfb6841eb
18 changed files with 1579 additions and 167 deletions

View File

@@ -3,20 +3,27 @@ Flask routes for INDEX-SISTEM-JOCURI v2.0
Clean, minimalist web interface with dynamic filters
"""
from flask import Blueprint, request, render_template, jsonify, current_app
from flask import (
Blueprint, request, render_template, jsonify, current_app,
send_from_directory,
)
from app.models.database import DatabaseManager
from app.models.activity import Activity
from app.services.search import SearchService
from app.config_taxonomy import CATEGORIES, CONTENT_TYPES
import os
from pathlib import Path
from app.config_taxonomy import (
CATEGORIES, CONTENT_TYPES, INDOOR_OUTDOOR, SPACE_NEEDED,
)
bp = Blueprint('main', __name__)
# Slug -> Romanian display name. Category and content_type slugs never collide,
# so a single flat map is enough for the UI filter labels.
# Slug -> Romanian display name. Category, content_type, indoor_outdoor and
# space_needed slugs never collide, so a single flat map is enough for the UI
# filter labels.
LANGUAGE_NAMES = {'ro': 'Română', 'en': 'Engleză'}
DISPLAY_NAMES = {**CATEGORIES, **CONTENT_TYPES, **LANGUAGE_NAMES}
DISPLAY_NAMES = {
**CATEGORIES, **CONTENT_TYPES, **INDOOR_OUTDOOR, **SPACE_NEEDED,
**LANGUAGE_NAMES,
}
# Initialize database manager (will be configured in application factory)
def get_db_manager():
@@ -138,6 +145,44 @@ def activity_detail(activity_id):
print(f"Error loading activity {activity_id}: {e}")
return render_template('404.html'), 404
@bp.route('/source/<int:activity_id>')
def source_download(activity_id):
"""Download the original source file for an activity (plan A6).
Shipped DARK: returns 404 unless SOURCE_DOWNLOAD_ENABLED is set (copyright
exposure — the user opts in). Resolves the activity's `source_file` under
CORPUS_DIR. send_from_directory does the safe-join and blocks traversal;
web-mirror / extension-less sources that are not real files 404 gracefully.
"""
if not current_app.config.get('SOURCE_DOWNLOAD_ENABLED', False):
return render_template('404.html'), 404
try:
db = get_db_manager()
activity_data = db.get_activity_by_id(activity_id)
if not activity_data:
return render_template('404.html'), 404
source_file = (activity_data.get('source_file') or '').strip()
if not source_file:
return render_template('404.html'), 404
corpus_dir = current_app.config.get('CORPUS_DIR')
if not corpus_dir:
return render_template('404.html'), 404
try:
# send_from_directory rejects path traversal and missing files with
# a 404 (NotFound) — no manual safe_join needed.
return send_from_directory(
corpus_dir, source_file, as_attachment=True
)
except Exception:
# Missing file / web-mirror source with no on-disk original.
return render_template('404.html'), 404
except Exception as e:
print(f"Source download error for {activity_id}: {e}")
return render_template('404.html'), 404
@bp.route('/health')
def health_check():
"""Health check endpoint for Docker"""