spb/trouve-ka Public
Trouve-KA — moteur de recherche web indépendant, Québec-first. Crawler distribué, index OpenSearch, ranking bilingue, galerie d'images. En prod : www.trouve-ka.com
Python 76.8%
TypeScript 15.7%
SQL 3.9%
Shell 1.4%
CSS 1.3%
Dockerfile 0.7%
1# Trouve-KA — tests du scoring Québec2# Author: Simon-Pierre Boucher3# Contact: contact@spboucher.ai45from trouveka.classifier import score_page6from trouveka.types import ParsedPage789def _page(**kwargs) -> ParsedPage:10 defaults = {"url": "https://example.com/page", "title": "", "body": ""}11 return ParsedPage(**(defaults | kwargs))121314def test_quebec_business_scores_high():15 page = _page(16 url="https://plomberiexyz.qc.ca/services",17 title="Plomberie XYZ — Plombier à Gatineau",18 description="Service de plomberie résidentielle en Outaouais",19 body="Plomberie XYZ dessert Gatineau et l'Outaouais. 123 rue Principale, Gatineau (Québec) J8X 3X3. "20 "Appelez-nous au 819-555-1234. Urgences 24h partout au Québec.",21 headings=["Plombier Gatineau", "Nos services"],22 language="fr",23 )24 signals = score_page(page, "plomberiexyz.qc.ca")25 assert signals.score > 0.726 assert "gatineau" in signals.locations27 assert "tld_quebec" in signals.reasons28 assert "code_postal_qc" in signals.reasons293031def test_ontario_business_scores_low():32 page = _page(33 url="https://ottawaplumbing.ca/",34 title="Ottawa Plumbing Services",35 description="Plumbing services in Ottawa, Ontario",36 body="We serve Ottawa, Kanata and Nepean. 456 Bank Street, Ottawa, ON K1S 3T4. Call 613-555-9999.",37 headings=["Plumbing Ottawa"],38 language="en",39 )40 signals = score_page(page, "ottawaplumbing.ca")41 assert signals.score < 0.2424344def test_nyt_article_about_montreal_gets_page_signal():45 # Un article international SUR Montréal : le domaine n'est pas québécois,46 # mais la page a un signal réel (page_quebec_score > 0, sans être maximal).47 page = _page(48 url="https://www.nytimes.com/2026/01/01/travel/montreal.html",49 title="36 Hours in Montreal",50 description="What to do in Montreal, Quebec's largest city",51 body="Montreal is the largest city in Quebec. From the Plateau-Mont-Royal to Old Montreal, "52 "the city offers poutine, festivals and more. Nearby Laval and Longueuil...",53 headings=["36 Hours in Montreal"],54 language="en",55 )56 signals = score_page(page, "nytimes.com")57 assert 0.2 < signals.score < 0.858 assert "montreal" in signals.locations596061def test_generic_english_page_scores_near_zero():62 page = _page(63 url="https://techblog.com/post",64 title="Understanding Rust lifetimes",65 body="Rust lifetimes are a way to express the scope of references in your program. " * 20,66 language="en",67 )68 signals = score_page(page, "techblog.com")69 assert signals.score < 0.1707172def test_french_alone_is_not_proof():73 # Une page française de France ne doit pas passer le seuil sur la langue seule74 page = _page(75 url="https://lemonde.fr/article",76 title="Actualités françaises",77 body="La France annonce de nouvelles mesures. Paris, Lyon et Marseille concernées. " * 10,78 language="fr",79 )80 signals = score_page(page, "lemonde.fr")81 assert signals.score < 0.3828384def test_score_saturates_below_one():85 body = "Montréal Québec Gatineau Sherbrooke Laval " * 100 + " H2X 1Y6 G1R 4S9 514-555-0000 Hydro-Québec"86 page = _page(url="https://x.qc.ca/", title="Montréal Québec", body=body, language="fr")87 signals = score_page(page, "x.qc.ca")88 assert 0.8 < signals.score <= 1.089