-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword_forms.go
59 lines (49 loc) · 1.31 KB
/
word_forms.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
49
50
51
52
53
54
55
56
57
58
59
package lingvo
import (
"context"
)
const (
endpointWordForms = "api/v1/WordForms"
)
// Lexeme contains a single word with all its word forms.
type Lexeme struct {
Lexeme string `json:"Lexem"`
PartOfSpeech string `json:"PartOfSpeech"`
Paradigm Paradigm `json:"ParadigmJson"`
}
// Paradigm contains word forms
type Paradigm struct {
Name string `json:"Name"`
Grammar string `json:"Grammar"`
Groups []Group `json:"Groups"`
}
// Group contains a group of word forms
type Group struct {
Name string `json:"Name"`
Table [][]TableCell `json:"Table"`
ColumnCount int `json:"ColumnCount"`
RowCount int `json:"RowCount"`
}
// TableCell contains a single word form
type TableCell struct {
Value string `json:"Value"`
Prefix string `json:"Prefix"`
Row string `json:"Row"`
}
// GetWordForms returns all word forms for word in language lang.
func (c *Client) GetWordForms(ctx context.Context, word string, lang Lang) ([]*Lexeme, error) {
u, err := addOptions(endpointWordForms, option{"text", word}, option{"lang", lang.code()})
if err != nil {
return nil, err
}
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
lexemes := new([]*Lexeme)
err = c.Do(ctx, req, lexemes)
if err != nil {
return nil, err
}
return *lexemes, nil
}