-
Notifications
You must be signed in to change notification settings - Fork 20
/
classifier.go
42 lines (34 loc) · 1.22 KB
/
classifier.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package flows
import "github.com/nyaruka/goflow/assets"
// Classifier represents an NLU classifier.
type Classifier struct {
assets.Classifier
}
// NewClassifier returns a new classifier object from the given classifier asset
func NewClassifier(asset assets.Classifier) *Classifier {
return &Classifier{Classifier: asset}
}
// Asset returns the underlying asset
func (c *Classifier) Asset() assets.Classifier { return c.Classifier }
// Reference returns a reference to this classifier
func (c *Classifier) Reference() *assets.ClassifierReference {
return assets.NewClassifierReference(c.UUID(), c.Name())
}
// ClassifierAssets provides access to all classifier assets
type ClassifierAssets struct {
byUUID map[assets.ClassifierUUID]*Classifier
}
// NewClassifierAssets creates a new set of classifier assets
func NewClassifierAssets(classifiers []assets.Classifier) *ClassifierAssets {
s := &ClassifierAssets{
byUUID: make(map[assets.ClassifierUUID]*Classifier, len(classifiers)),
}
for _, asset := range classifiers {
s.byUUID[asset.UUID()] = NewClassifier(asset)
}
return s
}
// Get returns the classifier with the given UUID
func (s *ClassifierAssets) Get(uuid assets.ClassifierUUID) *Classifier {
return s.byUUID[uuid]
}