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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user