diff --git a/modules/interaction/domain/semantics_test.go b/modules/interaction/domain/semantics_test.go index f95d4bf..e7e92cc 100644 --- a/modules/interaction/domain/semantics_test.go +++ b/modules/interaction/domain/semantics_test.go @@ -80,6 +80,9 @@ func TestTravelSearchClarification(t *testing.T) { if got := TravelSearchClarification("а куда летим?", history); got == "" { t.Fatal("follow-up must remain attached to the travel goal") } + if got := TravelSearchClarification("какая погода в Сочи?", history); got != "" { + t.Fatalf("unrelated question must not inherit travel goal, got %q", got) + } } func TestInterpretUtteranceDirectiveRecordsOutcomeWithoutExecution(t *testing.T) { diff --git a/modules/interaction/domain/travel.go b/modules/interaction/domain/travel.go index 019387d..91a653a 100644 --- a/modules/interaction/domain/travel.go +++ b/modules/interaction/domain/travel.go @@ -30,7 +30,7 @@ func StripAssistantVocative(message string) string { func TravelSearchClarification(message string, history []interaction.HumanUtterance) string { current := semanticTokens(StripAssistantVocative(message)) travel := travelCue(current) - if !travel { + if !travel && travelFollowUpCue(current) { for index := len(history) - 1; index >= 0; index-- { if travelCue(semanticTokens(history[index].Content)) { travel = true @@ -62,6 +62,10 @@ func travelCue(tokens []string) bool { return containsStemInTokens(tokens, "билет", "рейс", "поезд", "автобус", "перелет", "перелёт") } +func travelFollowUpCue(tokens []string) bool { + return containsStemInTokens(tokens, "куда", "откуда", "маршрут", "летим", "дата", "число") +} + func hasDigit(value string) bool { for _, runeValue := range value { if runeValue >= '0' && runeValue <= '9' {