Spaces:
Running on Zero
Running on Zero
Deploiement GuindiMa AI (interface Gradio) (part 2)
Browse files- scripts/audit_quartiers_numerotes.py +270 -0
- src/intent/extract_intent.py +35 -1
- src/matching/geo.py +4 -0
- src/matching/lieux.py +6 -0
- src/routing/adapter.py +22 -2
scripts/audit_quartiers_numerotes.py
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Audit des quartiers numérotés (lot Q1) : lesquels existent dans nos données, lesquels manquent.
|
| 2 |
+
|
| 3 |
+
À Dakar, beaucoup de quartiers portent un numéro, toujours dit en français
|
| 4 |
+
(Sacré-Cœur 3, Liberté 6, HLM 5, Unité 15…). Ce script cherche chaque numéro
|
| 5 |
+
dans nos lieux et nos arrêts, sans réseau, et écrit
|
| 6 |
+
data/audit/quartiers_numerotes_manquants.csv. Il ne modifie aucune donnée.
|
| 7 |
+
|
| 8 |
+
Sources, de la plus sûre à la moins sûre :
|
| 9 |
+
1. les arrêts du réseau tel que le moteur le charge (itinéraires Tata et
|
| 10 |
+
Dem Dikk, corrections comprises) : position « mesurée » si sa confiance est
|
| 11 |
+
« bonne », sinon « estimée » ;
|
| 12 |
+
2. data/arrets_geo.csv : le nom de l'arrêt, ou la colonne « quartier » (le
|
| 13 |
+
quartier où se trouve un arrêt) ;
|
| 14 |
+
3. data/sources/osm_bus_dakar/arrets_osm.csv : arrêts OpenStreetMap, position
|
| 15 |
+
« mesurée » (coordonnées OSM) ;
|
| 16 |
+
4. data/corrections/corrections_geo_ddd_proposees.csv : l'adresse Nominatim
|
| 17 |
+
d'un arrêt Dem Dikk (colonne detail, « estimée ») ;
|
| 18 |
+
data/reference/lignes_reference.csv : la liste officielle des arrêts de
|
| 19 |
+
chaque ligne (nom seul : position « absente ») ;
|
| 20 |
+
5. data/lieux_geo.csv : point de quartier précalculé, toujours « estimée »
|
| 21 |
+
(ce n'est pas un arrêt mesuré) ;
|
| 22 |
+
6. data/corrections/lieux_quartiers_numerotes.csv (lot Q2) : quartiers
|
| 23 |
+
confirmés par deux sources, position « mesurée ».
|
| 24 |
+
|
| 25 |
+
Usage (PowerShell) :
|
| 26 |
+
$env:PYTHONIOENCODING='utf-8'
|
| 27 |
+
.\\.venv\\Scripts\\python.exe scripts\\audit_quartiers_numerotes.py
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
from __future__ import annotations
|
| 31 |
+
|
| 32 |
+
import contextlib
|
| 33 |
+
import csv
|
| 34 |
+
import io
|
| 35 |
+
import re
|
| 36 |
+
import sys
|
| 37 |
+
import unicodedata
|
| 38 |
+
from collections import defaultdict
|
| 39 |
+
from pathlib import Path
|
| 40 |
+
|
| 41 |
+
RACINE = Path(__file__).resolve().parents[1]
|
| 42 |
+
sys.path.insert(0, str(RACINE / "src"))
|
| 43 |
+
SORTIE = RACINE / "data" / "audit" / "quartiers_numerotes_manquants.csv"
|
| 44 |
+
|
| 45 |
+
ROMAINS = {"i": 1, "ii": 2, "iii": 3, "iv": 4, "v": 5, "vi": 6, "vii": 7, "viii": 8, "ix": 9, "x": 10}
|
| 46 |
+
MOTS = {"un": 1, "deux": 2, "trois": 3, "quatre": 4, "cinq": 5, "six": 6}
|
| 47 |
+
|
| 48 |
+
# (famille, motif du nom normalisé, numéros attendus, gabarit du nom attendu)
|
| 49 |
+
FAMILLES = [
|
| 50 |
+
("Sacré-Cœur", r"\bsacre coeur", range(1, 4), "Sacré-Cœur {}"),
|
| 51 |
+
("Liberté", r"\b(?:sicap )?liberte", range(1, 7), "Liberté {}"),
|
| 52 |
+
("HLM", r"\bhlm", range(1, 7), "HLM {}"),
|
| 53 |
+
# « Unité 15 », « Unités 09 10 15 », « U23 », « U.25 » (OSM, page Dem Dikk).
|
| 54 |
+
("Parcelles Assainies (unités)", r"\b(?:unites?|u(?= ?\d))", range(1, 27), "Unité {}"),
|
| 55 |
+
("Dieuppeul", r"\bdieuppeul", range(1, 5), "Dieuppeul {}"),
|
| 56 |
+
("Cambérène", r"\bcamberene", range(1, 3), "Cambérène {}"),
|
| 57 |
+
("Sicap Amitié", r"\b(?:sicap )?amitie", range(1, 4), "Amitié {}"),
|
| 58 |
+
("Hamo (Guédiawaye)", r"\bhamo", range(1, 7), "Hamo {}"),
|
| 59 |
+
("Gorom", r"\bgorom", range(1, 3), "Gorom {}"),
|
| 60 |
+
("Jaxaay", r"\bjaxaay", range(1, 3), "Jaxaay {}"),
|
| 61 |
+
]
|
| 62 |
+
# Quartiers sans numéro cités par Cheikh : simple contrôle de présence.
|
| 63 |
+
SANS_NUMERO = [
|
| 64 |
+
("HLM", r"\bhlm grand yoff\b", "HLM Grand Yoff"),
|
| 65 |
+
("HLM", r"\bhlm grand medine\b", "HLM Grand Médine"),
|
| 66 |
+
("Grand Yoff", r"\bgrand yoff\b", "Grand Yoff"),
|
| 67 |
+
("Castors", r"\bcastors?\b", "Castors"),
|
| 68 |
+
("Sicap", r"\bbaobabs?\b", "Sicap Baobabs"),
|
| 69 |
+
("Sicap", r"\bmermoz\b", "Sicap Mermoz"),
|
| 70 |
+
("Cité Keur Gorgui", r"\bkeur gorgui\b", "Cité Keur Gorgui"),
|
| 71 |
+
("Grand Dakar", r"\bgrand dakar\b", "Grand Dakar"),
|
| 72 |
+
("Sicap", r"\bsicap karack\b", "Sicap Karack"),
|
| 73 |
+
("Patte d'Oie", r"\bpatte d ?oie\b", "Patte d'Oie"),
|
| 74 |
+
]
|
| 75 |
+
RANG_POSITION = {"mesurée": 0, "estimée": 1, "absente": 2}
|
| 76 |
+
# Pour la priorité : les arrêts du quartier, numérotés ou non (« Marché HLM »,
|
| 77 |
+
# « Derklé », « Parcelles Assainies »), disent combien de lignes le desservent.
|
| 78 |
+
QUARTIER_DE_LA_FAMILLE = {
|
| 79 |
+
"Parcelles Assainies (unités)": r"\bparcelles\b|\bunites?\b",
|
| 80 |
+
"Dieuppeul": r"\bdieuppeul\b|\bderkle\b",
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def normaliser(texte: object) -> str:
|
| 85 |
+
texte = str(texte or "").lower().replace("œ", "oe")
|
| 86 |
+
texte = "".join(c for c in unicodedata.normalize("NFD", texte) if unicodedata.category(c) != "Mn")
|
| 87 |
+
return re.sub(r"\s+", " ", re.sub(r"[^a-z0-9/]+", " ", texte)).strip()
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def numeros_apres(nom_norm: str, motif: str) -> set[int]:
|
| 91 |
+
"""Les numéros qui suivent le nom de famille : « unites 09 10 15 », « hamo v/vi »."""
|
| 92 |
+
trouves: set[int] = set()
|
| 93 |
+
for depart in re.finditer(motif, nom_norm):
|
| 94 |
+
suite = nom_norm[depart.end():].replace("/", " ").split()
|
| 95 |
+
for mot in suite:
|
| 96 |
+
mot = mot.strip()
|
| 97 |
+
if mot in ("et", "a"):
|
| 98 |
+
continue
|
| 99 |
+
if mot.isdigit():
|
| 100 |
+
trouves.add(int(mot))
|
| 101 |
+
elif mot in ROMAINS:
|
| 102 |
+
trouves.add(ROMAINS[mot])
|
| 103 |
+
elif mot in MOTS:
|
| 104 |
+
trouves.add(MOTS[mot])
|
| 105 |
+
else:
|
| 106 |
+
break
|
| 107 |
+
return trouves
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def charger_sources() -> list[dict]:
|
| 111 |
+
"""Toutes les mentions (nom, fichier, position) de nos données."""
|
| 112 |
+
from routing import adapter as moteur
|
| 113 |
+
|
| 114 |
+
tests = RACINE / "tests"
|
| 115 |
+
sys.path.insert(0, str(tests))
|
| 116 |
+
import test_trajets # noqa: E402 (le matcher hors ligne des tests, sans réseau)
|
| 117 |
+
|
| 118 |
+
with contextlib.redirect_stdout(io.StringIO()):
|
| 119 |
+
matcher = test_trajets._matcher_hors_ligne()
|
| 120 |
+
moteur.chercher_v2(matcher, "Ouakam", "Palais")
|
| 121 |
+
reseau = moteur._NETWORK
|
| 122 |
+
|
| 123 |
+
tata_ddd = {r["arret"] for r in csv.DictReader(open(RACINE / "data" / "itineraires_dakar.csv", encoding="utf-8"))}
|
| 124 |
+
officiel = {
|
| 125 |
+
r["arret"]
|
| 126 |
+
for r in csv.DictReader(open(RACINE / "data" / "corrections" / "corrections_geo_ddd_proposees.csv", encoding="utf-8"))
|
| 127 |
+
}
|
| 128 |
+
lignes_par_arret: dict[str, set] = defaultdict(set)
|
| 129 |
+
for cle, ligne in reseau.lines.items():
|
| 130 |
+
for arret in ligne.stops:
|
| 131 |
+
lignes_par_arret[arret].add(cle)
|
| 132 |
+
|
| 133 |
+
sources: list[dict] = []
|
| 134 |
+
for arret in reseau.stop_names:
|
| 135 |
+
if reseau.stop_confidence.get(arret) == "bonne":
|
| 136 |
+
position = "mesurée"
|
| 137 |
+
else:
|
| 138 |
+
position = "estimée" if reseau.coords(arret) else "absente"
|
| 139 |
+
fichier = (
|
| 140 |
+
"data/itineraires_dakar.csv" if arret in tata_ddd
|
| 141 |
+
else "data/corrections/corrections_geo_ddd_proposees.csv" if arret in officiel
|
| 142 |
+
else "data/corrections (itinéraires revus)"
|
| 143 |
+
)
|
| 144 |
+
sources.append({"nom": arret, "fichier": fichier, "position": position,
|
| 145 |
+
"lignes": lignes_par_arret.get(arret, set())})
|
| 146 |
+
for r in csv.DictReader(open(RACINE / "data" / "arrets_geo.csv", encoding="utf-8")):
|
| 147 |
+
position = "mesurée" if r["confiance"] == "bonne" else "estimée"
|
| 148 |
+
sources.append({"nom": r["arret"], "fichier": "data/arrets_geo.csv", "position": position,
|
| 149 |
+
"lignes": lignes_par_arret.get(r["arret"], set())})
|
| 150 |
+
if r.get("quartier"):
|
| 151 |
+
sources.append({"nom": r["quartier"], "fichier": "data/arrets_geo.csv (colonne quartier)",
|
| 152 |
+
"position": position, "via": r["arret"],
|
| 153 |
+
"lignes": lignes_par_arret.get(r["arret"], set())})
|
| 154 |
+
for r in csv.DictReader(open(RACINE / "data" / "sources" / "osm_bus_dakar" / "arrets_osm.csv", encoding="utf-8")):
|
| 155 |
+
if (r.get("name") or "").strip():
|
| 156 |
+
sources.append({"nom": r["name"], "fichier": "data/sources/osm_bus_dakar/arrets_osm.csv",
|
| 157 |
+
"position": "mesurée" if r.get("lat") else "absente", "lignes": set()})
|
| 158 |
+
chemin_ddd = RACINE / "data" / "corrections" / "corrections_geo_ddd_proposees.csv"
|
| 159 |
+
for r in csv.DictReader(open(chemin_ddd, encoding="utf-8")):
|
| 160 |
+
if (r.get("source") or "") == "nominatim" and r.get("detail"):
|
| 161 |
+
# « Marché HLM 5, Rue HLM-173, HLM 5, Commune de HLM… » : le quartier de l'arrêt.
|
| 162 |
+
for morceau in r["detail"].split(","):
|
| 163 |
+
sources.append({"nom": morceau.strip(), "fichier": f"{chemin_ddd.relative_to(RACINE).as_posix()} (adresse Nominatim)",
|
| 164 |
+
"position": "estimée", "via": r["arret"], "lignes": set()})
|
| 165 |
+
# Listes officielles (« Terminus Cambérène ; Cambérène 2 ; Cambérène 1 ; … ;
|
| 166 |
+
# U.25 ; U.26 ») : le nom existe, sans position.
|
| 167 |
+
chemin_ref = RACINE / "data" / "reference" / "lignes_reference.csv"
|
| 168 |
+
if chemin_ref.exists():
|
| 169 |
+
for r in csv.DictReader(open(chemin_ref, encoding="utf-8-sig")):
|
| 170 |
+
for morceau in (r.get("arrets_principaux") or "").split(";"):
|
| 171 |
+
if morceau.strip():
|
| 172 |
+
sources.append({"nom": morceau.strip(),
|
| 173 |
+
"fichier": "data/reference/lignes_reference.csv (liste officielle, nom seul)",
|
| 174 |
+
"position": "absente", "lignes": set()})
|
| 175 |
+
chemin_q2 = RACINE / "data" / "corrections" / "lieux_quartiers_numerotes.csv"
|
| 176 |
+
if chemin_q2.exists():
|
| 177 |
+
for r in csv.DictReader(open(chemin_q2, encoding="utf-8-sig")):
|
| 178 |
+
mesuree = (r.get("position") or "").startswith("mesurée") and r.get("lat")
|
| 179 |
+
sources.append({"nom": r["lieu"], "fichier": "data/corrections/lieux_quartiers_numerotes.csv",
|
| 180 |
+
"position": "mesurée" if mesuree else "estimée", "lignes": set()})
|
| 181 |
+
for r in csv.DictReader(open(RACINE / "data" / "lieux_geo.csv", encoding="utf-8")):
|
| 182 |
+
sources.append({"nom": r["lieu"], "fichier": "data/lieux_geo.csv",
|
| 183 |
+
"position": "estimée" if r.get("lat") else "absente", "lignes": set()})
|
| 184 |
+
for source in sources:
|
| 185 |
+
source["norm"] = normaliser(source["nom"])
|
| 186 |
+
return sources
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def mentions_collecte() -> list[str]:
|
| 190 |
+
"""Les transcriptions des vocaux collectés (lecture seule), pour la priorité."""
|
| 191 |
+
chemin = RACINE / "data" / "collecte" / "metadata.csv"
|
| 192 |
+
if not chemin.exists():
|
| 193 |
+
return []
|
| 194 |
+
return [
|
| 195 |
+
normaliser(" ".join([r.get("transcription_propre") or "", r.get("transcription") or ""]))
|
| 196 |
+
for r in csv.DictReader(open(chemin, encoding="utf-8"))
|
| 197 |
+
]
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def ligne_csv(famille, numero, attendu, trouves) -> dict:
|
| 201 |
+
if not trouves:
|
| 202 |
+
return {"famille": famille, "numero": numero, "nom_attendu": attendu, "present": "non",
|
| 203 |
+
"nom_dans_nos_donnees": "", "fichier": "", "position": "absente"}
|
| 204 |
+
trouves = sorted(trouves, key=lambda s: (RANG_POSITION[s["position"]], "quartier" in s["fichier"], s["nom"]))
|
| 205 |
+
meilleur = trouves[0]
|
| 206 |
+
noms = []
|
| 207 |
+
for s in trouves:
|
| 208 |
+
nom = f"{s['nom']} (quartier de l'arrêt {s['via']})" if s.get("via") else s["nom"]
|
| 209 |
+
if nom not in noms:
|
| 210 |
+
noms.append(nom)
|
| 211 |
+
return {"famille": famille, "numero": numero, "nom_attendu": attendu, "present": "oui",
|
| 212 |
+
"nom_dans_nos_donnees": " ; ".join(noms[:4]), "fichier": meilleur["fichier"],
|
| 213 |
+
"position": meilleur["position"]}
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
def main() -> None:
|
| 217 |
+
sources = charger_sources()
|
| 218 |
+
collecte = mentions_collecte()
|
| 219 |
+
rangees, manquants = [], []
|
| 220 |
+
for famille, motif, numeros, gabarit in FAMILLES:
|
| 221 |
+
par_numero: dict[int, list] = defaultdict(list)
|
| 222 |
+
quartier = QUARTIER_DE_LA_FAMILLE.get(famille, motif)
|
| 223 |
+
lignes_famille: set = set()
|
| 224 |
+
for s in sources:
|
| 225 |
+
for n in numeros_apres(s["norm"], motif):
|
| 226 |
+
par_numero[n].append(s)
|
| 227 |
+
if re.search(quartier, s["norm"]):
|
| 228 |
+
lignes_famille |= s["lignes"]
|
| 229 |
+
for n in numeros:
|
| 230 |
+
attendu = gabarit.format(n)
|
| 231 |
+
rangee = ligne_csv(famille, n, attendu, par_numero.get(n, []))
|
| 232 |
+
rangees.append(rangee)
|
| 233 |
+
# À ajouter : absent, ou présent par son nom seul (aucune position).
|
| 234 |
+
if rangee["present"] == "non" or rangee["position"] == "absente":
|
| 235 |
+
dit = sum(bool(re.search(motif + rf"\s*0?{n}\b", t)) for t in collecte)
|
| 236 |
+
etat = "absent" if rangee["present"] == "non" else "nom seul, sans position"
|
| 237 |
+
manquants.append((famille, attendu, dit, len(lignes_famille), etat))
|
| 238 |
+
for famille, motif, attendu in SANS_NUMERO:
|
| 239 |
+
trouves = [s for s in sources if re.search(motif, s["norm"])]
|
| 240 |
+
rangee = ligne_csv(famille, "-", attendu, trouves)
|
| 241 |
+
rangees.append(rangee)
|
| 242 |
+
if rangee["present"] == "non":
|
| 243 |
+
dit = sum(bool(re.search(motif, t)) for t in collecte)
|
| 244 |
+
manquants.append((famille, attendu, dit, 0, "absent"))
|
| 245 |
+
|
| 246 |
+
SORTIE.parent.mkdir(parents=True, exist_ok=True)
|
| 247 |
+
colonnes = ["famille", "numero", "nom_attendu", "present", "nom_dans_nos_donnees", "fichier", "position"]
|
| 248 |
+
with open(SORTIE, "w", encoding="utf-8", newline="") as fichier:
|
| 249 |
+
ecrivain = csv.DictWriter(fichier, fieldnames=colonnes)
|
| 250 |
+
ecrivain.writeheader()
|
| 251 |
+
ecrivain.writerows(rangees)
|
| 252 |
+
|
| 253 |
+
print(f"Écrit : {SORTIE.relative_to(RACINE)} ({len(rangees)} lignes)\n")
|
| 254 |
+
print("Par famille : présents / attendus (dont position mesurée)")
|
| 255 |
+
familles = list(dict.fromkeys(r["famille"] for r in rangees))
|
| 256 |
+
for famille in familles:
|
| 257 |
+
lignes = [r for r in rangees if r["famille"] == famille]
|
| 258 |
+
presents = [r for r in lignes if r["present"] == "oui"]
|
| 259 |
+
mesures = [r for r in presents if r["position"] == "mesurée"]
|
| 260 |
+
absents = [str(r["numero"]) for r in lignes if r["present"] == "non"]
|
| 261 |
+
print(f" {famille:32} {len(presents):2}/{len(lignes):2} (mesurée {len(mesures)})"
|
| 262 |
+
+ (f" manquent : {', '.join(absents)}" if absents else ""))
|
| 263 |
+
print(f"\nÀ ajouter : {len(manquants)} (absents, ou nom seul sans position)")
|
| 264 |
+
print("Priorité : mentions dans les vocaux collectés, puis lignes qui desservent le quartier")
|
| 265 |
+
for famille, attendu, dit, lignes, etat in sorted(manquants, key=lambda m: (-m[2], -m[3], m[1]))[:15]:
|
| 266 |
+
print(f" {attendu:24} vocaux : {dit:2} lignes du quartier : {lignes:3} ({etat})")
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
if __name__ == "__main__":
|
| 270 |
+
main()
|
src/intent/extract_intent.py
CHANGED
|
@@ -646,6 +646,27 @@ LIEUX_SUPPLEMENTAIRES = (
|
|
| 646 |
# Lieux incertains, situés par leur position.
|
| 647 |
"Mbao", "Yarakh", "Point E", "Cité Soprim", "Soprim", "Cité Keur Gorgui",
|
| 648 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 649 |
|
| 650 |
# Arrêts Dem Dikk que l'app sert depuis les listes officielles (voir
|
| 651 |
# _lieux_ddd_officiels) : comparés à LIEUX et aux lieux ci-dessus, puis ajoutés.
|
|
@@ -678,6 +699,11 @@ def _cible(lieu: str) -> str:
|
|
| 678 |
|
| 679 |
_CIBLES = [(_cible(lieu), lieu) for lieu in LIEUX] + [
|
| 680 |
(_cible(lieu), lieu) for lieu in LIEUX_SUPPLEMENTAIRES
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 681 |
]
|
| 682 |
# Noms normalisés exacts. Un lieu très court (« HLM ») doit être reconnu quand il
|
| 683 |
# est écrit tel quel, même si sa longueur passe sous LONGUEUR_MIN.
|
|
@@ -784,6 +810,12 @@ NOMBRES_FRANCAIS = {
|
|
| 784 |
"deux": "2", "deuxieme": "2", "trois": "3", "troie": "3", "troi": "3", "troisieme": "3",
|
| 785 |
"quatre": "4", "quatrieme": "4", "cinq": "5", "cinquieme": "5",
|
| 786 |
"six": "6", "sis": "6", "sixieme": "6", "sizieme": "6",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 787 |
}
|
| 788 |
QUARTIERS_NUMEROTES = (
|
| 789 |
"sacre coeur", "liberte", "hlm", "unite", "unites", "dieuppeul", "hamo", "grand yoff",
|
|
@@ -992,7 +1024,9 @@ _MOTIF_DEM_COLLE = _motif_dem_colle()
|
|
| 992 |
# de « SICAP Mbao » (« sicap baobab », 0,86) : on préfère ne rien deviner.
|
| 993 |
# « faire » ressemble à « Foire » : « qu'est-ce que tu peux faire » n'est pas un
|
| 994 |
# trajet vers la Foire.
|
| 995 |
-
|
|
|
|
|
|
|
| 996 |
# Chiffres dits et leurs graphies ASR : un chiffre n'est JAMAIS un lieu. Après
|
| 997 |
# « liberté »/« palais » il est converti en chiffre arabe ; isolé, il est ignoré
|
| 998 |
# (sinon « siis » se ferait passer pour l'arrêt « SIPS »).
|
|
|
|
| 646 |
# Lieux incertains, situés par leur position.
|
| 647 |
"Mbao", "Yarakh", "Point E", "Cité Soprim", "Soprim", "Cité Keur Gorgui",
|
| 648 |
)
|
| 649 |
+
# Lot Q2 : quartiers numérotés confirmés par deux sources (HLM 2, Liberté 3,
|
| 650 |
+
# Unité 12, Sicap Baobabs…), positions dans
|
| 651 |
+
# data/corrections/lieux_quartiers_numerotes.csv. Leurs formes parlées
|
| 652 |
+
# (« Baobab », « Sicap Liberté 2 ») sont dans alias_quartiers_numerotes.csv.
|
| 653 |
+
LIEUX_QUARTIERS = Path(__file__).resolve().parents[2] / "data" / "corrections" / "lieux_quartiers_numerotes.csv"
|
| 654 |
+
ALIAS_QUARTIERS = Path(__file__).resolve().parents[2] / "data" / "corrections" / "alias_quartiers_numerotes.csv"
|
| 655 |
+
|
| 656 |
+
|
| 657 |
+
def _lire_colonne(chemin: Path, *colonnes: str) -> list[tuple[str, ...]]:
|
| 658 |
+
if not chemin.exists():
|
| 659 |
+
return []
|
| 660 |
+
with open(chemin, newline="", encoding="utf-8-sig") as fichier:
|
| 661 |
+
return [
|
| 662 |
+
tuple((r.get(c) or "").strip() for c in colonnes)
|
| 663 |
+
for r in csv.DictReader(fichier)
|
| 664 |
+
if all((r.get(c) or "").strip() for c in colonnes)
|
| 665 |
+
]
|
| 666 |
+
|
| 667 |
+
|
| 668 |
+
LIEUX_QUARTIERS_NUMEROTES = tuple(lieu for (lieu,) in _lire_colonne(LIEUX_QUARTIERS, "lieu"))
|
| 669 |
+
LIEUX_SUPPLEMENTAIRES = LIEUX_SUPPLEMENTAIRES + LIEUX_QUARTIERS_NUMEROTES
|
| 670 |
|
| 671 |
# Arrêts Dem Dikk que l'app sert depuis les listes officielles (voir
|
| 672 |
# _lieux_ddd_officiels) : comparés à LIEUX et aux lieux ci-dessus, puis ajoutés.
|
|
|
|
| 699 |
|
| 700 |
_CIBLES = [(_cible(lieu), lieu) for lieu in LIEUX] + [
|
| 701 |
(_cible(lieu), lieu) for lieu in LIEUX_SUPPLEMENTAIRES
|
| 702 |
+
] + [
|
| 703 |
+
# Lot Q2 : formes parlées d'un quartier numéroté, nom exact du lieu.
|
| 704 |
+
(_cible(forme), lieu)
|
| 705 |
+
for forme, lieu in _lire_colonne(ALIAS_QUARTIERS, "forme", "lieu")
|
| 706 |
+
if lieu in LIEUX_QUARTIERS_NUMEROTES
|
| 707 |
]
|
| 708 |
# Noms normalisés exacts. Un lieu très court (« HLM ») doit être reconnu quand il
|
| 709 |
# est écrit tel quel, même si sa longueur passe sous LONGUEUR_MIN.
|
|
|
|
| 810 |
"deux": "2", "deuxieme": "2", "trois": "3", "troie": "3", "troi": "3", "troisieme": "3",
|
| 811 |
"quatre": "4", "quatrieme": "4", "cinq": "5", "cinquieme": "5",
|
| 812 |
"six": "6", "sis": "6", "sixieme": "6", "sizieme": "6",
|
| 813 |
+
# Lot Q2 : les unités des Parcelles vont jusqu'à 26 (« unité douze »,
|
| 814 |
+
# « unité vingt-six ») ; un numéro absent des données ne crée aucun lieu.
|
| 815 |
+
"sept": "7", "huit": "8", "neuf": "9", "dix": "10", "onze": "11", "douze": "12",
|
| 816 |
+
"treize": "13", "quatorze": "14", "quinze": "15", "seize": "16", "dix sept": "17",
|
| 817 |
+
"dix huit": "18", "dix neuf": "19", "vingt": "20", "vingt et un": "21", "vingt deux": "22",
|
| 818 |
+
"vingt trois": "23", "vingt quatre": "24", "vingt cinq": "25", "vingt six": "26",
|
| 819 |
}
|
| 820 |
QUARTIERS_NUMEROTES = (
|
| 821 |
"sacre coeur", "liberte", "hlm", "unite", "unites", "dieuppeul", "hamo", "grand yoff",
|
|
|
|
| 1024 |
# de « SICAP Mbao » (« sicap baobab », 0,86) : on préfère ne rien deviner.
|
| 1025 |
# « faire » ressemble à « Foire » : « qu'est-ce que tu peux faire » n'est pas un
|
| 1026 |
# trajet vers la Foire.
|
| 1027 |
+
# Lot Q2 : « baobab » n'en fait plus partie : Sicap Baobabs a désormais une
|
| 1028 |
+
# position mesurée (deux sources) et se dit « Baobab ».
|
| 1029 |
+
MOTS_HORS_LIEUX = {"faire"}
|
| 1030 |
# Chiffres dits et leurs graphies ASR : un chiffre n'est JAMAIS un lieu. Après
|
| 1031 |
# « liberté »/« palais » il est converti en chiffre arabe ; isolé, il est ignoré
|
| 1032 |
# (sinon « siis » se ferait passer pour l'arrêt « SIPS »).
|
src/matching/geo.py
CHANGED
|
@@ -37,6 +37,8 @@ except ImportError: # pragma: no cover
|
|
| 37 |
DATA = Path(__file__).resolve().parents[2] / "data"
|
| 38 |
ARRETS_GEO = DATA / "arrets_geo.csv"
|
| 39 |
LIEUX_GEO = DATA / "lieux_geo.csv"
|
|
|
|
|
|
|
| 40 |
ITINERAIRES_CSV = DATA / "itineraires_dakar.csv"
|
| 41 |
CACHE_LIEUX = DATA / "sources" / "cache_lieux_nominatim.json"
|
| 42 |
|
|
@@ -329,6 +331,8 @@ class LieuxGeo:
|
|
| 329 |
self._lieux: dict[str, tuple[float, float]] = {}
|
| 330 |
self._absents: set[str] = set()
|
| 331 |
self._lire_lieux(lieux_geo)
|
|
|
|
|
|
|
| 332 |
# Positions revues (data/corrections/positions_corrigees.csv et
|
| 333 |
# positions_estimees.csv) : les mêmes que le moteur v2. AIBD était à
|
| 334 |
# Grand Yoff dans arrets_geo.csv ET dans lieux_geo.csv.
|
|
|
|
| 37 |
DATA = Path(__file__).resolve().parents[2] / "data"
|
| 38 |
ARRETS_GEO = DATA / "arrets_geo.csv"
|
| 39 |
LIEUX_GEO = DATA / "lieux_geo.csv"
|
| 40 |
+
# Lot Q2 : quartiers numérotés confirmés par deux sources (même format : lieu, lat, lon).
|
| 41 |
+
LIEUX_QUARTIERS = DATA / "corrections" / "lieux_quartiers_numerotes.csv"
|
| 42 |
ITINERAIRES_CSV = DATA / "itineraires_dakar.csv"
|
| 43 |
CACHE_LIEUX = DATA / "sources" / "cache_lieux_nominatim.json"
|
| 44 |
|
|
|
|
| 331 |
self._lieux: dict[str, tuple[float, float]] = {}
|
| 332 |
self._absents: set[str] = set()
|
| 333 |
self._lire_lieux(lieux_geo)
|
| 334 |
+
if lieux_geo == LIEUX_GEO:
|
| 335 |
+
self._lire_lieux(LIEUX_QUARTIERS)
|
| 336 |
# Positions revues (data/corrections/positions_corrigees.csv et
|
| 337 |
# positions_estimees.csv) : les mêmes que le moteur v2. AIBD était à
|
| 338 |
# Grand Yoff dans arrets_geo.csv ET dans lieux_geo.csv.
|
src/matching/lieux.py
CHANGED
|
@@ -424,6 +424,12 @@ def _score_nom(requete: str, arret: str) -> float:
|
|
| 424 |
for nom, precisions in HOMONYMES.items():
|
| 425 |
if nom in q and nom in s and any(m in s for m in precisions) and not any(m in q for m in precisions):
|
| 426 |
return 0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
brut = _score_brut(tuple(q), tuple(s))
|
| 428 |
# Une rue ou une route qui porte le nom d'un quartier (« Route de Rufisque »)
|
| 429 |
# n'est pas ce quartier : on la note moins bien qu'un vrai arrêt.
|
|
|
|
| 424 |
for nom, precisions in HOMONYMES.items():
|
| 425 |
if nom in q and nom in s and any(m in s for m in precisions) and not any(m in q for m in precisions):
|
| 426 |
return 0.0
|
| 427 |
+
# Lot Q2 : un numéro de quartier suit son quartier. « Liberté 2 » n'est pas
|
| 428 |
+
# « 2 Voies Liberté 6 » : le 2 y est le nombre de voies, et Liberté porte 6.
|
| 429 |
+
for i, mot in enumerate(q):
|
| 430 |
+
if i and mot.isdigit() and not q[i - 1].isdigit() and q[i - 1] in s:
|
| 431 |
+
if not any(s[j] == q[i - 1] and j + 1 < len(s) and s[j + 1] == mot for j in range(len(s))):
|
| 432 |
+
return 0.0
|
| 433 |
brut = _score_brut(tuple(q), tuple(s))
|
| 434 |
# Une rue ou une route qui porte le nom d'un quartier (« Route de Rufisque »)
|
| 435 |
# n'est pas ce quartier : on la note moins bien qu'un vrai arrêt.
|
src/routing/adapter.py
CHANGED
|
@@ -632,12 +632,14 @@ def _resoudre(matcher, lieu: str) -> dict:
|
|
| 632 |
"par_son_nom": par_son_nom,
|
| 633 |
"point_sur": point_sur,
|
| 634 |
# Lot T5 : positions MESURÉES des arrêts qui portent le nom exact du lieu,
|
| 635 |
-
# seules bases d'une distance à pied affichée.
|
|
|
|
|
|
|
| 636 |
"points_mesures": [
|
| 637 |
coords
|
| 638 |
for nom, coords in positions_exactes
|
| 639 |
if _NETWORK.stop_confidence.get(nom) == "bonne"
|
| 640 |
-
],
|
| 641 |
# Arrêts que l'usager a demandés par leur nom, à l'orthographe près :
|
| 642 |
# « Maristes » -> « Maristes (Par Station Titan) », « Sapeurs Pompiers »
|
| 643 |
# -> « Dieuppeul (Sapeurs Pompiers) », « Fass Mbao » -> « Fassmbao ».
|
|
@@ -1251,6 +1253,24 @@ def direct_par_ligne(matcher, depart: str, arrivee: str, numero: int, compagnies
|
|
| 1251 |
AUTRES_BUS_MAX = 3
|
| 1252 |
|
| 1253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1254 |
def marche_mesuree(lieu: dict, arret: str, etape: dict | None = None) -> int | None:
|
| 1255 |
"""Distance à pied (m, arrondie à 50 m) entre le lieu et l'arrêt, si mesurée des deux côtés.
|
| 1256 |
|
|
|
|
| 632 |
"par_son_nom": par_son_nom,
|
| 633 |
"point_sur": point_sur,
|
| 634 |
# Lot T5 : positions MESURÉES des arrêts qui portent le nom exact du lieu,
|
| 635 |
+
# seules bases d'une distance à pied affichée. Lot Q2 : un quartier
|
| 636 |
+
# numéroté confirmé par deux sources (HLM 2, Unité 25…) a son propre
|
| 637 |
+
# point mesuré : la carte peut dire la vraie distance jusqu'à l'arrêt.
|
| 638 |
"points_mesures": [
|
| 639 |
coords
|
| 640 |
for nom, coords in positions_exactes
|
| 641 |
if _NETWORK.stop_confidence.get(nom) == "bonne"
|
| 642 |
+
] + ([_points_quartiers()[cle_exacte(lieu)]] if cle_exacte(lieu) in _points_quartiers() else []),
|
| 643 |
# Arrêts que l'usager a demandés par leur nom, à l'orthographe près :
|
| 644 |
# « Maristes » -> « Maristes (Par Station Titan) », « Sapeurs Pompiers »
|
| 645 |
# -> « Dieuppeul (Sapeurs Pompiers) », « Fass Mbao » -> « Fassmbao ».
|
|
|
|
| 1253 |
AUTRES_BUS_MAX = 3
|
| 1254 |
|
| 1255 |
|
| 1256 |
+
@lru_cache(maxsize=1)
|
| 1257 |
+
def _points_quartiers() -> dict[str, tuple[float, float]]:
|
| 1258 |
+
"""Lot Q2 : nom exact -> point mesuré (deux sources) des quartiers numérotés."""
|
| 1259 |
+
import csv
|
| 1260 |
+
from pathlib import Path
|
| 1261 |
+
|
| 1262 |
+
chemin = Path(__file__).resolve().parents[2] / "data" / "corrections" / "lieux_quartiers_numerotes.csv"
|
| 1263 |
+
if not chemin.exists():
|
| 1264 |
+
return {}
|
| 1265 |
+
with open(chemin, newline="", encoding="utf-8-sig") as fichier:
|
| 1266 |
+
return {
|
| 1267 |
+
cle_exacte(r["lieu"]): (float(r["lat"]), float(r["lon"]))
|
| 1268 |
+
for r in csv.DictReader(fichier)
|
| 1269 |
+
if (r.get("lieu") or "").strip() and r.get("lat") and r.get("lon")
|
| 1270 |
+
and (r.get("position") or "").startswith("mesurée")
|
| 1271 |
+
}
|
| 1272 |
+
|
| 1273 |
+
|
| 1274 |
def marche_mesuree(lieu: dict, arret: str, etape: dict | None = None) -> int | None:
|
| 1275 |
"""Distance à pied (m, arrondie à 50 m) entre le lieu et l'arrêt, si mesurée des deux côtés.
|
| 1276 |
|