diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-28 12:59:42 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-28 12:59:42 -0500 |
commit | a7645346293ed6a912c26d0c50b6f7943f1f3072 (patch) | |
tree | d4d144e03a5e2dfcebbad2692fa71e790719d8fd /lib/field.h | |
parent | 6ba8989bbbd497f949a3e8b17abed1d0bd048347 (diff) | |
download | verbly-a7645346293ed6a912c26d0c50b6f7943f1f3072.tar.gz verbly-a7645346293ed6a912c26d0c50b6f7943f1f3072.tar.bz2 verbly-a7645346293ed6a912c26d0c50b6f7943f1f3072.zip |
Restructured verb frame schema to be more queryable
Groups are much less significant now, and they no longer have a database table, nor are they considered a top level object anymore. Instead of containing their own role data, that data is folded into the frames so that it's easier to query; as a result, each group has its own copy of the frames that it contains. Additionally, parts are considered top level objects now, and you can query for frames based on attributes of their indexed parts. Synrestrs are also contained in their own table now, so that parts can be filtered against their synrestrs; they are however not considered top level objects. Created a new type of field, the "join where" or "condition join" field, which is a normal join field that has a built in condition on a specified field. This is used to allow creating multiple distinct join fields from one object to another. This is required for the lemma::form and frame::part joins, because filters for forms of separate inflections should not be coalesced; similarly, filters on differently indexed frame parts should not be coalesced. Queries can now be ordered, ascending or descending, by a field, in addition to randomly as before. This is necessary for accessing the parts of a verb frame in the correct order, but may be useful to an end user as well. Fixed a bug with statement generation in that condition groups were not being surrounded in parentheses, which made mixing OR groups and AND groups generate inaccurate statements. This has been fixed; additionally, parentheses are not placed around the top level condition, and nested condition groups with the same logic type are coalesced, to make query strings as easy to read as possible. Also simplified the form::lemma field; it no longer conditions on the inflection of the form like the lemma::form field does. Also added a debug flag to statement::getQueryString that makes it return a query string with all of the bindings filled in, for debug use only.
Diffstat (limited to 'lib/field.h')
-rw-r--r-- | lib/field.h | 78 |
1 files changed, 66 insertions, 12 deletions
diff --git a/lib/field.h b/lib/field.h index f61e038..b4bf02d 100644 --- a/lib/field.h +++ b/lib/field.h | |||
@@ -17,6 +17,7 @@ namespace verbly { | |||
17 | integer, | 17 | integer, |
18 | boolean, | 18 | boolean, |
19 | join, | 19 | join, |
20 | join_where, | ||
20 | join_through, | 21 | join_through, |
21 | hierarchal_join | 22 | hierarchal_join |
22 | }; | 23 | }; |
@@ -95,6 +96,17 @@ namespace verbly { | |||
95 | return field(obj, type::join, name, nullable, table); | 96 | return field(obj, type::join, name, nullable, table); |
96 | } | 97 | } |
97 | 98 | ||
99 | static field joinWhere( | ||
100 | object obj, | ||
101 | const char* name, | ||
102 | object joinWith, | ||
103 | const field& conditionField, | ||
104 | int conditionValue, | ||
105 | bool nullable = false) | ||
106 | { | ||
107 | return field(obj, type::join_where, name, nullable, 0, joinWith, 0, 0, 0, &conditionField, conditionValue); | ||
108 | } | ||
109 | |||
98 | static field joinThrough( | 110 | static field joinThrough( |
99 | object obj, | 111 | object obj, |
100 | const char* name, | 112 | const char* name, |
@@ -151,7 +163,10 @@ namespace verbly { | |||
151 | 163 | ||
152 | bool isJoin() const | 164 | bool isJoin() const |
153 | { | 165 | { |
154 | return ((type_ == type::join) || (type_ == type::join_through) || (type_ == type::hierarchal_join)); | 166 | return ((type_ == type::join) |
167 | || (type_ == type::join_where) | ||
168 | || (type_ == type::join_through) | ||
169 | || (type_ == type::hierarchal_join)); | ||
155 | } | 170 | } |
156 | 171 | ||
157 | const char* getColumn() const | 172 | const char* getColumn() const |
@@ -180,7 +195,7 @@ namespace verbly { | |||
180 | { | 195 | { |
181 | return (type_ == type::hierarchal_join) | 196 | return (type_ == type::hierarchal_join) |
182 | ? object_ | 197 | ? object_ |
183 | : ((type_ == type::join) || (type_ == type::join_through)) | 198 | : ((type_ == type::join) || (type_ == type::join_where) || (type_ == type::join_through)) |
184 | ? joinObject_ | 199 | ? joinObject_ |
185 | : throw std::domain_error("Non-join fields don't have join objects"); | 200 | : throw std::domain_error("Non-join fields don't have join objects"); |
186 | } | 201 | } |
@@ -209,6 +224,22 @@ namespace verbly { | |||
209 | : throw std::domain_error("Only many-to-many join fields have a foreign join column"); | 224 | : throw std::domain_error("Only many-to-many join fields have a foreign join column"); |
210 | } | 225 | } |
211 | 226 | ||
227 | // Condition joins | ||
228 | |||
229 | const field& getConditionField() const | ||
230 | { | ||
231 | return (type_ == type::join_where) | ||
232 | ? *conditionField_ | ||
233 | : throw std::domain_error("Only condition join fields have a condition field"); | ||
234 | } | ||
235 | |||
236 | int getConditionValue() const | ||
237 | { | ||
238 | return (type_ == type::join_where) | ||
239 | ? conditionValue_ | ||
240 | : throw std::domain_error("Only condition join fields have a condition value"); | ||
241 | } | ||
242 | |||
212 | // Ordering | 243 | // Ordering |
213 | 244 | ||
214 | bool operator<(const field& other) const | 245 | bool operator<(const field& other) const |
@@ -217,20 +248,30 @@ namespace verbly { | |||
217 | // However, there do exist a number of relationships from an object to | 248 | // However, there do exist a number of relationships from an object to |
218 | // itself, such as notion hypernymy/hyponymy. Hypernymy and hyponymy have | 249 | // itself, such as notion hypernymy/hyponymy. Hypernymy and hyponymy have |
219 | // the same object (notion), the same column (notion_id), and the same | 250 | // the same object (notion), the same column (notion_id), and the same |
220 | // table (hypernymy); however, they have different join columns. | 251 | // table (hypernymy); however, they have different join columns. For |
221 | return std::tie(object_, column_, table_, joinColumn_) < std::tie(other.object_, other.column_, other.table_, other.joinColumn_); | 252 | // condition joins, the condition field and condition value are also |
253 | // significant. | ||
254 | if (conditionField_) | ||
255 | { | ||
256 | return std::tie(object_, column_, table_, joinColumn_, *conditionField_, conditionValue_) | ||
257 | < std::tie(other.object_, other.column_, other.table_, other.joinColumn_, *other.conditionField_, other.conditionValue_); | ||
258 | } else { | ||
259 | return std::tie(object_, column_, table_, joinColumn_) < std::tie(other.object_, other.column_, other.table_, other.joinColumn_); | ||
260 | } | ||
222 | } | 261 | } |
223 | 262 | ||
224 | // Equality | 263 | // Equality |
225 | 264 | ||
226 | bool operator==(const field& other) const | 265 | bool operator==(const field& other) const |
227 | { | 266 | { |
228 | // For the most part, (object, column) uniquely identifies fields. | 267 | // See operator<() for documentation. |
229 | // However, there do exist a number of relationships from an object to | 268 | if (conditionField_) |
230 | // itself, such as notion hypernymy/hyponymy. Hypernymy and hyponymy have | 269 | { |
231 | // the same object (notion), the same column (notion_id), and the same | 270 | return std::tie(object_, column_, table_, joinColumn_, *conditionField_, conditionValue_) |
232 | // table (hypernymy); however, they have different join columns. | 271 | == std::tie(other.object_, other.column_, other.table_, other.joinColumn_, *other.conditionField_, other.conditionValue_); |
233 | return std::tie(object_, column_, table_, joinColumn_) == std::tie(other.object_, other.column_, other.table_, other.joinColumn_); | 272 | } else { |
273 | return std::tie(object_, column_, table_, joinColumn_) == std::tie(other.object_, other.column_, other.table_, other.joinColumn_); | ||
274 | } | ||
234 | } | 275 | } |
235 | 276 | ||
236 | // Filter construction | 277 | // Filter construction |
@@ -245,6 +286,7 @@ namespace verbly { | |||
245 | filter operator==(part_of_speech value) const; // Part of speech equality | 286 | filter operator==(part_of_speech value) const; // Part of speech equality |
246 | filter operator==(positioning value) const; // Adjective positioning equality | 287 | filter operator==(positioning value) const; // Adjective positioning equality |
247 | filter operator==(inflection value) const; // Inflection category equality | 288 | filter operator==(inflection value) const; // Inflection category equality |
289 | filter operator==(part_type value) const; // Verb frame part type equality | ||
248 | 290 | ||
249 | filter operator==(bool value) const; // Boolean equality | 291 | filter operator==(bool value) const; // Boolean equality |
250 | 292 | ||
@@ -252,6 +294,10 @@ namespace verbly { | |||
252 | filter operator!=(std::string value) const; // String inequality | 294 | filter operator!=(std::string value) const; // String inequality |
253 | filter operator%=(std::string value) const; // String matching | 295 | filter operator%=(std::string value) const; // String matching |
254 | 296 | ||
297 | filter operator==(const char* value) const; // String equality | ||
298 | filter operator!=(const char* value) const; // String inequality | ||
299 | filter operator%=(const char* value) const; // String matching | ||
300 | |||
255 | operator filter() const; // Non-nullity | 301 | operator filter() const; // Non-nullity |
256 | filter operator!() const; // Nullity | 302 | filter operator!() const; // Nullity |
257 | 303 | ||
@@ -270,7 +316,9 @@ namespace verbly { | |||
270 | object joinObject = object::undefined, | 316 | object joinObject = object::undefined, |
271 | const char* foreignColumn = 0, | 317 | const char* foreignColumn = 0, |
272 | const char* joinColumn = 0, | 318 | const char* joinColumn = 0, |
273 | const char* foreignJoinColumn = 0) : | 319 | const char* foreignJoinColumn = 0, |
320 | const field* conditionField = 0, | ||
321 | int conditionValue = 0) : | ||
274 | object_(obj), | 322 | object_(obj), |
275 | type_(datatype), | 323 | type_(datatype), |
276 | column_(column), | 324 | column_(column), |
@@ -279,7 +327,9 @@ namespace verbly { | |||
279 | joinObject_(joinObject), | 327 | joinObject_(joinObject), |
280 | foreignColumn_(foreignColumn), | 328 | foreignColumn_(foreignColumn), |
281 | joinColumn_(joinColumn), | 329 | joinColumn_(joinColumn), |
282 | foreignJoinColumn_(foreignJoinColumn) | 330 | foreignJoinColumn_(foreignJoinColumn), |
331 | conditionField_(conditionField), | ||
332 | conditionValue_(conditionValue) | ||
283 | { | 333 | { |
284 | } | 334 | } |
285 | 335 | ||
@@ -300,6 +350,10 @@ namespace verbly { | |||
300 | const char* joinColumn_ = 0; | 350 | const char* joinColumn_ = 0; |
301 | const char* foreignJoinColumn_ = 0; | 351 | const char* foreignJoinColumn_ = 0; |
302 | 352 | ||
353 | // Condition joins | ||
354 | const field* conditionField_ = 0; | ||
355 | int conditionValue_ = 0; | ||
356 | |||
303 | }; | 357 | }; |
304 | 358 | ||
305 | }; | 359 | }; |