Skip to content

Commit 85f0001

Browse files
committed
added new context variables matcher
1 parent 87c9d0d commit 85f0001

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

matcher.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ type Match struct {
55
Confidence float64
66
}
77

8+
type CMatch struct {
9+
Name string
10+
Value interface{}
11+
}
12+
813
type Matcher struct {
9-
Entity Match
10-
Intent Match
11-
AND *Matcher
12-
OR *Matcher
14+
Entity Match
15+
Intent Match
16+
ContextVariable CMatch
17+
AND *Matcher
18+
OR *Matcher
1319
}
1420

1521
func (out *Output) Match(matcher *Matcher) bool {
@@ -26,6 +32,16 @@ func (out *Output) Match(matcher *Matcher) bool {
2632
}
2733
}
2834

35+
if out.Context.Variables != nil {
36+
for varName, varValue := range out.Context.Variables {
37+
if matcher.ContextVariable.Name == varName {
38+
if matcher.ContextVariable.Value == varValue {
39+
ok = true
40+
}
41+
}
42+
}
43+
}
44+
2945
if matcher.AND != nil {
3046
if out.Match(matcher.AND) && ok {
3147
ok = true

output_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package neocortex
22

3-
func (out *Output) AddContextVariable(name string, value interface{}) *Output {
3+
func (out *Output) SetContextVariable(name string, value interface{}) *Output {
44
if out.Context.Variables == nil {
55
out.Context.Variables = map[string]interface{}{}
66
}

0 commit comments

Comments
 (0)