diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-02-06 20:58:37 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-02-06 20:58:37 -0500 |
commit | f1f67e62cebb4144f0599196263cd93b41fa972e (patch) | |
tree | 5d0f8fceeec63f47fb85846f5568bcb36f4a975f /lib/binding.cpp | |
parent | 6cc23ba387d0813b801ba094709673a61bac889c (diff) | |
download | verbly-f1f67e62cebb4144f0599196263cd93b41fa972e.tar.gz verbly-f1f67e62cebb4144f0599196263cd93b41fa972e.tar.bz2 verbly-f1f67e62cebb4144f0599196263cd93b41fa972e.zip |
Made pronunciation::rhymes join dynamic
This involved adding a new type of filter; one that compares (currently only equality and inequality) a field with another field located in an enclosing join context. In the process, it was discovered that simplifying the lemma::forms join field earlier actually made some queries return inaccurate results because the inflection of the form was being ignored and anything in the lemma would be used because of the inner join. Because the existing condition join did not allow for the condition field to be on the from side of the join, two things were done: a condition version of joinThrough was made, and lemma was finally eliminated as a top-level object, replaced instead with a condition join between word and form through lemmas_forms. Queries are also now grouped by the first select field (assumed to be the primary ID) of the top table, in order to eliminate duplicates created by inner joins, so that there is a uniform distribution between results for random queries. Created a database index on pronunciations(rhyme) which decreases query time for rhyming filters. The new database version is backwards-compatible because no data or structure changed.
Diffstat (limited to 'lib/binding.cpp')
-rw-r--r-- | lib/binding.cpp | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/lib/binding.cpp b/lib/binding.cpp index 349cd6f..0b58785 100644 --- a/lib/binding.cpp +++ b/lib/binding.cpp | |||
@@ -24,6 +24,14 @@ namespace verbly { | |||
24 | break; | 24 | break; |
25 | } | 25 | } |
26 | 26 | ||
27 | case type::field: | ||
28 | { | ||
29 | new(&field_.table_) std::string(other.field_.table_); | ||
30 | new(&field_.column_) std::string(other.field_.column_); | ||
31 | |||
32 | break; | ||
33 | } | ||
34 | |||
27 | case type::invalid: | 35 | case type::invalid: |
28 | { | 36 | { |
29 | break; | 37 | break; |
@@ -50,6 +58,8 @@ namespace verbly { | |||
50 | type tempType = first.type_; | 58 | type tempType = first.type_; |
51 | int tempInteger; | 59 | int tempInteger; |
52 | std::string tempString; | 60 | std::string tempString; |
61 | std::string tempTable; | ||
62 | std::string tempColumn; | ||
53 | 63 | ||
54 | switch (first.type_) | 64 | switch (first.type_) |
55 | { | 65 | { |
@@ -67,6 +77,14 @@ namespace verbly { | |||
67 | break; | 77 | break; |
68 | } | 78 | } |
69 | 79 | ||
80 | case type::field: | ||
81 | { | ||
82 | tempTable = std::move(first.field_.table_); | ||
83 | tempColumn = std::move(first.field_.column_); | ||
84 | |||
85 | break; | ||
86 | } | ||
87 | |||
70 | case type::invalid: | 88 | case type::invalid: |
71 | { | 89 | { |
72 | break; | 90 | break; |
@@ -93,6 +111,14 @@ namespace verbly { | |||
93 | break; | 111 | break; |
94 | } | 112 | } |
95 | 113 | ||
114 | case type::field: | ||
115 | { | ||
116 | new(&first.field_.table_) std::string(std::move(second.field_.table_)); | ||
117 | new(&first.field_.column_) std::string(std::move(second.field_.column_)); | ||
118 | |||
119 | break; | ||
120 | } | ||
121 | |||
96 | case type::invalid: | 122 | case type::invalid: |
97 | { | 123 | { |
98 | break; | 124 | break; |
@@ -119,6 +145,14 @@ namespace verbly { | |||
119 | break; | 145 | break; |
120 | } | 146 | } |
121 | 147 | ||
148 | case type::field: | ||
149 | { | ||
150 | new(&first.field_.table_) std::string(std::move(tempTable)); | ||
151 | new(&first.field_.column_) std::string(std::move(tempColumn)); | ||
152 | |||
153 | break; | ||
154 | } | ||
155 | |||
122 | case type::invalid: | 156 | case type::invalid: |
123 | { | 157 | { |
124 | break; | 158 | break; |
@@ -138,6 +172,15 @@ namespace verbly { | |||
138 | break; | 172 | break; |
139 | } | 173 | } |
140 | 174 | ||
175 | case type::field: | ||
176 | { | ||
177 | using string_type = std::string; | ||
178 | field_.table_.~string_type(); | ||
179 | field_.column_.~string_type(); | ||
180 | |||
181 | break; | ||
182 | } | ||
183 | |||
141 | case type::integer: | 184 | case type::integer: |
142 | case type::invalid: | 185 | case type::invalid: |
143 | { | 186 | { |
@@ -164,7 +207,7 @@ namespace verbly { | |||
164 | 207 | ||
165 | binding::binding(std::string arg) : type_(type::string) | 208 | binding::binding(std::string arg) : type_(type::string) |
166 | { | 209 | { |
167 | new(&string_) std::string(arg); | 210 | new(&string_) std::string(std::move(arg)); |
168 | } | 211 | } |
169 | 212 | ||
170 | std::string binding::getString() const | 213 | std::string binding::getString() const |
@@ -177,4 +220,30 @@ namespace verbly { | |||
177 | return string_; | 220 | return string_; |
178 | } | 221 | } |
179 | 222 | ||
223 | binding::binding(std::string table, std::string column) : type_(type::field) | ||
224 | { | ||
225 | new(&field_.table_) std::string(std::move(table)); | ||
226 | new(&field_.column_) std::string(std::move(column)); | ||
227 | } | ||
228 | |||
229 | std::string binding::getTable() const | ||
230 | { | ||
231 | if (type_ != type::field) | ||
232 | { | ||
233 | throw std::domain_error("binding::getTable called on non-field binding"); | ||
234 | } | ||
235 | |||
236 | return field_.table_; | ||
237 | } | ||
238 | |||
239 | std::string binding::getColumn() const | ||
240 | { | ||
241 | if (type_ != type::field) | ||
242 | { | ||
243 | throw std::domain_error("binding::getColumn called on non-field binding"); | ||
244 | } | ||
245 | |||
246 | return field_.column_; | ||
247 | } | ||
248 | |||
180 | }; | 249 | }; |