-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs_dbapi.go
187 lines (160 loc) · 5.72 KB
/
structs_dbapi.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
175
176
177
178
179
180
181
182
183
184
185
186
187
package dbapi
import (
"strings"
"github.com/stts-se/pronlex/lex"
)
// DBMQuery is a query used by the DBManager, containing lexicon referenes (db+lex name) and a dbapi.Query
type DBMQuery struct {
LexRefs []lex.LexRef
Query Query
}
// type LexiconQuery struct {
// Lexicons []string
// Query Query
// }
// TODO Lägga till bolska fält för 'not'?
// Kunna sätta sortering eller ej?
// Query represents an sql search query to the lexicon database
// TODO Change to list(s) of search critieria.
// TODO add boolean for include/exclude (i.e., "NOT" in the generated SQL).
type Query struct {
// list of words to get corresponding entries for
Words []string `json:"words"`
// a 'like' db search expression matching words
WordLike string `json:"wordLike"`
WordRegexp string `json:"wordRegexp"`
WordParts []string `json:"wordParts"`
WordPartsLike string `json:"wordPartsLike"`
WordPartsRegexp string `json:"wordPartsRegexp"`
// a slice of Entry.IDs to search for
EntryIDs []int64 `json:"entryIds"`
// a 'like' db search expression matching transcriptions
TranscriptionLike string `json:"transcriptionLike"`
TranscriptionRegexp string `json:"transcriptionRegexp"`
// a 'like' db search expression matching part of speech strings
PartOfSpeechLike string `json:"partOfSpeechLike"`
PartOfSpeechRegexp string `json:"partOfSpeechRegexp"`
// list of lemma forms to get corresponding entries for
Lemmas []string `json:"lemmas"`
// an SQL 'like' expression to match lemma forms
LemmaLike string `json:"lemmaLike"`
LemmaRegexp string `json:"lemmaRegexp"`
// an SQL 'like' expression to match lemma readings
ReadingLike string `json:"readingLike"`
ReadingRegexp string `json:"readingRegexp"`
// an SQL 'like' expression to match lemma paradigms
ParadigmLike string `json:"paradigmLike"`
ParadigmRegexp string `json:"paradigmRegexp"`
// A list of entry statuses to match
EntryStatus []string `json:"entryStatus"`
// Select entries with one or more EntryValidations
HasEntryValidation bool `json:"hasEntryValidation"`
// // Search for Entries with EntryValidations with the listed
// // validation rule names (such as 'Decomp2Orth', etc)
// EntryValidations []string `json:"entryValidations"`
// the page returned by the SQL query's 'LIMIT' (starts at 1)
Page int64 `json:"page"`
// the page length of the SQL query's 'LIMIT'
PageLength int64 `json:"pageLength"`
}
// Empty returns true if there are not search criteria values
// This is no longer a sane way to do it, since the number of search criteria has grown.
func (q Query) Empty() bool {
switch {
case len(q.Words) > 0:
return false
case strings.TrimSpace(q.WordLike) != "":
return false
case strings.TrimSpace(q.WordRegexp) != "":
return false
case len(q.WordParts) > 0:
return false
case strings.TrimSpace(q.WordPartsLike) != "":
return false
case strings.TrimSpace(q.WordPartsRegexp) != "":
return false
case len(q.EntryIDs) > 0:
return false
case strings.TrimSpace(q.TranscriptionLike) != "":
return false
case strings.TrimSpace(q.TranscriptionRegexp) != "":
return false
case strings.TrimSpace(q.PartOfSpeechLike) != "":
return false
case strings.TrimSpace(q.PartOfSpeechRegexp) != "":
return false
case len(q.Lemmas) > 0:
return false
case strings.TrimSpace(q.LemmaLike) != "":
return false
case strings.TrimSpace(q.LemmaRegexp) != "":
return false
case strings.TrimSpace(q.ReadingLike) != "":
return false
case strings.TrimSpace(q.ReadingRegexp) != "":
return false
case strings.TrimSpace(q.ParadigmLike) != "":
return false
case strings.TrimSpace(q.ParadigmRegexp) != "":
return false
}
//log.Printf("dbapi.EmptyQuery: query struct appears to lack any search constraint: %v", q)
return true
}
// NewQuery returns a Query instance where PageLength: 25
func NewQuery() Query {
return Query{PageLength: 25}
}
// LexiconIDs returns a list of db IDs of the Lexicons of the Query
// func (q Query) LexiconIDs() []int64 {
// var ids []int64
// for _, l := range q.Lexicons {
// ids = append(ids, l.ID)
// }
// return ids
// }
// Lexicon corresponds to the lexicon db table, to which Entries are
// associated
type lexicon struct {
id int64 // `json:"id"`
name string // `json:"name"`
symbolSetName string // `json:"symbolSetName"`
}
// Symbol corresponds to the symbol db table, and holds a phonetic
// symbol
type Symbol struct {
LexiconID int64 `json:"lexiconId"`
Symbol string `json:"symbol"`
Category string `json:"category"`
Description string `json:"description"`
IPA string `json:"ipa"`
}
// LexStats holds the result of a call to the dbapi.LexiconStats function.
type LexStats struct {
Lexicon string `json:"lexicon"`
// The number of entries in the lexicon corresponding to database id LexiconID
Entries int64 `json:"entries"`
// Status frequencies, as strings: StatusName<TAB>Frequency
// TODO better structure for status/freq (string/int)
StatusFrequencies []string `json:"statusFrequencies"`
ValStats ValStats
}
// QueryStats holds the result of a call to the dbapi.LexiconStats function.
// TODO add fields for additional stats
type QueryStats struct {
Query Query `json:"query"`
Entries int64 `json:"entries"`
}
// ValStats is used to incrementally give statistics during a validation process, or to just represent a final validation statistics.
type ValStats struct {
// TotalEntries is the total entries to be validated
TotalEntries int
// ValidatedEntries is the total validated entries so far
ValidatedEntries int
// TotalValidations is the total number of validation messages so far
TotalValidations int
// InvalidEntries is the number of invalid entries so far
InvalidEntries int
Levels map[string]int `json:"levels"`
Rules map[string]int `json:"rules"`
}