51 lines
1.6 KiB
Go
51 lines
1.6 KiB
Go
// 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")
|
|
}
|
|
|
|
// extractWeatherLocation parses a location from the utterance, or falls back
|
|
// to the configured default. Very basic: just checks for known city names.
|
|
func extractWeatherLocation(u, defaultLoc string) string {
|
|
lower := strings.ToLower(u)
|
|
cities := 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",
|
|
}
|
|
for substr, name := range cities {
|
|
if strings.Contains(lower, substr) {
|
|
return name
|
|
}
|
|
}
|
|
if defaultLoc != "" {
|
|
return defaultLoc
|
|
}
|
|
return "Moscow"
|
|
}
|