-
Notifications
You must be signed in to change notification settings - Fork 0
/
intenthandle.go
47 lines (44 loc) · 1.14 KB
/
intenthandle.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
43
44
45
46
47
package main
import (
"encoding/base64"
"encoding/json"
"fmt"
"log"
)
type UserIntent struct {
Text string `json:"text"`
Intent Intent `json:"intent"`
Entities []Entities `json:"entities"`
IntentRanking []IntentRanking `json:"intent_ranking"`
}
type Intent struct {
Name string `json:"name"`
Confidence float64 `json:"confidence"`
}
type Entities struct {
Start int `json:"start"`
End int `json:"end"`
Text string `json:"text"`
Value int `json:"value"`
Confidence int `json:"confidence"`
Entity string `json:"entity"`
}
type IntentRanking struct {
Name string `json:"name"`
Confidence float64 `json:"confidence"`
}
func ProcessUserIntent(uIntent string) UserIntent {
// userIntent is base64 encoded data.
data, err := base64.StdEncoding.DecodeString(uIntent)
if err != nil {
log.Fatal("error:", err)
}
fmt.Println(string(data))
// decode it to json
var userIntent UserIntent
json.Unmarshal(data, &userIntent)
// parse json and get the intent
fmt.Println(userIntent.Text, userIntent.Intent.Name)
// process intent.
return userIntent
}