Recognize Dutch compound GIS theme queries
This commit is contained in:
@@ -95,10 +95,20 @@ class GeoAssistantService:
|
||||
def requested_themes(cls, question: str) -> set[str] | None:
|
||||
normalized = " ".join(re.sub(r"[^\w]+", " ", question.casefold()).split())
|
||||
padded = f" {normalized} "
|
||||
tokens = normalized.split()
|
||||
|
||||
def term_is_present(term: str) -> bool:
|
||||
if " " in term:
|
||||
return f" {term} " in padded
|
||||
return any(
|
||||
token == term or (len(term) >= 4 and token.startswith(term))
|
||||
for token in tokens
|
||||
)
|
||||
|
||||
themes = {
|
||||
theme
|
||||
for theme, terms in cls.THEME_QUERY_TERMS.items()
|
||||
if any(f" {term} " in padded for term in terms)
|
||||
if any(term_is_present(term) for term in terms)
|
||||
}
|
||||
return themes or None
|
||||
|
||||
|
||||
@@ -112,6 +112,8 @@ def test_geo_assistant_limits_explicit_cross_domain_question_to_requested_themes
|
||||
("Hoe evolueerden bevolking en bosoppervlakte?", {"population", "forest"}),
|
||||
("Toon wegen, waterlopen en overstromingen.", {"roads", "water", "flood_hazard"}),
|
||||
("Welke bodemtypes en landbouwteelten komen voor?", {"soil", "agriculture"}),
|
||||
("Geef bodemdetails en perceeloppervlaktes voor Mol.", {"soil", "parcels"}),
|
||||
("Vergelijk bevolkingsontwikkeling en voorzieningenniveau.", {"population", "services"}),
|
||||
("Vat de belangrijkste gebiedsmetingen samen.", None),
|
||||
("Welke officiële bronnen zijn beschikbaar?", None),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user