#!/usr/bin/env python3 """Re-boost the 5 explicit Kol-Zchut docs with section metadata so the pipeline's section-signal boost (+5.0) fires on them when the query contains 'סעיף N'.""" import json, re, urllib.parse, urllib.request API = "https://www.kolzchut.org.il/w/api.php" HEADERS = {"User-Agent": "tau-rag-scraper/1.0"} # Pages with extra tags AND section metadata so the pipeline's # section-signal boost (+5.0 in pipeline.py:979) fires on them. # Schema: (title, extra_tags, law_name, section_number) TARGETS = [ ("סעיף 14 לחוק פיצויי פיטורים", ["[סעיף 14]", "[סעיף14]", "[פיצויי פיטורים]", "[חוק פיצויי פיטורים]"], "חוק פיצויי פיטורים, התשכ\"ג-1963", "14"), ("ביטול עסקה שנעשתה באינטרנט או בטלפון", ["[ביטול עסקה]", "[14 יום]", "[עסקה מרחוק]", "[חוק הגנת הצרכן]"], "חוק הגנת הצרכן, התשמ\"א-1981", "14ג"), ("ביטול רכישה שנעשתה בבית העסק והחזרת המוצר", ["[ביטול עסקה]", "[החזרת מוצר]", "[חוק הגנת הצרכן]"], "חוק הגנת הצרכן, התשמ\"א-1981", "14"), ("עסקת מכר מרחוק", ["[עסקה מרחוק]", "[ביטול עסקה]", "[14 יום]", "[חוק הגנת הצרכן]"], "חוק הגנת הצרכן, התשמ\"א-1981", "14ג"), ("עסקה ברוכלות", ["[עסקה ברוכלות]", "[חוק הגנת הצרכן]", "[ביטול עסקה]"], "חוק הגנת הצרכן, התשמ\"א-1981", "14ב"), ] out = [] for title, extra_tags, law_name, section in TARGETS: params = {"action":"parse","page":title,"prop":"wikitext","format":"json","redirects":"1"} url = API + "?" + urllib.parse.urlencode(params, safe=":/") req = urllib.request.Request(url, headers=HEADERS) try: data = json.loads(urllib.request.urlopen(req, timeout=20).read()) wt = data.get("parse",{}).get("wikitext",{}).get("*","") if not wt: print(f" ✗ {title}: empty"); continue for _ in range(8): new = re.sub(r"\{\{[^{}]*\}\}", "", wt, flags=re.DOTALL) if new == wt: break wt = new wt = re.sub(r"\[\[([^\]|]+)(?:\|([^\]]+))?\]\]", lambda m: m.group(2) or m.group(1), wt) wt = re.sub(r"<[^>]+>", "", wt) wt = re.sub(r"\s+", " ", wt).strip()[:2000] if len(wt) < 50: continue title_tag = f"[{title}]" prefix = " ".join( [title_tag, title_tag, title_tag] + extra_tags + extra_tags + ["[כל-זכות]"] ) text = f"{prefix} כל-זכות — {title}: {wt}" safe_id = re.sub(r"[^\w]", "_", title) out.append({ "id": f"kolzchut/boost/{safe_id}", "text": text, "metadata": { "title": title, "source": "kolzchut", "kind": "rights", # Critical — these fields trigger the +5.0 pipeline boost # when the query contains "סעיף N": "section": section, "law": law_name, } }) print(f" ✓ {title}: {len(text)} chars section={section}") except Exception as e: print(f" ✗ {title}: {e}") with open("/tmp/kolzchut_boost.jsonl", "w", encoding="utf-8") as f: for d in out: f.write(json.dumps(d, ensure_ascii=False) + "\n") print(f"\n✅ Wrote {len(out)} boosted → /tmp/kolzchut_boost.jsonl")