// Package main — weatherq.go holds the weather-query keyword helpers: does // this utterance ask about weather at all, and which city (if any) did it // name. Both are plain substring/lookup matching, not NLU — extend this file // rather than voice.go for anything in that shape. package main import "strings" // isWeatherQuery returns true if the utterance is about weather. func isWeatherQuery(u string) bool { lower := strings.ToLower(u) return strings.Contains(lower, "погод") || strings.Contains(lower, "градус") || strings.Contains(lower, "температур") || strings.Contains(lower, "дожд") || strings.Contains(lower, "холод") || strings.Contains(lower, "тепл") || strings.Contains(lower, "weather") || strings.Contains(lower, "temperature") } // weatherCities — the city names an utterance may name explicitly, as // lowercase substrings mapped to the provider's spelling. This is a // convenience for "какая погода в Лондоне", NOT a source of default truth: // nothing here is used unless he actually said it. var weatherCities = map[string]string{ "москв": "Moscow", "moscow": "Moscow", "питер": "Saint Petersburg", "spb": "Saint Petersburg", "петербур": "Saint Petersburg", "лондон": "London", "london": "London", "париж": "Paris", "paris": "Paris", "берлин": "Berlin", "berlin": "Berlin", "нью-йорк": "New York", "new york": "New York", } // extractWeatherLocation returns the city he named, or the configured default // when he named none. It returns "" when he named none AND no default is // configured — the caller must then say it does not know. // // It used to return "Moscow" in that case. That is a made-up answer presented // as fact: reading out Moscow's temperature to someone who is not in Moscow is // wrong in exactly the way maven must never be wrong. voice.weather // .default_location is the only source of an unstated location. func extractWeatherLocation(u, defaultLoc string) string { lower := strings.ToLower(u) for substr, name := range weatherCities { if strings.Contains(lower, substr) { return name } } return defaultLoc }