the calendar answers his day, not any day (V-552)
queryCalendar matched on a day word and stepped aside only on weather wording. Every world question naming a day was claimed by it and answered with an empty schedule: "какой сегодня курс доллара" replied "на 05.08.2026 ничего нет", which reads as an answer about a subject she never looked at. All four probe utterances have an answer in search, and search sits below the calendar. V-474 fixed one instance of the class. Sunset, holidays, exchange rates and world news are the same class and weather wording does not cover them. router.IsAgendaQuestion is the narrowing. Its first arm reuses AgendaQueryGrammars, so the rule that routes a question to the query chain and the rule that lets the calendar answer it cannot drift. The second reads a scheduled-thing noun, wider than the grammars because "какие встречи завтра" carries no possessive. The third claims a question that names no subject of its own. A continuation is exempt: "а завтра?" cannot name an agenda, and this is the only date-aware source there is.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package router
|
||||
|
||||
import "regexp"
|
||||
|
||||
// IsAgendaQuestion answers whether an utterance asks about the owner's own
|
||||
// schedule, as opposed to merely naming a day.
|
||||
//
|
||||
// It exists because the calendar query source used to match on a day word and
|
||||
// nothing else (Vikunja #552). Every world question that happened to name a
|
||||
// day was claimed by the calendar and answered with an empty schedule: "какой
|
||||
// сегодня курс доллара" replied "на 05.08.2026 ничего нет", which reads as an
|
||||
// answer about a subject she never looked at. V-474 had already fixed one
|
||||
// instance of the class by teaching the calendar to step aside on weather
|
||||
// wording. Sunset, holidays, exchange rates and world news are the same class
|
||||
// and weather wording does not cover them.
|
||||
//
|
||||
// Three arms, and the order is only readability — any one of them is enough:
|
||||
//
|
||||
// - an agenda grammar already claims the phrasing. Reusing
|
||||
// AgendaQueryGrammars means the rule that ROUTES a question to the query
|
||||
// chain and the rule that lets the CALENDAR answer it cannot drift apart.
|
||||
// - the utterance names a scheduled thing. Wider than the grammars on
|
||||
// purpose: "какие встречи завтра" carries no possessive and no plan noun,
|
||||
// so no grammar claims it, and it is plainly a calendar question.
|
||||
// - the question names no subject of its own. "что сегодня?" is his agenda
|
||||
// by default, because there is nothing else for it to be about. This is
|
||||
// the same test the bare-imperative Praxis arm applies.
|
||||
//
|
||||
// Not a routing decision and not a fact, so a pattern is the right mechanism
|
||||
// here: it selects which source answers, and every source below still runs
|
||||
// when it returns false.
|
||||
func IsAgendaQuestion(u string) bool {
|
||||
for _, g := range AgendaQueryGrammars() {
|
||||
if g.Pattern.MatchString(u) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return scheduledThing.MatchString(u) || subjectlessDayQuestion.MatchString(u)
|
||||
}
|
||||
|
||||
// scheduledThing — the nouns that name something on a calendar. Closed in the
|
||||
// sense that matters: these are the words for an appointment itself, not the
|
||||
// words for what an appointment is about. The stems are the union of the ones
|
||||
// AgendaQueryGrammars already carries, read here as a noun test rather than as
|
||||
// part of a phrasing.
|
||||
//
|
||||
// Stems and not whole words, because Russian declines them and "какие встречи"
|
||||
// and "на встречу" are one question.
|
||||
var scheduledThing = regexp.MustCompile(`(?i)(календар|расписани|повестк|планёрк|планерк|встреч|созвон|митинг|совещани|приём|прием|собеседовани|тренировк|занятие|занятия)`)
|
||||
|
||||
// subjectlessDayQuestion — "что сегодня?", "что там на завтра", "что в среду".
|
||||
// An interrogative, an optional preposition, a day word, and nothing else. The
|
||||
// anchors at both ends are the whole point: the moment the sentence names what
|
||||
// it is asking about, it stops being his agenda and this must not match.
|
||||
var subjectlessDayQuestion = regexp.MustCompile(
|
||||
`(?i)^\s*(что|чего|какие|сколько|what)\s+(там\s+|ещё\s+|еще\s+)?(на\s+|в\s+|во\s+)?` +
|
||||
dayWordPattern + `\s*[?!.]*$`)
|
||||
@@ -0,0 +1,41 @@
|
||||
package router
|
||||
|
||||
import "testing"
|
||||
|
||||
// The four utterances in Vikunja #552 plus the ones that must keep reaching
|
||||
// the calendar. The list is the whole point of the predicate: every "want
|
||||
// false" row was answered "на 05.08.2026 ничего нет" on the deployed daemon.
|
||||
func TestIsAgendaQuestionSeparatesHisDayFromTheWorld(t *testing.T) {
|
||||
tests := []struct {
|
||||
utterance string
|
||||
want bool
|
||||
}{
|
||||
// His day.
|
||||
{"что у меня сегодня", true},
|
||||
{"во сколько у меня встреча сегодня", true},
|
||||
{"что в календаре на завтра", true},
|
||||
{"какие планы на завтра", true},
|
||||
{"какие встречи завтра", true},
|
||||
{"когда планёрка", true},
|
||||
{"покажи расписание на среду", true},
|
||||
{"что дальше?", true},
|
||||
// No subject of its own, so his day by default.
|
||||
{"что сегодня?", true},
|
||||
{"что на завтра", true},
|
||||
{"что там в среду?", true},
|
||||
|
||||
// The world, naming a day. Every one of these is #552.
|
||||
{"во сколько закат сегодня", false},
|
||||
{"какой сегодня курс доллара", false},
|
||||
{"какой сегодня праздник", false},
|
||||
{"что интересного произошло сегодня в мире", false},
|
||||
{"кто выиграл вчера матч", false},
|
||||
// A day word plus a subject is never subjectless, however short.
|
||||
{"что за праздник сегодня", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := IsAgendaQuestion(tt.utterance); got != tt.want {
|
||||
t.Errorf("IsAgendaQuestion(%q) = %v, want %v", tt.utterance, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user