9e1958e7b0
router.WeekdayIndex reads the lexicon and asks the dictionary about the case. Four private lists go away: the habit declension map, the weekday block of the day-plan refusal, the weekday and part-of-day entries of the weather guard, and the stem list in ruwords.go. The stem list was the real defect. mentionsUnknownDay matched sred, pyatnits and subbot with strings.Contains, so sredi, sredstvo and sredniy all read as Wednesday and a question carrying one was answered with onlyNearDaysReply instead of a date. It matches whole tokens now. The weather guard was a third copy of three closed sets that already exist. It kept the rooms of the house, which are its own, and asks the lexicon for the weekdays, the parts of the day and the words that follow v without naming a place. Questions phrased v srede, v utra and v obshchem reached the geocoder as cities before. Full suite green under -race.
73 lines
3.0 KiB
Go
73 lines
3.0 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/kami/maven/internal/router"
|
|
)
|
|
|
|
// TestExtractWeatherLocation — any place he names comes through, not just the
|
|
// six that used to be in a table (Vikunja #421).
|
|
func TestExtractWeatherLocation(t *testing.T) {
|
|
cases := []struct {
|
|
utterance string
|
|
def string
|
|
want string
|
|
}{
|
|
// The cities the table had, and the ones it silently dropped.
|
|
{"какая погода в Москве", "Berlin", "Москве"},
|
|
{"какая погода в Казани", "Berlin", "Казани"},
|
|
{"погода в Тбилиси?", "Berlin", "Тбилиси"},
|
|
{"what's the weather in New York", "Berlin", "New York"},
|
|
{"тепло в Нижнем Новгороде?", "Berlin", "Нижнем Новгороде"},
|
|
// He named nothing: the configured default, and nothing at all when
|
|
// there is no default.
|
|
{"какая сегодня погода", "Berlin", "Berlin"},
|
|
{"какая сегодня погода", "", ""},
|
|
// "в" followed by something that is not a place stays the default —
|
|
// the house sensors and the day words answer elsewhere.
|
|
{"тепло в комнате?", "Berlin", "Berlin"},
|
|
{"какая погода в выходные", "Berlin", "Berlin"},
|
|
// The cases the three private copies of the lexicon were short by
|
|
// (V-581): a weekday in a case the old map did not list, a part of the
|
|
// day in one it did not list, and "в общем".
|
|
{"какая погода в среде", "Berlin", "Berlin"},
|
|
{"какая погода в воскресеньях", "Berlin", "Berlin"},
|
|
{"какая погода в понедельникам", "Berlin", "Berlin"},
|
|
{"какая погода в общем", "Berlin", "Berlin"},
|
|
}
|
|
for _, c := range cases {
|
|
if got := extractWeatherLocation(c.utterance, c.def); got != c.want {
|
|
t.Errorf("extractWeatherLocation(%q, %q) = %q, want %q", c.utterance, c.def, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestCalendarStepsAsideForWeather — the defect (Vikunja #474). "какая сегодня
|
|
// погода в Москве?" answered "на 02.08.2026 ничего нет.": the calendar matches
|
|
// on a day word alone, and it sits above the weather source.
|
|
func TestCalendarStepsAsideForWeather(t *testing.T) {
|
|
h, api := contQueryHandler()
|
|
for _, u := range []string{
|
|
"какая сегодня погода в Москве?",
|
|
"будет дождь завтра?",
|
|
"сколько градусов сегодня?",
|
|
} {
|
|
if reply, ok := h.queryCalendar(context.Background(), &queryTurn{
|
|
dec: router.Decision{Intent: router.IntentQuery, Utterance: u},
|
|
}); ok {
|
|
t.Errorf("the calendar claimed %q with %q", u, reply)
|
|
}
|
|
}
|
|
if api.events != 0 {
|
|
t.Errorf("CalendarEvents called %d times for weather questions, want 0", api.events)
|
|
}
|
|
// The agenda question it exists for still reaches it.
|
|
if _, ok := h.queryCalendar(context.Background(), &queryTurn{
|
|
dec: router.Decision{Intent: router.IntentQuery, Utterance: "что у меня сегодня?"},
|
|
}); !ok {
|
|
t.Fatal("the calendar stopped answering the agenda question")
|
|
}
|
|
}
|