Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ccf790d130 | ||
|
|
54c2cc27a3 |
@@ -50,6 +50,12 @@ func InterpretHumanResponse(request contract.HumanResponseRequest, owner identit
|
|||||||
response.Clarification = "Я не вижу активного ожидания, к которому это относится."
|
response.Clarification = "Я не вижу активного ожидания, к которому это относится."
|
||||||
return contract.HumanResponseResult{Response: response, Handled: true, Reply: response.Clarification}, nil
|
return contract.HumanResponseResult{Response: response, Handled: true, Reply: response.Clarification}, nil
|
||||||
}
|
}
|
||||||
|
if len(candidates) > 1 {
|
||||||
|
matched := matchingCandidates(message, candidates)
|
||||||
|
if len(matched) == 1 {
|
||||||
|
candidates = matched
|
||||||
|
}
|
||||||
|
}
|
||||||
if len(candidates) > 1 {
|
if len(candidates) > 1 {
|
||||||
response.ResolutionState = contract.ResponseAmbiguous
|
response.ResolutionState = contract.ResponseAmbiguous
|
||||||
response.Outcome = contract.ResponseOutcomeClarificationNeeded
|
response.Outcome = contract.ResponseOutcomeClarificationNeeded
|
||||||
@@ -153,6 +159,30 @@ func candidateSummary(candidates []ResponseCandidate) string {
|
|||||||
return strings.Join(parts, "; ")
|
return strings.Join(parts, "; ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func matchingCandidates(message string, candidates []ResponseCandidate) []ResponseCandidate {
|
||||||
|
lower := strings.ToLower(message)
|
||||||
|
var matched []ResponseCandidate
|
||||||
|
for _, candidate := range candidates {
|
||||||
|
if summaryMatches(lower, candidate.Attention.Summary) {
|
||||||
|
matched = append(matched, candidate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matched
|
||||||
|
}
|
||||||
|
|
||||||
|
func summaryMatches(lowerMessage string, summary string) bool {
|
||||||
|
for _, token := range strings.Fields(strings.ToLower(summary)) {
|
||||||
|
token = strings.Trim(token, ".,!?:;()[]«»\"'")
|
||||||
|
if len([]rune(token)) < 4 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.Contains(lowerMessage, token) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func humanResponseTime(value time.Time) string {
|
func humanResponseTime(value time.Time) string {
|
||||||
if value.IsZero() {
|
if value.IsZero() {
|
||||||
return "позже"
|
return "позже"
|
||||||
|
|||||||
@@ -41,6 +41,13 @@ func TestInterpretHumanResponseAmbiguousTargetAsksClarificationWithoutResolvedMu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInterpretHumanResponseResolvesAmbiguousTargetByNaturalSummaryReference(t *testing.T) {
|
||||||
|
result := interpretResponseForTest(t, "Готово, проверить базу сделано", []ResponseCandidate{responseCandidate("a1", "p1", "позвонить врачу"), responseCandidate("a2", "p2", "проверить базу")})
|
||||||
|
if !result.Handled || result.Response.ResolutionState != continuity.ResponseResolved || result.Response.TargetAttentionID != "a2" {
|
||||||
|
t.Fatalf("expected natural summary target resolution, got %#v", result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestInterpretHumanResponseNoTargetAsksClarification(t *testing.T) {
|
func TestInterpretHumanResponseNoTargetAsksClarification(t *testing.T) {
|
||||||
result := interpretResponseForTest(t, "Готово", nil)
|
result := interpretResponseForTest(t, "Готово", nil)
|
||||||
if !result.Handled || result.Response.ResolutionState != continuity.ResponseNoTarget || result.Response.Outcome != continuity.ResponseOutcomeClarificationNeeded {
|
if !result.Handled || result.Response.ResolutionState != continuity.ResponseNoTarget || result.Response.Outcome != continuity.ResponseOutcomeClarificationNeeded {
|
||||||
|
|||||||
Reference in New Issue
Block a user