-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparser.go
174 lines (110 loc) · 2.27 KB
/
parser.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
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
package sportsearch
import (
"log"
"strings"
)
type Who struct {
Target string `json:"target"`
TargetType int `json:"targetType"`
}
type What struct {
Statistics map[string]bool `json:"statistics"`
}
type When struct {
Period int `json:"period"`
BeginRange string `json:"beginRange"`
EndRange string `json:"endRange"`
LastN int `json:"lastN"`
LastNType int `json:"lastNType"`
}
type Intent struct {
Players []int
Teams []int
LastN int
Begin string
End string
Fields []string
}
type Classification struct {
IsPlayer bool
IsTeam bool
IsKeyword bool
IsParam bool
Players []int
Teams []int
Fields []string
Math []string
}
type PageSummary struct {
}
func CheckPlayer(f string, c *Classification, isLast bool) {
var idx map[string][]PlayerNameNode
if c.Players == nil {
c.Players = []int{}
}
if isLast {
idx = idxPlayerLast
} else {
idx = idxPlayerFirst
}
fl := strings.ToLower(f)
_, ok := idx[fl]
if ok {
c.IsPlayer = true
nodes := findByName(fl, isLast)
for _, n := range nodes {
c.Players = append(c.Players, n.ID)
}
}
} // CheckPlayer
func CheckTeam(f string) int {
lf := strings.ToLower(f)
t, ok := idxTeamFull[lf]
if ok {
return t
}
t, ok = idxTeamName[lf]
if ok {
return t
}
t, ok = idxTeamCity[lf]
if ok {
return t
}
t, ok = idxTeamAbv[lf]
if ok {
return t
}
return NOT_FOUND
} // CheckTeam
func CheckKeyword(f string) int {
strings.ToLower(f)
return NOT_FOUND
} // CheckKeyword
func Classifier(q string) []Classification {
if len(q) == 0 || q == EMPTY_STRING {
return nil
}
fields := strings.Fields(q)
var ret []Classification
for _, f := range fields {
c := Classification{}
lf := strings.ToLower(f)
CheckPlayer(lf, &c, true)
CheckPlayer(lf, &c, false)
teamId := CheckTeam(lf)
if teamId != NOT_FOUND {
c.IsTeam = true
}
ret = append(ret, c)
key := CheckKeyword(lf)
if key != NOT_FOUND {
c.IsKeyword = true
}
}
log.Printf("%v\n", ret)
return ret
} // Classifier
func search() []PageSummary {
return nil
} // search