/
response_types.go
149 lines (130 loc) · 3.33 KB
/
response_types.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
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
package vision
import SDK "google.golang.org/api/vision/v1"
// Entity contains general result of response.
type Entity struct {
Description string
Score float64
// for Web
EntityID string
}
// SafeEntity contains result of SafeSearch.
type SafeEntity struct {
Adult Likelihood
Spoof Likelihood
Medical Likelihood
Violence Likelihood
}
// NewSafeEntity creates SafeEntity from result of SafeSearchAnnotation.
func NewSafeEntity(anno *SDK.SafeSearchAnnotation) SafeEntity {
return SafeEntity{
Adult: NewLikelihood(anno.Adult),
Spoof: NewLikelihood(anno.Spoof),
Medical: NewLikelihood(anno.Medical),
Violence: NewLikelihood(anno.Violence),
}
}
// Likelihood list of string result.
const (
LikelihoodTextUnknown = "UNKNOWN"
LikelihoodTextVeryUnlikely = "VERY_UNLIKELY"
LikelihoodTextUnlikely = "UNLIKELY"
LikelihoodTextPossible = "POSSIBLE"
LikelihoodTextLikely = "LIKELY"
LikelihoodTextVeryLikely = "VERY_LIKELY"
)
// Likelihood is likelihood of detection result.
type Likelihood int
// Likelihood list.
const (
LikelihoodError Likelihood = iota
LikelihoodUnknown
LikelihoodVeryUnlikely
LikelihoodUnlikely
LikelihoodPossible
LikelihoodLikely
LikelihoodVeryLikely
)
// NewLikelihood creates Likelihood.
func NewLikelihood(s string) Likelihood {
switch s {
case LikelihoodTextUnknown:
return LikelihoodUnknown
case LikelihoodTextVeryUnlikely:
return LikelihoodVeryUnlikely
case LikelihoodTextUnlikely:
return LikelihoodUnlikely
case LikelihoodTextPossible:
return LikelihoodPossible
case LikelihoodTextLikely:
return LikelihoodLikely
case LikelihoodTextVeryLikely:
return LikelihoodVeryLikely
default:
return LikelihoodError
}
}
func (l Likelihood) String() string {
switch l {
case LikelihoodUnknown:
return LikelihoodTextUnknown
case LikelihoodVeryUnlikely:
return LikelihoodTextVeryUnlikely
case LikelihoodUnlikely:
return LikelihoodTextUnlikely
case LikelihoodPossible:
return LikelihoodTextPossible
case LikelihoodLikely:
return LikelihoodTextLikely
case LikelihoodVeryLikely:
return LikelihoodTextVeryLikely
default:
return ""
}
}
// IsError checks if Likelifood is error.
func (l Likelihood) IsError() bool {
return l == LikelihoodError
}
// Unknown checks if Likelifood is more than Unknown.
func (l Likelihood) Unknown() bool {
return l >= LikelihoodUnknown
}
// VeryUnlikely checks if Likelifood is more than VeryUnlikely.
func (l Likelihood) VeryUnlikely() bool {
return l >= LikelihoodVeryUnlikely
}
// Unlikely checks if Likelifood is more than Unlikely.
func (l Likelihood) Unlikely() bool {
return l >= LikelihoodUnlikely
}
// Possible checks if Likelifood is more than Possible.
func (l Likelihood) Possible() bool {
return l >= LikelihoodPossible
}
// Likely checks if Likelifood is more than Likely.
func (l Likelihood) Likely() bool {
return l >= LikelihoodLikely
}
// VeryLikely checks if Likelifood is more than VeryLikely.
func (l Likelihood) VeryLikely() bool {
return l >= LikelihoodVeryLikely
}
// Vertex has a 2D point in the image.
type Vertex struct {
X int64
Y int64
}
// NewVertices creates []Vertex from *SDK.BoundingPoly.
func NewVertices(p *SDK.BoundingPoly) []Vertex {
if p == nil {
return nil
}
list := make([]Vertex, len(p.Vertices))
for i, v := range p.Vertices {
list[i] = Vertex{
X: v.X,
Y: v.Y,
}
}
return list
}