-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructs.go
More file actions
177 lines (138 loc) · 3.72 KB
/
Copy pathstructs.go
File metadata and controls
177 lines (138 loc) · 3.72 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package thesaurus
import (
"bytes"
"fmt"
"strings"
"github.com/fatih/color"
)
type Results struct {
ID string `json:"id"`
Metadata Metadata `json:"metadata"`
Results []Result `json:"results"`
Word string `json:"word"`
}
type Metadata struct {
Operation string `json:"operation"`
Provider string `json:"provider"`
Schema string `json:"schema"`
}
type Result struct {
ID string `json:"id"`
Language string `json:"language"`
LexicalEntries []LexicalEntry `json:"lexicalEntries"`
Type string `json:"type"`
Word string `json:"word"`
}
type LexicalEntry struct {
Entries []Entry `json:"entries"`
Language string `json:"language"`
LexicalCategory LexicalCategory `json:"lexicalCategory"`
Text string `json:"text"`
}
func (entry *LexicalEntry) RenderLexicalCategory() string {
return strings.ToUpper(entry.LexicalCategory.Text)
}
type Entry struct {
Senses []Sense `json:"senses"`
}
type Sense struct {
Antonyms []Onym `json:"antonyms"`
Examples []Example `json:"examples"`
ID string `json:"id"`
Registers []LexicalCategory `json:"registers"`
Subsenses []Subsense `json:"subsenses"`
Synonyms []Onym `json:"synonyms"`
}
func (s Sense) RenderExamples() string {
var buf bytes.Buffer
for _, ex := range s.Examples {
fmt.Fprintf(&buf, "%s\n", ex.Render())
}
return buf.String()
}
func (s Sense) HasSynonyms() bool {
return len(s.Synonyms) > 0
}
func (s Sense) HasAntonyms() bool {
return len(s.Antonyms) > 0
}
func (s Sense) RenderTags() string {
tags := make([]string, 0)
for _, t := range s.Registers {
tags = append(tags, t.Text)
}
if len(tags) == 0 {
return ""
}
return color.GreenString(fmt.Sprintf("%s ", strings.Join(tags, ", ")))
}
func (s *Sense) RenderSynonyms() string {
synonyms := make([]string, len(s.Synonyms))
for i, syn := range s.Synonyms {
synonyms[i] = syn.Text
}
bold := color.New(color.Bold, color.FgBlue)
synonyms[0] = bold.Sprintf("%s", synonyms[0])
return strings.Join(synonyms, ", ")
}
func (s *Sense) RenderAntonyms() string {
antonyms := make([]string, len(s.Antonyms))
for i, syn := range s.Antonyms {
antonyms[i] = syn.Text
}
bold := color.New(color.Bold, color.FgBlue)
antonyms[0] = bold.Sprintf("%s", antonyms[0])
return strings.Join(antonyms, ", ")
}
type Onym struct {
ID *string `json:"id,omitempty"`
Language Language `json:"language"`
Text string `json:"text"`
}
type Example struct {
Text string `json:"text"`
}
func (ex Example) Render() string {
return ex.Text
}
type LexicalCategory struct {
ID string `json:"id"`
Text string `json:"text"`
}
type Subsense struct {
ID string `json:"id"`
Synonyms []Onym `json:"synonyms"`
Registers []LexicalCategory `json:"registers"`
Regions []LexicalCategory `json:"regions"`
}
func (s Subsense) HasSynonyms() bool {
return len(s.Synonyms) > 0
}
func (s Subsense) RenderTags() string {
tags := make([]string, 0)
for _, t := range s.Regions {
tags = append(tags, cleanTag(t.Text))
}
for _, t := range s.Registers {
tags = append(tags, cleanTag(t.Text))
}
if len(tags) == 0 {
return ""
}
return color.GreenString(fmt.Sprintf("%s ", strings.Join(tags, ", ")))
}
func cleanTag(s string) (output string) {
output = s
output = strings.Replace(output, "_", " ", -1)
return
}
func (s *Subsense) RenderSynonyms() string {
synonyms := make([]string, len(s.Synonyms))
for i, syn := range s.Synonyms {
synonyms[i] = syn.Text
}
bold := color.New(color.Bold, color.FgBlue)
synonyms[0] = bold.Sprintf("%s", synonyms[0])
return strings.Join(synonyms, ", ")
}
type Language string