| 977 | } |
| 978 | |
| 979 | func normalizeTurnStatusLabel(text string) (string, bool) { |
| 980 | text = strings.TrimSpace(text) |
| 981 | if text == "" { |
| 982 | return "", false |
| 983 | } |
| 984 | |
| 985 | text = strings.Trim(text, "\"'`") |
| 986 | text = strings.TrimSpace(text) |
| 987 | if text == "" || strings.ContainsAny(text, "\r\n") { |
| 988 | return "", false |
| 989 | } |
| 990 | text = strings.TrimRight(text, ".!?") |
| 991 | text = strings.Join(strings.Fields(text), " ") |
| 992 | if text == "" || hasSentenceBoundary(text) { |
| 993 | return "", false |
| 994 | } |
| 995 | |
| 996 | words := strings.Fields(text) |
| 997 | if len(words) < 2 || len(words) > 5 { |
| 998 | return "", false |
| 999 | } |
| 1000 | |
| 1001 | lower := strings.ToLower(text) |
| 1002 | if hasDisallowedTurnStatusLabelSubject(lower) { |
| 1003 | return "", false |
| 1004 | } |
| 1005 | |
| 1006 | disallowedPhrases := []string{ |
| 1007 | "agent asked", |
| 1008 | "agent identified", |
| 1009 | "agent found", |
| 1010 | "agent explained", |
| 1011 | } |
| 1012 | for _, phrase := range disallowedPhrases { |
| 1013 | if strings.Contains(lower, phrase) { |
| 1014 | return "", false |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | return text, true |
| 1019 | } |
| 1020 | |
| 1021 | func hasDisallowedTurnStatusLabelSubject(text string) bool { |
| 1022 | subject := leadingLetters(text) |