// SetKeywords processes and registers keywords with Abot's core for routing. func SetKeywords(p *dt.Plugin, khs ...dt.KeywordHandler) { p.Keywords = &dt.Keywords{ Dict: map[string]dt.KeywordFn{}, } for _, kh := range khs { for _, intent := range kh.Trigger.Intents { intent = strings.ToLower(intent) if !language.Contains(p.Trigger.Intents, intent) { p.Trigger.Intents = append(p.Trigger.Intents, intent) } key := "I_" + intent _, exists := p.Keywords.Dict[key] if exists { continue } p.Keywords.Dict[key] = kh.Fn } eng := porter2.Stemmer for _, cmd := range kh.Trigger.Commands { cmd = strings.ToLower(eng.Stem(cmd)) if !language.Contains(p.Trigger.Commands, cmd) { p.Trigger.Commands = append(p.Trigger.Commands, cmd) } for _, obj := range kh.Trigger.Objects { obj = strings.ToLower(eng.Stem(obj)) if !language.Contains(p.Trigger.Objects, obj) { p.Trigger.Objects = append(p.Trigger.Objects, obj) } key := "CO_" + cmd + "_" + obj p.Keywords.Dict[key] = kh.Fn } } } }
// AppendTrigger appends the StructuredInput's modified contents to a plugin. // All Commands and Objects stemmed using the Porter2 Snowball algorithm. func AppendTrigger(p *dt.Plugin, t *dt.StructuredInput) { eng := porter2.Stemmer for _, cmd := range t.Commands { cmd = eng.Stem(cmd) if !language.Contains(p.Trigger.Commands, cmd) { p.Trigger.Commands = append(p.Trigger.Commands, cmd) } } for _, obj := range t.Objects { obj = eng.Stem(obj) if !language.Contains(p.Trigger.Objects, obj) { p.Trigger.Objects = append(p.Trigger.Objects, obj) } } }