This commit is contained in:
@@ -92,23 +92,33 @@ func InterpretUtterance(utterance interaction.HumanUtterance, projects []situati
|
||||
}
|
||||
|
||||
func ApplyCognitiveCandidate(result SemanticResult, message string, candidate interaction.SemanticCandidate, previousFocus *situation.ActiveProjectFocus) SemanticResult {
|
||||
candidate.SelectionState = interaction.CandidateSelected
|
||||
if candidate.UtteranceID == "" {
|
||||
candidate.UtteranceID = result.Interpretation.UtteranceID
|
||||
}
|
||||
selected := false
|
||||
candidate.SelectionState = interaction.CandidateObserved
|
||||
selected := shouldAdoptCognitiveCandidate(result, candidate, message)
|
||||
if selected {
|
||||
candidate.SelectionState = interaction.CandidateSelected
|
||||
}
|
||||
|
||||
matched := false
|
||||
for index := range result.Candidates {
|
||||
if result.Candidates[index].SelectionState == interaction.CandidateSelected {
|
||||
result.Candidates[index].SelectionState = interaction.CandidateObserved
|
||||
}
|
||||
if result.Candidates[index].ID == candidate.ID {
|
||||
result.Candidates[index] = candidate
|
||||
selected = true
|
||||
matched = true
|
||||
}
|
||||
}
|
||||
if !selected {
|
||||
if !matched {
|
||||
result.Candidates = append(result.Candidates, candidate)
|
||||
}
|
||||
if !selected {
|
||||
result.Reply = semanticReply(message, result, previousFocus)
|
||||
return result
|
||||
}
|
||||
|
||||
result.Interpretation.SpeechAct = candidate.PrimarySpeechAct
|
||||
result.Interpretation.SecondarySpeechAct = candidate.SecondarySpeechAct
|
||||
result.Interpretation.ConfidenceMillis = candidate.ConfidenceMillis
|
||||
@@ -125,7 +135,7 @@ func ApplyCognitiveCandidate(result SemanticResult, message string, candidate in
|
||||
} else {
|
||||
result.Interpretation.AssertionVerification = string(epistemics.VerificationNotApplicable)
|
||||
}
|
||||
if candidate.Applicability == interaction.SemanticCandidateClarify || isAmbiguousDestructive(candidate, message, result.Projects) {
|
||||
if result.Interpretation.Applicability == interaction.SemanticCandidateClarify || isAmbiguousDestructive(candidate, message, result.Projects) {
|
||||
result.Interpretation.Clarification = interaction.ClarificationRequired
|
||||
result.NeedsCognition = false
|
||||
result.Interpretation.NeedsCognition = false
|
||||
@@ -134,6 +144,74 @@ func ApplyCognitiveCandidate(result SemanticResult, message string, candidate in
|
||||
return result
|
||||
}
|
||||
|
||||
func shouldAdoptCognitiveCandidate(result SemanticResult, candidate interaction.SemanticCandidate, message string) bool {
|
||||
if result.Interpretation.Clarification == interaction.ClarificationRequired {
|
||||
return false
|
||||
}
|
||||
if candidate.Source != interaction.CandidateSourceCognitive {
|
||||
return false
|
||||
}
|
||||
if candidate.Applicability == interaction.SemanticCandidateClarify {
|
||||
return false
|
||||
}
|
||||
if candidate.PrimarySpeechAct == interaction.SpeechActUnknown {
|
||||
return false
|
||||
}
|
||||
if isConsequenceRisk(message) && result.Interpretation.SpeechAct == interaction.SpeechActDirective {
|
||||
if candidate.PrimarySpeechAct != interaction.SpeechActDirective {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if candidate.PrimarySpeechAct != result.Interpretation.SpeechAct {
|
||||
if result.Interpretation.SpeechAct == interaction.SpeechActQuestion || result.Interpretation.SpeechAct == interaction.SpeechActRequestToInvestigate || result.Interpretation.SpeechAct == interaction.SpeechActConversational {
|
||||
return true
|
||||
}
|
||||
if result.Interpretation.Applicability == interaction.SemanticNeedsBroaderInterpret || result.Interpretation.Applicability == interaction.SemanticLowConfidence || result.Interpretation.Applicability == interaction.SemanticMixedIntent {
|
||||
return true
|
||||
}
|
||||
return candidate.NeedsCognition
|
||||
}
|
||||
if candidate.NeedsCognition {
|
||||
return true
|
||||
}
|
||||
if result.Interpretation.SpeechAct == interaction.SpeechActQuestion || result.Interpretation.SpeechAct == interaction.SpeechActRequestToInvestigate || result.Interpretation.SpeechAct == interaction.SpeechActConversational {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isConsequenceRisk(message string) bool {
|
||||
lower := strings.ToLower(strings.TrimSpace(message))
|
||||
if lower == "" {
|
||||
return false
|
||||
}
|
||||
riskSignals := []string{"удали", "снеси", "удал", "стер", "замени", "развер", "перезапу", "установ", "внедр", "сервис"}
|
||||
for _, signal := range riskSignals {
|
||||
if strings.Contains(lower, signal) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ShouldAttemptCognitive(result SemanticResult) bool {
|
||||
if result.Interpretation.Clarification == interaction.ClarificationRequired {
|
||||
return false
|
||||
}
|
||||
if result.NeedsCognition {
|
||||
return true
|
||||
}
|
||||
if result.Interpretation.SpeechAct == interaction.SpeechActQuestion || result.Interpretation.SpeechAct == interaction.SpeechActRequestToInvestigate || result.Interpretation.SpeechAct == interaction.SpeechActConversational {
|
||||
return true
|
||||
}
|
||||
if result.Interpretation.Applicability == interaction.SemanticNeedsBroaderInterpret || result.Interpretation.Applicability == interaction.SemanticLowConfidence || result.Interpretation.Applicability == interaction.SemanticMixedIntent {
|
||||
return true
|
||||
}
|
||||
if result.Interpretation.SpeechAct == interaction.SpeechActDirective {
|
||||
return !isConsequenceRisk(result.Interpretation.RequestedOutcome)
|
||||
}
|
||||
return false
|
||||
}
|
||||
func explicitProjectFocus(message string, projects []situation.ProjectDescriptor) *interaction.ProjectReference {
|
||||
lower := strings.ToLower(message)
|
||||
if !(strings.Contains(lower, "работаем с") || strings.Contains(lower, "вернемся к") || strings.Contains(lower, "вернёмся к") || strings.HasPrefix(strings.TrimSpace(lower), "теперь ")) {
|
||||
|
||||
Reference in New Issue
Block a user