@@ -12,7 +12,7 @@ import (
12
12
13
13
// Entity represents a wit-ai Entity.
14
14
//
15
- // https://wit.ai/docs/http/20200513/ #post__entities_link
15
+ // https://wit.ai/docs/http/#post__entities_link
16
16
type Entity struct {
17
17
ID string `json:"id"`
18
18
Name string `json:"name"`
@@ -21,17 +21,30 @@ type Entity struct {
21
21
Keywords []EntityKeyword `json:"keywords,omitempty"`
22
22
}
23
23
24
+ type CreateEntityResponse struct {
25
+ ID string `json:"id"`
26
+ Name string `json:"name"`
27
+ Lookups []string `json:"lookups,omitempty"`
28
+ Roles []EntityRole `json:"roles,omitempty"`
29
+ Keywords []EntityKeyword `json:"keywords,omitempty"`
30
+ }
31
+
32
+ type EntityRole struct {
33
+ ID string `json:"id"`
34
+ Name string `json:"name"`
35
+ }
36
+
24
37
// EntityKeyword is a keyword lookup for an Entity.
25
38
//
26
- // https://wit.ai/docs/http/20200513/ #post__entities__entity_keywords_link
39
+ // https://wit.ai/docs/http/#post__entities__entity_keywords_link
27
40
type EntityKeyword struct {
28
41
Keyword string `json:"keyword"`
29
42
Synonyms []string `json:"synonyms"`
30
43
}
31
44
32
45
// GetEntities - returns list of entities.
33
46
//
34
- // https://wit.ai/docs/http/20200513/ #get__entities_link
47
+ // https://wit.ai/docs/http/#get__entities_link
35
48
func (c * Client ) GetEntities () ([]Entity , error ) {
36
49
resp , err := c .request (http .MethodGet , "/entities" , "application/json" , nil )
37
50
if err != nil {
@@ -48,8 +61,8 @@ func (c *Client) GetEntities() ([]Entity, error) {
48
61
49
62
// CreateEntity - Creates a new entity with the given attributes
50
63
//
51
- // https://wit.ai/docs/http/20200513/ #post__entities_link
52
- func (c * Client ) CreateEntity (entity Entity ) (* Entity , error ) {
64
+ // https://wit.ai/docs/http/#post__entities_link
65
+ func (c * Client ) CreateEntity (entity Entity ) (* CreateEntityResponse , error ) {
53
66
entityJSON , err := json .Marshal (entity )
54
67
if err != nil {
55
68
return nil , err
@@ -62,54 +75,56 @@ func (c *Client) CreateEntity(entity Entity) (*Entity, error) {
62
75
63
76
defer resp .Close ()
64
77
65
- var entityResp * Entity
78
+ var entityResp * CreateEntityResponse
66
79
decoder := json .NewDecoder (resp )
67
80
err = decoder .Decode (& entityResp )
68
81
return entityResp , err
69
82
}
70
83
71
84
// GetEntity - returns entity by ID or name.
72
85
//
73
- // https://wit.ai/docs/http/20200513/ #get__entities__entity_link
74
- func (c * Client ) GetEntity (entityID string ) (* Entity , error ) {
86
+ // https://wit.ai/docs/http/#get__entities__entity_link
87
+ func (c * Client ) GetEntity (entityID string ) (* CreateEntityResponse , error ) {
75
88
resp , err := c .request (http .MethodGet , fmt .Sprintf ("/entities/%s" , url .PathEscape (entityID )), "application/json" , nil )
76
89
if err != nil {
77
90
return nil , err
78
91
}
79
92
80
93
defer resp .Close ()
81
94
82
- var entity * Entity
95
+ var entity * CreateEntityResponse
83
96
decoder := json .NewDecoder (resp )
84
97
err = decoder .Decode (& entity )
85
98
return entity , err
86
99
}
87
100
88
- // UpdateEntity - Updates an entity by ID or name.
101
+ // UpdateEntity - Updates an entity by name.
89
102
//
90
- // https://wit.ai/docs/http/20200513/ #put__entities__entity_link
91
- func (c * Client ) UpdateEntity (entityID string , entity Entity ) error {
103
+ // https://wit.ai/docs/http/#put__entities__entity_link
104
+ func (c * Client ) UpdateEntity (name string , entity Entity ) ( * CreateEntityResponse , error ) {
92
105
entityJSON , err := json .Marshal (entity )
93
106
if err != nil {
94
- return err
107
+ return nil , err
95
108
}
96
109
97
- resp , err := c .request (http .MethodPut , fmt .Sprintf ("/entities/%s" , url .PathEscape (entityID )), "application/json" , bytes .NewBuffer (entityJSON ))
110
+ resp , err := c .request (http .MethodPut , fmt .Sprintf ("/entities/%s" , url .PathEscape (name )), "application/json" , bytes .NewBuffer (entityJSON ))
98
111
if err != nil {
99
- return err
112
+ return nil , err
100
113
}
101
114
102
115
defer resp .Close ()
103
116
117
+ var entityResp * CreateEntityResponse
104
118
decoder := json .NewDecoder (resp )
105
- return decoder .Decode (& entity )
119
+ err = decoder .Decode (& entityResp )
120
+ return entityResp , err
106
121
}
107
122
108
- // DeleteEntity - deletes entity by ID or name.
123
+ // DeleteEntity - deletes entity by name
109
124
//
110
- // https://wit.ai/docs/http/20200513/ #delete__entities__entity_link
111
- func (c * Client ) DeleteEntity (entityID string ) error {
112
- resp , err := c .request (http .MethodDelete , fmt .Sprintf ("/entities/%s" , url .PathEscape (entityID )), "application/json" , nil )
125
+ // https://wit.ai/docs/http/#delete__entities__entity_link
126
+ func (c * Client ) DeleteEntity (name string ) error {
127
+ resp , err := c .request (http .MethodDelete , fmt .Sprintf ("/entities/%s" , url .PathEscape (name )), "application/json" , nil )
113
128
if err == nil {
114
129
resp .Close ()
115
130
}
@@ -119,9 +134,9 @@ func (c *Client) DeleteEntity(entityID string) error {
119
134
120
135
// DeleteEntityRole - deletes entity role.
121
136
//
122
- // https://wit.ai/docs/http/20200513/ #delete__entities__entity_role_link
123
- func (c * Client ) DeleteEntityRole (entityID string , role string ) error {
124
- resp , err := c .request (http .MethodDelete , fmt .Sprintf ("/entities/%s:%s" , url .PathEscape (entityID ), url .PathEscape (role )), "application/json" , nil )
137
+ // https://wit.ai/docs/http/#delete__entities__entity_role_link
138
+ func (c * Client ) DeleteEntityRole (name string , role string ) error {
139
+ resp , err := c .request (http .MethodDelete , fmt .Sprintf ("/entities/%s:%s" , url .PathEscape (name ), url .PathEscape (role )), "application/json" , nil )
125
140
if err == nil {
126
141
resp .Close ()
127
142
}
@@ -131,7 +146,7 @@ func (c *Client) DeleteEntityRole(entityID string, role string) error {
131
146
132
147
// AddEntityKeyword - Add a possible value into the list of values for the keyword entity.
133
148
//
134
- // https://wit.ai/docs/http/20200513/ #post__entities__entity_keywords_link
149
+ // https://wit.ai/docs/http/#post__entities__entity_keywords_link
135
150
func (c * Client ) AddEntityKeyword (entityID string , keyword EntityKeyword ) (* Entity , error ) {
136
151
valueJSON , err := json .Marshal (keyword )
137
152
if err != nil {
@@ -156,7 +171,7 @@ func (c *Client) AddEntityKeyword(entityID string, keyword EntityKeyword) (*Enti
156
171
157
172
// DeleteEntityKeyword - Delete a keyword from the keywords entity.
158
173
//
159
- // https://wit.ai/docs/http/20200513/ #delete__entities__entity_keywords__keyword_link
174
+ // https://wit.ai/docs/http/#delete__entities__entity_keywords__keyword_link
160
175
func (c * Client ) DeleteEntityKeyword (entityID string , keyword string ) error {
161
176
resp , err := c .request (http .MethodDelete , fmt .Sprintf ("/entities/%s/keywords/%s" , url .PathEscape (entityID ), url .PathEscape (keyword )), "application/json" , nil )
162
177
if err == nil {
@@ -168,7 +183,7 @@ func (c *Client) DeleteEntityKeyword(entityID string, keyword string) error {
168
183
169
184
// AddEntityKeywordSynonym - Create a new synonym of the canonical value of the keywords entity.
170
185
//
171
- // https://wit.ai/docs/http/20200513/ #post__entities__entity_keywords__keyword_synonyms_link
186
+ // https://wit.ai/docs/http/#post__entities__entity_keywords__keyword_synonyms_link
172
187
func (c * Client ) AddEntityKeywordSynonym (entityID string , keyword string , synonym string ) (* Entity , error ) {
173
188
type syn struct {
174
189
Synonym string `json:"synonym"`
@@ -199,7 +214,7 @@ func (c *Client) AddEntityKeywordSynonym(entityID string, keyword string, synony
199
214
200
215
// DeleteEntityKeywordSynonym - Delete a synonym of the keyword of the entity.
201
216
//
202
- // https://wit.ai/docs/http/20200513/ #delete__entities__entity_keywords__keyword_synonyms__synonym_link
217
+ // https://wit.ai/docs/http/#delete__entities__entity_keywords__keyword_synonyms__synonym_link
203
218
func (c * Client ) DeleteEntityKeywordSynonym (entityID string , keyword string , expression string ) error {
204
219
resp , err := c .request (http .MethodDelete , fmt .Sprintf ("/entities/%s/keywords/%s/synonyms/%s" , url .PathEscape (entityID ), url .PathEscape (keyword ), url .PathEscape (expression )), "application/json" , nil )
205
220
if err == nil {
0 commit comments