Spaces:
Running
Running
Fix FULLTEXT: make chunks_path robust to str or Path
Browse files- src/fulltext.py +11 -4
src/fulltext.py
CHANGED
|
@@ -4,22 +4,28 @@
|
|
| 4 |
"""
|
| 5 |
fulltext.py — Mode FULLTEXT (texte exact depuis JSONL, sans LLM)
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
"""
|
| 9 |
|
| 10 |
import json
|
| 11 |
from pathlib import Path
|
| 12 |
-
from typing import Optional
|
| 13 |
|
| 14 |
|
| 15 |
def normalize_article_id(raw: str) -> str:
|
| 16 |
-
return raw.strip().upper().replace(" ", "").replace(".", "-")
|
| 17 |
|
| 18 |
|
| 19 |
-
def load_article_text(article_id: str, chunks_path: Path) -> Optional[str]:
|
| 20 |
"""
|
| 21 |
Recherche l'article_id dans chunks_path (JSONL) et renvoie le texte exact.
|
|
|
|
|
|
|
| 22 |
"""
|
|
|
|
|
|
|
| 23 |
if not chunks_path.exists():
|
| 24 |
raise FileNotFoundError(f"Fichier chunks introuvable : {chunks_path}")
|
| 25 |
|
|
@@ -33,4 +39,5 @@ def load_article_text(article_id: str, chunks_path: Path) -> Optional[str]:
|
|
| 33 |
aid = normalize_article_id(obj.get("article_id", ""))
|
| 34 |
if aid == article_id:
|
| 35 |
return (obj.get("text") or "").strip()
|
|
|
|
| 36 |
return None
|
|
|
|
| 4 |
"""
|
| 5 |
fulltext.py — Mode FULLTEXT (texte exact depuis JSONL, sans LLM)
|
| 6 |
|
| 7 |
+
Robuste :
|
| 8 |
+
- accepte chunks_path en str ou Path
|
| 9 |
+
- normalise l'article_id
|
| 10 |
"""
|
| 11 |
|
| 12 |
import json
|
| 13 |
from pathlib import Path
|
| 14 |
+
from typing import Optional, Union
|
| 15 |
|
| 16 |
|
| 17 |
def normalize_article_id(raw: str) -> str:
|
| 18 |
+
return (raw or "").strip().upper().replace(" ", "").replace(".", "-")
|
| 19 |
|
| 20 |
|
| 21 |
+
def load_article_text(article_id: str, chunks_path: Union[str, Path]) -> Optional[str]:
|
| 22 |
"""
|
| 23 |
Recherche l'article_id dans chunks_path (JSONL) et renvoie le texte exact.
|
| 24 |
+
|
| 25 |
+
chunks_path : peut être un Path OU une string (cas Hugging Face via config.py).
|
| 26 |
"""
|
| 27 |
+
chunks_path = Path(chunks_path) # <-- FIX: rend le code compatible str/Path
|
| 28 |
+
|
| 29 |
if not chunks_path.exists():
|
| 30 |
raise FileNotFoundError(f"Fichier chunks introuvable : {chunks_path}")
|
| 31 |
|
|
|
|
| 39 |
aid = normalize_article_id(obj.get("article_id", ""))
|
| 40 |
if aid == article_id:
|
| 41 |
return (obj.get("text") or "").strip()
|
| 42 |
+
|
| 43 |
return None
|