Keep conversational fallback on the requested meaning
CI / test (push) Successful in 1m3s
CI / test (pull_request) Successful in 1m3s

This commit is contained in:
m
2026-08-25 00:57:48 +03:00
parent ca9db836de
commit b029adfb43
4 changed files with 67 additions and 7 deletions
+47 -4
View File
@@ -214,7 +214,7 @@ func semanticScores(tokens []string, hasQuestionMark bool, explicitCorrection bo
questionWords := map[string]struct{}{"кто": {}, "что": {}, "как": {}, "почему": {}, "зачем": {}, "где": {}, "когда": {}, "сколько": {}, "какой": {}, "какая": {}, "какие": {}, "чей": {}}
conversationWords := []string{"привет", "здравствуйте", "спасибо", "ку", "здравствуй"}
investigateStems := []string{"разбер", "проверь", "проанализ", "исслед", "выясн", "уточн", "подум", "понят", "посмотри", "попроб", "повтор", "снов"}
directiveStems := []string{"сдел", "запуст", "созд", "настро", "добав", "измени", "помен", "использ", "удал", "напом", "подключ", "исправ", "обрати", "спрос", "посчитай", "рассчитай", "ответь"}
directiveStems := []string{"сдел", "запуст", "созд", "настро", "добав", "измени", "помен", "использ", "удал", "напом", "подключ", "исправ", "обрати", "спрос", "найд", "посчитай", "рассчитай", "ответь"}
explanatoryRequestStems := []string{"расска", "раска", "объяс", "опиш", "покаж", "подскаж", "сообщ"}
preferenceStems := []string{"предпоч", "хочу", "лучше", "не используй"}
hypothesisStems := []string{"думаю", "кажется", "гипотез", "похоже"}
@@ -472,13 +472,56 @@ func capabilityHintsFor(primary, secondary interaction.SpeechAct, tokens []strin
// place, person or one-off question branch; when the cue is absent the
// truth-first fallback remains in force.
func sourceDependentQuestion(primary, secondary interaction.SpeechAct, tokens []string) bool {
inquiry := primary == interaction.SpeechActQuestion || primary == interaction.SpeechActRequestToInvestigate || secondary == interaction.SpeechActQuestion || secondary == interaction.SpeechActRequestToInvestigate
inquiry := primary == interaction.SpeechActQuestion || primary == interaction.SpeechActRequestToInvestigate || secondary == interaction.SpeechActQuestion || secondary == interaction.SpeechActRequestToInvestigate || (primary == interaction.SpeechActDirective && containsStemInTokens(tokens, "найд", "поищ", "подбер"))
if !inquiry {
return false
}
currentCue := containsStemInTokens(tokens, "сейчас", "сегодня", "текущ", "актуаль", "последн", "прямо")
observedStateCue := containsStemInTokens(tokens, "погод", "температур", "осад", "ветер", "курс", "цен", "стоим", "новост", "распис", "событ", "статус", "доступен", "работает", "запущен", "срок")
return currentCue || observedStateCue
observedStateCue := containsStemInTokens(tokens, "погод", "температур", "осад", "ветер", "курс", "цен", "стоим", "новост", "распис", "событ", "статус", "доступен", "работает", "запущен", "срок") || approximateToken(tokens, "погод", 2)
placeSearchCue := containsStemInTokens(tokens, "ресторан", "кафе", "отел", "магаз", "мест", "ближ", "адрес", "организац")
return currentCue || observedStateCue || placeSearchCue
}
// approximateToken catches ordinary keyboard slips without turning routing
// into a list of complete user questions. It is only used for broad
// source-dependent concepts such as weather.
func approximateToken(tokens []string, target string, maxDistance int) bool {
for _, token := range tokens {
if editDistance([]rune(token), []rune(target)) <= maxDistance {
return true
}
}
return false
}
func editDistance(left, right []rune) int {
previous := make([]int, len(right)+1)
for index := range previous {
previous[index] = index
}
for i, leftRune := range left {
current := make([]int, len(right)+1)
current[0] = i + 1
for j, rightRune := range right {
cost := 0
if leftRune != rightRune {
cost = 1
}
current[j+1] = minInt(current[j]+1, previous[j+1]+1, previous[j]+cost)
}
previous = current
}
return previous[len(right)]
}
func minInt(values ...int) int {
result := values[0]
for _, value := range values[1:] {
if value < result {
result = value
}
}
return result
}
func informationRequestKind(message string, candidate interaction.SemanticCandidate) interaction.InformationRequestKind {
+15
View File
@@ -154,6 +154,21 @@ func TestSourceDependentQuestionRequestsWebResearchWithoutEntityBranch(t *testin
}
}
func TestSourceDependentQuestionToleratesTyposAndPlaceSearch(t *testing.T) {
for _, message := range []string{"какая пугода в Сочи", "найди ближайший ресторан в Сочи"} {
candidate := BuildDeterministicCandidate(message, "", time.Unix(10, 0).UnixMilli())
seen := false
for _, hint := range candidate.CapabilityHints {
if hint == "WEB_RESEARCH" {
seen = true
}
}
if !seen {
t.Fatalf("message=%q was not routed to WEB_RESEARCH: %+v", message, candidate)
}
}
}
func TestRequestToClarifyCurrentFactRequestsWebResearch(t *testing.T) {
candidate := BuildDeterministicCandidate("уточни погоду в питере", "", time.Unix(10, 0).UnixMilli())
for _, hint := range candidate.CapabilityHints {