Route household knowledge through cognition
CI / test (push) Successful in 1m50s
CI / test (pull_request) Successful in 1m16s

This commit is contained in:
m
2026-08-26 04:31:18 +03:00
parent f316f7ec3f
commit 4e3d153557
6 changed files with 136 additions and 14 deletions
@@ -226,6 +226,16 @@ func TestNearestPlaneUsesTravelContextAndCurrentDay(t *testing.T) {
}
}
func TestTravelResearchQueryUsesKnownOriginForTrainSchedule(t *testing.T) {
now := time.Date(2026, time.August, 26, 9, 0, 0, 0, time.UTC)
history := []interaction.HumanUtterance{{Content: "я сейчас в Москве"}}
got := TravelResearchQuery("найди поезд до Петербурга", history, now)
want := "расписание поездов из Москве в Петербурга время отправления сегодня 26.08.2026"
if got != want {
t.Fatalf("train schedule query lost route context or primary outcome: %q", got)
}
}
func TestIndependentRequestPartsKeepsCoordinatedEntitiesTogether(t *testing.T) {
if got := IndependentRequestParts("какая разница во времени между Москвой и Шанхаем?"); len(got) != 1 {
t.Fatalf("coordinated entities became independent requests: %#v", got)
+26
View File
@@ -46,6 +46,12 @@ func TravelResearchQuery(message string, history []interaction.HumanUtterance, n
if origin != "" && !containsStemInTokens(tokens, "из", "откуда", "от") {
query += " отправление из " + origin
}
} else if trainScheduleRequest(tokens) {
origin := travelContextOrigin(history)
destination := travelContextDestinationFromTokens(tokens)
if origin != "" && destination != "" {
return trainScheduleResearchQuery(origin, destination, now, containsStemInTokens(tokens, "ближ"))
}
} else if travelCue(tokens) && !containsStemInTokens(tokens, "из", "откуда", "от") {
origin := travelContextOrigin(history)
destination := travelContextDestinationFromTokens(tokens)
@@ -61,6 +67,21 @@ func TravelResearchQuery(message string, history []interaction.HumanUtterance, n
return query
}
// trainScheduleResearchQuery formulates an observed schedule request from the
// user's route and remembered origin. It contains no city, provider or answer
// catalogue: actual departure data remains evidence from the selected source.
func trainScheduleResearchQuery(origin, destination string, now time.Time, nearest bool) string {
prefix := "расписание поездов"
if nearest {
prefix = "ближайшие поезда"
}
query := prefix + " из " + origin + " в " + destination + " время отправления"
if !now.IsZero() {
query += " сегодня " + now.Format("02.01.2006")
}
return query
}
// nearestAirTravelSearchQuery is a capability-local search formulation, not a
// provider or place lookup. It removes conversational imperatives while
// preserving the two user-derived route endpoints and the implicit current-day
@@ -401,6 +422,11 @@ func travelCue(tokens []string) bool {
return containsStemInTokens(tokens, "билет", "рейс", "самолет", "самолёт", "вылет", "поезд", "автобус", "перелет", "перелёт")
}
func trainScheduleRequest(tokens []string) bool {
return containsStemInTokens(tokens, "поезд") &&
(containsStemInTokens(tokens, "найд", "ближ", "расписан", "отправ", "прибуд", "едет", "едут") || len(tokens) > 1)
}
func nearestAirTravelRequest(tokens []string) bool {
return containsStemInTokens(tokens, "ближ") && containsStemInTokens(tokens, "самолет", "самолёт", "авиарейс", "перелет", "перелёт")
}