oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package chat
2
3import (
4 "slices"
5 "strings"
6 "unicode"
7)
8
9// followUpMarkers open a follow-up question, compared in lower case after
10// any leading punctuation (so "¿y" is "y").
11var followUpMarkers = [][]string{{"and", "for"}, {"what", "about"}, {"how", "about"}, {"same", "for"}, {"y", "para"}, {"qué", "tal"}, {"que", "tal"}, {"and"}, {"y"}}
12
13// maxFollowUpWords is the most words a follow-up has.
14const maxFollowUpWords = 6
15
16// isFollowUp is the instance's conservative rule for a lookup question
17// that follows on from an earlier one (plan Task 3.6): at most 6 words,
18// starting with a fixed follow-up marker. Shortness alone never makes a
19// follow-up; when in doubt it is not one.
20func isFollowUp(message string) bool {
21 words := strings.FieldsFunc(strings.ToLower(message), func(r rune) bool {
22 return unicode.IsSpace(r) || unicode.IsPunct(r) && r != '\'' || unicode.IsSymbol(r)
23 })
24 if len(words) == 0 || len(words) > maxFollowUpWords {
25 return false
26 }
27 for _, m := range followUpMarkers {
28 if len(words) >= len(m) && slices.Equal(words[:len(m)], m) {
29 return true
30 }
31 }
32 return false
33}
34