-
Notifications
You must be signed in to change notification settings - Fork 7
/
parse.go
48 lines (43 loc) · 871 Bytes
/
parse.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
48
package infermedica
import (
"encoding/json"
"net/http"
"time"
)
type ParseReq struct {
Text string `json:"text"`
}
type ParseRes struct {
Mentions []Mention `json:"mentions"`
}
type Mention struct {
Orth string `json:"orth"`
Name string `json:"name"`
ID string `json:"id"`
ChoiceID string `json:"choice_id"`
Type string `json:"type"`
CommonName string `json:"common_name"`
}
func (a *App) Parse(pr ParseReq) (*ParseRes, error) {
model := a.model
a.model = ""
req, err := a.preparePOSTRequest("parse", pr)
if err != nil {
return nil, err
}
a.model = model
client := &http.Client{
Timeout: time.Second * 5,
}
res, err := client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
r := ParseRes{}
err = json.NewDecoder(res.Body).Decode(&r)
if err != nil {
return nil, err
}
return &r, nil
}