refactor: prioritize cognitive interpretation over deterministic rules
CI / test (push) Failing after 14s
CI / test (push) Failing after 14s
This commit is contained in:
@@ -175,7 +175,8 @@ func semanticScores(tokens []string, hasQuestionMark bool, explicitCorrection bo
|
||||
interaction.SpeechActConversational: 0,
|
||||
}
|
||||
if hasQuestionMark {
|
||||
scores[interaction.SpeechActQuestion] += 3
|
||||
scores[interaction.SpeechActQuestion] += 4
|
||||
scores[interaction.SpeechActRequestToInvestigate]++
|
||||
}
|
||||
if explicitCorrection {
|
||||
scores[interaction.SpeechActCorrection] += 6
|
||||
@@ -192,14 +193,17 @@ func semanticScores(tokens []string, hasQuestionMark bool, explicitCorrection bo
|
||||
scores[interaction.SpeechActConfirmation] += 2
|
||||
}
|
||||
questionWords := map[string]struct{}{"кто": {}, "что": {}, "как": {}, "почему": {}, "зачем": {}, "где": {}, "когда": {}, "сколько": {}, "какой": {}, "какая": {}, "какие": {}, "чей": {}}
|
||||
conversationWords := []string{"привет", "здравствуйте", "спасибо", "ку", "здравствуй", "добрый", "день", "добрый день"}
|
||||
investigateStems := []string{"разбер", "проверь", "проанализ", "исслед", "выясн", "посмотри", "узнай", "расскаж", "объясн", "поясн"}
|
||||
directiveStems := []string{"сдел", "запуст", "созд", "настро", "добав", "измени", "помен", "поменя", "измен", "использ", "удал", "напом", "подключ", "исправ", "обрати", "поправ", "обнов", "ответь", "посмотри"}
|
||||
conversationWords := []string{"привет", "здравствуйте", "спасибо", "ку", "здравствуй", "добрый"}
|
||||
investigateStems := []string{"разбер", "проверь", "провери", "проанализ", "исслед", "выясн", "узнай"}
|
||||
directiveStems := []string{"сдел", "запуст", "созд", "настро", "добав", "измени", "помен", "поменя", "измен", "использ", "удал", "напом", "подключ", "исправ", "обрати", "поправ", "обнов", "ответь", "посмотри", "проверь"}
|
||||
preferenceStems := []string{"предпоч", "хочу", "лучше", "не используй"}
|
||||
hypothesisStems := []string{"думаю", "кажется", "гипотез", "похоже"}
|
||||
decisionStems := []string{"решил", "решение", "выбираю"}
|
||||
arithmeticMarker := false
|
||||
for index, token := range tokens {
|
||||
if firstPersonPastReport(tokens, index) && containsStem(token, directiveStems...) {
|
||||
continue
|
||||
}
|
||||
if _, ok := questionWords[token]; ok && !(token == "что" && index+1 < len(tokens) && tokens[index+1] == "нибудь") {
|
||||
scores[interaction.SpeechActQuestion] += 4
|
||||
}
|
||||
@@ -226,37 +230,24 @@ func semanticScores(tokens []string, hasQuestionMark bool, explicitCorrection bo
|
||||
arithmeticMarker = true
|
||||
}
|
||||
}
|
||||
if len(tokens) >= 2 && len(tokens[0]) >= 4 && (strings.HasSuffix(tokens[0], "й") || strings.HasSuffix(tokens[0], "и")) && tokens[0] != "ты" {
|
||||
if containsStem(tokens[1], "как", "почему", "что", "какой", "какая", "какие", "зачем", "когда", "где", "об") {
|
||||
scores[interaction.SpeechActQuestion] += 3
|
||||
scores[interaction.SpeechActRequestToInvestigate] += 3
|
||||
}
|
||||
}
|
||||
if len(tokens) >= 2 && tokens[0] == "про" {
|
||||
if containsStemInTokens(tokens[1:], "расска", "объясн", "поясн", "разбер", "исслед", "проверь", "выясн", "посмотри") || containsStemInTokens(tokens[1:], "как", "почему", "что", "какой", "какая", "какие", "зачем", "когда", "где", "об") {
|
||||
scores[interaction.SpeechActQuestion] += 4
|
||||
scores[interaction.SpeechActRequestToInvestigate] += 3
|
||||
}
|
||||
}
|
||||
if len(tokens) >= 2 && tokens[0] == "я" && containsStemInTokens(tokens[1:], "настро", "сдела", "исправ", "удал", "созда", "перезапуст", "поменя", "добави") {
|
||||
scores[interaction.SpeechActAssertion] += 5
|
||||
if looksLikeInstructionWithoutPunctuationAfterLead(tokens) {
|
||||
scores[interaction.SpeechActQuestion] += 4
|
||||
scores[interaction.SpeechActRequestToInvestigate] += 2
|
||||
}
|
||||
if arithmeticMarker {
|
||||
scores[interaction.SpeechActQuestion] += 2
|
||||
}
|
||||
if len(tokens) > 0 && strings.HasSuffix(tokens[0], "ешь") {
|
||||
scores[interaction.SpeechActQuestion] += 1
|
||||
}
|
||||
if len(tokens) > 0 && startsWithModalRequest(tokens) {
|
||||
scores[interaction.SpeechActQuestion] += 2
|
||||
scores[interaction.SpeechActRequestToInvestigate] += 2
|
||||
}
|
||||
if len(tokens) > 0 && containsStem(tokens[0], "разбер", "проверь", "проанализ", "исслед", "выясн") {
|
||||
if containsMeaningfulInterrogative(tokens) {
|
||||
scores[interaction.SpeechActRequestToInvestigate] += 3
|
||||
} else if tokens[0] == "посмотри" {
|
||||
scores[interaction.SpeechActRequestToInvestigate] += 1
|
||||
}
|
||||
if looksLikeInformationRequest(tokens) {
|
||||
scores[interaction.SpeechActQuestion] += 4
|
||||
scores[interaction.SpeechActRequestToInvestigate] += 2
|
||||
}
|
||||
if !hasQuestionMark && containsInterrogative(tokens) {
|
||||
scores[interaction.SpeechActQuestion] += 4
|
||||
scores[interaction.SpeechActRequestToInvestigate] += 2
|
||||
}
|
||||
if containsModelReference(tokens) {
|
||||
scores[interaction.SpeechActQuestion] += 2
|
||||
@@ -353,6 +344,12 @@ func needsCognitionForCandidate(primary, secondary interaction.SpeechAct, tokens
|
||||
if primary == interaction.SpeechActConversational && secondary == interaction.SpeechActDirective {
|
||||
return true
|
||||
}
|
||||
if primary == interaction.SpeechActQuestion && containsMeaningfulInterrogative(tokens) {
|
||||
return true
|
||||
}
|
||||
if isAssistantStatusProbe(primary, secondary, tokens) {
|
||||
return true
|
||||
}
|
||||
if primary == interaction.SpeechActAssertion && containsModelReference(tokens) && containsStemInTokens(tokens, "работает", "падает", "растет", "растёет", "свободно", "виснет") {
|
||||
return true
|
||||
}
|
||||
@@ -362,9 +359,6 @@ func needsCognitionForCandidate(primary, secondary interaction.SpeechAct, tokens
|
||||
if secondary == interaction.SpeechActQuestion || secondary == interaction.SpeechActRequestToInvestigate {
|
||||
return true
|
||||
}
|
||||
if isAssistantStatusProbe(primary, secondary, tokens) {
|
||||
return true
|
||||
}
|
||||
if primary == interaction.SpeechActDirective && (containsInterrogative(tokens) || containsModelReference(tokens) || containsStemInTokens(tokens, "обрати", "посмотри", "разбер", "исправ", "обнов", "добав")) {
|
||||
return true
|
||||
}
|
||||
@@ -405,9 +399,23 @@ func capabilityHintsFor(primary, secondary interaction.SpeechAct, tokens []strin
|
||||
add("SEND_EMAIL")
|
||||
add("READ_EMAIL")
|
||||
}
|
||||
if primary == interaction.SpeechActDirective && containsStemInTokens(tokens, "добав", "реализ", "поддержк") {
|
||||
add("MODIFY_CODE")
|
||||
}
|
||||
if containsToken(tokens, "напомни") || containsToken(tokens, "напомин") {
|
||||
add("SCHEDULE_REMINDER")
|
||||
}
|
||||
if primary == interaction.SpeechActRequestToInvestigate || (primary == interaction.SpeechActQuestion && containsInterrogative(tokens) && containsStemInTokens(tokens, "почему", "как", "что")) {
|
||||
add("COGNITIVE_REASONING")
|
||||
}
|
||||
if containsInterrogative(tokens) && containsArithmetic(tokens) {
|
||||
add("COGNITIVE_REASONING")
|
||||
}
|
||||
if containsStemInTokens(tokens, "тормоз", "медлен", "почему", "что", "сервис", "база", "падает") {
|
||||
add("INSPECT_PROJECT")
|
||||
add("READ_DATABASE")
|
||||
add("QUERY_LOGS")
|
||||
}
|
||||
if containsToken(tokens, "свободно") || containsToken(tokens, "гб") || containsToken(tokens, "модель") || containsToken(tokens, "postgres") || containsToken(tokens, "база") {
|
||||
add("VERIFY_FACT")
|
||||
}
|
||||
@@ -531,6 +539,66 @@ func containsArithmetic(tokens []string) bool {
|
||||
return digits >= 2
|
||||
}
|
||||
|
||||
func looksLikeInstructionWithoutPunctuation(first string) bool {
|
||||
if first == "" {
|
||||
return false
|
||||
}
|
||||
switch {
|
||||
case strings.HasSuffix(first, "й"), strings.HasSuffix(first, "и"), strings.HasSuffix(first, "ите"):
|
||||
return utf8.RuneCountInString(first) > 3
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func looksLikeInstructionWithoutPunctuationAfterLead(tokens []string) bool {
|
||||
if len(tokens) < 2 {
|
||||
return false
|
||||
}
|
||||
if utf8.RuneCountInString(tokens[0]) > 3 {
|
||||
return false
|
||||
}
|
||||
switch tokens[0] {
|
||||
case "про", "по", "на", "в", "за":
|
||||
default:
|
||||
return false
|
||||
}
|
||||
for _, token := range tokens[1:] {
|
||||
if utf8.RuneCountInString(token) <= 3 {
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case strings.HasSuffix(token, "ешь"), strings.HasSuffix(token, "и"), strings.HasSuffix(token, "й"), strings.HasSuffix(token, "те"), strings.HasSuffix(token, "йте"):
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func looksLikeInformationRequest(tokens []string) bool {
|
||||
if len(tokens) < 2 {
|
||||
return false
|
||||
}
|
||||
if !containsSuffix(tokens[0], "й", "и", "те", "йте") {
|
||||
return false
|
||||
}
|
||||
for _, token := range tokens[1:] {
|
||||
if containsStem(token, "что", "как", "почему", "зачем", "когда", "кто", "какой", "какая", "какие", "об", "про", "подроб") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func containsSuffix(value string, suffixes ...string) bool {
|
||||
for _, suffix := range suffixes {
|
||||
if strings.HasSuffix(value, suffix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func likelyConsequential(tokens []string) bool {
|
||||
for _, token := range tokens {
|
||||
if containsStem(token, "удал", "снес", "замен", "миграц", "парол", "опубли", "перезапуст", "смени", "купи", "установ", "внедр") {
|
||||
@@ -550,6 +618,24 @@ func followsNibud(tokens []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func firstPersonPastReport(tokens []string, index int) bool {
|
||||
if len(tokens) == 0 || index == 0 {
|
||||
return false
|
||||
}
|
||||
if tokens[0] != "я" && tokens[0] != "мы" {
|
||||
return false
|
||||
}
|
||||
if index < 2 {
|
||||
return false
|
||||
}
|
||||
for _, token := range tokens[:index] {
|
||||
if token == "всё" || token == "все" || token == "сейчас" || token == "уже" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func containsModelReference(tokens []string) bool {
|
||||
for _, token := range tokens {
|
||||
if token == "модель" || token == "модели" || token == "postgres" || token == "postgresql" || strings.Contains(token, "gemma") || strings.Contains(token, "гемма") || strings.Contains(token, "qwen") {
|
||||
|
||||
@@ -129,6 +129,8 @@ func TestInterpretUtteranceNaturalRussianHelpflowUsesContextAwareCognitionInput(
|
||||
{message: "Расскажи как это работает", wantSpeech: "", wantCognition: true, allowNoMatch: true},
|
||||
{message: "можешь объяснить почему база растёт", wantSpeech: "", wantCognition: true, allowNoMatch: true},
|
||||
{message: "ПОЧЕМУ postgres использует так много памяти", wantSpeech: "", wantCognition: true, allowNoMatch: true},
|
||||
{message: "ПОЧЕМУ postgres использует столько памяти", wantSpeech: "", wantCognition: true, allowNoMatch: true},
|
||||
{message: "разберись почему сервис упал", wantSpeech: "", wantCognition: true, allowNoMatch: true},
|
||||
{message: "разберись почему сервис упал", wantSpeech: "", wantCognition: true, allowNoMatch: true},
|
||||
{message: "посмотри что произошло", wantSpeech: "", wantCognition: true, allowNoMatch: true},
|
||||
{message: "исправь ошибку если найдёшь", wantSpeech: "", wantCognition: true, allowNoMatch: true},
|
||||
|
||||
Reference in New Issue
Block a user