summary refs log tree commit diff stats
path: root/lib/lemma.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-02-06 20:58:37 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-02-06 20:58:37 -0500
commitf1f67e62cebb4144f0599196263cd93b41fa972e (patch)
tree5d0f8fceeec63f47fb85846f5568bcb36f4a975f /lib/lemma.cpp
parent6cc23ba387d0813b801ba094709673a61bac889c (diff)
downloadverbly-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/lemma.cpp')
-rw-r--r--lib/lemma.cpp67
1 files changed, 0 insertions, 67 deletions
diff --git a/lib/lemma.cpp b/lib/lemma.cpp deleted file mode 100644 index ea7b0ea..0000000 --- a/lib/lemma.cpp +++ /dev/null
@@ -1,67 +0,0 @@
1#include "lemma.h"
2#include <sqlite3.h>
3#include "database.h"
4#include "query.h"
5
6namespace verbly {
7
8 const object lemma::objectType = object::lemma;
9
10 const std::list<std::string> lemma::select = {"lemma_id"};
11
12 const field lemma::id = field::integerField(object::lemma, "lemma_id");
13 const field lemma::inflectionCategory = field::integerField(object::lemma, "category");
14
15 const field lemma::words = field::joinField(object::lemma, "lemma_id", object::word);
16
17 field lemma::forms(inflection category)
18 {
19 return field::joinWhere(object::lemma, "form_id", object::form, inflectionCategory, static_cast<int>(category));
20 }
21
22 lemma::lemma(const database& db, sqlite3_stmt* row) : db_(&db), valid_(true)
23 {
24 id_ = sqlite3_column_int(row, 0);
25 }
26
27 const form& lemma::getBaseForm() const
28 {
29 if (!valid_)
30 {
31 throw std::domain_error("Bad access to uninitialized lemma");
32 }
33
34 if (!forms_.count(inflection::base))
35 {
36 initializeForm(inflection::base);
37 }
38
39 return forms_.at(inflection::base).front();
40 }
41
42 bool lemma::hasInflection(inflection category) const
43 {
44 return !getInflections(category).empty();
45 }
46
47 const std::vector<form>& lemma::getInflections(inflection category) const
48 {
49 if (!valid_)
50 {
51 throw std::domain_error("Bad access to uninitialized lemma");
52 }
53
54 if (!forms_.count(category))
55 {
56 initializeForm(category);
57 }
58
59 return forms_.at(category);
60 }
61
62 void lemma::initializeForm(inflection infl) const
63 {
64 forms_[infl] = db_->forms(form::lemmas %= ((inflectionCategory == infl) && *this), verbly::form::id, -1).all();
65 }
66
67};