summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-10-16 11:19:23 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-10-16 11:19:23 -0400
commit1fd518d1c2b1d4e88ad88218b606a284b7128107 (patch)
tree220bbea3845cdd8058c3a4c44b8acb6687803cc3
parent59eab842de02b2b2ba8bf53e2214b558457e6356 (diff)
downloadverbly-1fd518d1c2b1d4e88ad88218b606a284b7128107.tar.gz
verbly-1fd518d1c2b1d4e88ad88218b606a284b7128107.tar.bz2
verbly-1fd518d1c2b1d4e88ad88218b606a284b7128107.zip
Added length field to form table
This commit contains a database update.
-rw-r--r--generator/form.cpp4
-rw-r--r--generator/form.h6
-rw-r--r--generator/schema.sql3
-rw-r--r--lib/form.cpp4
-rw-r--r--lib/form.h14
5 files changed, 27 insertions, 4 deletions
diff --git a/generator/form.cpp b/generator/form.cpp index 6be9d47..f616344 100644 --- a/generator/form.cpp +++ b/generator/form.cpp
@@ -14,7 +14,8 @@ namespace verbly {
14 id_(nextId_++), 14 id_(nextId_++),
15 text_(text), 15 text_(text),
16 complexity_(std::count(std::begin(text), std::end(text), ' ') + 1), 16 complexity_(std::count(std::begin(text), std::end(text), ' ') + 1),
17 proper_(std::any_of(std::begin(text), std::end(text), std::isupper)) 17 proper_(std::any_of(std::begin(text), std::end(text), std::isupper)),
18 length_(text.length())
18 { 19 {
19 } 20 }
20 21
@@ -32,6 +33,7 @@ namespace verbly {
32 fields.emplace_back("form", arg.getText()); 33 fields.emplace_back("form", arg.getText());
33 fields.emplace_back("complexity", arg.getComplexity()); 34 fields.emplace_back("complexity", arg.getComplexity());
34 fields.emplace_back("proper", arg.isProper()); 35 fields.emplace_back("proper", arg.isProper());
36 fields.emplace_back("length", arg.getLength());
35 37
36 db.insertIntoTable("forms", std::move(fields)); 38 db.insertIntoTable("forms", std::move(fields));
37 } 39 }
diff --git a/generator/form.h b/generator/form.h index 5576035..5a2de30 100644 --- a/generator/form.h +++ b/generator/form.h
@@ -43,6 +43,11 @@ namespace verbly {
43 return proper_; 43 return proper_;
44 } 44 }
45 45
46 int getLength() const
47 {
48 return length_;
49 }
50
46 std::set<const pronunciation*> getPronunciations() const 51 std::set<const pronunciation*> getPronunciations() const
47 { 52 {
48 return pronunciations_; 53 return pronunciations_;
@@ -56,6 +61,7 @@ namespace verbly {
56 const std::string text_; 61 const std::string text_;
57 const int complexity_; 62 const int complexity_;
58 const bool proper_; 63 const bool proper_;
64 const int length_;
59 65
60 std::set<const pronunciation*> pronunciations_; 66 std::set<const pronunciation*> pronunciations_;
61 67
diff --git a/generator/schema.sql b/generator/schema.sql index a49a853..c0f2bcb 100644 --- a/generator/schema.sql +++ b/generator/schema.sql
@@ -155,7 +155,8 @@ CREATE TABLE `forms` (
155 `form_id` INTEGER PRIMARY KEY, 155 `form_id` INTEGER PRIMARY KEY,
156 `form` VARCHAR(32) NOT NULL, 156 `form` VARCHAR(32) NOT NULL,
157 `complexity` SMALLINT NOT NULL, 157 `complexity` SMALLINT NOT NULL,
158 `proper` SMALLINT NOT NULL 158 `proper` SMALLINT NOT NULL,
159 `length` SMALLINT NOT NULL
159); 160);
160 161
161CREATE UNIQUE INDEX `form_by_string` ON `forms`(`form`); 162CREATE UNIQUE INDEX `form_by_string` ON `forms`(`form`);
diff --git a/lib/form.cpp b/lib/form.cpp index 2f9509f..feaf765 100644 --- a/lib/form.cpp +++ b/lib/form.cpp
@@ -10,12 +10,13 @@ namespace verbly {
10 10
11 const object form::objectType = object::form; 11 const object form::objectType = object::form;
12 12
13 const std::list<std::string> form::select = {"form_id", "form", "complexity", "proper"}; 13 const std::list<std::string> form::select = {"form_id", "form", "complexity", "proper", "length"};
14 14
15 const field form::id = field::integerField(object::form, "form_id"); 15 const field form::id = field::integerField(object::form, "form_id");
16 const field form::text = field::stringField(object::form, "form"); 16 const field form::text = field::stringField(object::form, "form");
17 const field form::complexity = field::integerField(object::form, "complexity"); 17 const field form::complexity = field::integerField(object::form, "complexity");
18 const field form::proper = field::booleanField(object::form, "proper"); 18 const field form::proper = field::booleanField(object::form, "proper");
19 const field form::length = field::integerField(object::form, "length");
19 20
20 const field form::pronunciations = field::joinThrough(object::form, "form_id", object::pronunciation, "forms_pronunciations", "pronunciation_id"); 21 const field form::pronunciations = field::joinThrough(object::form, "form_id", object::pronunciation, "forms_pronunciations", "pronunciation_id");
21 22
@@ -30,6 +31,7 @@ namespace verbly {
30 text_ = std::string(reinterpret_cast<const char*>(sqlite3_column_text(row, 1))); 31 text_ = std::string(reinterpret_cast<const char*>(sqlite3_column_text(row, 1)));
31 complexity_ = sqlite3_column_int(row, 2); 32 complexity_ = sqlite3_column_int(row, 2);
32 proper_ = (sqlite3_column_int(row, 3) == 1); 33 proper_ = (sqlite3_column_int(row, 3) == 1);
34 length_ = sqlite3_column_int(row, 4);
33 } 35 }
34 36
35 const std::vector<pronunciation>& form::getPronunciations() const 37 const std::vector<pronunciation>& form::getPronunciations() const
diff --git a/lib/form.h b/lib/form.h index e3e1185..479672f 100644 --- a/lib/form.h +++ b/lib/form.h
@@ -73,6 +73,16 @@ namespace verbly {
73 return proper_; 73 return proper_;
74 } 74 }
75 75
76 int getLength() const
77 {
78 if (!valid_)
79 {
80 throw std::domain_error("Bad access to uninitialized form");
81 }
82
83 return length_;
84 }
85
76 const std::vector<pronunciation>& getPronunciations() const; 86 const std::vector<pronunciation>& getPronunciations() const;
77 87
78 // Convenience 88 // Convenience
@@ -91,6 +101,7 @@ namespace verbly {
91 static const field text; 101 static const field text;
92 static const field complexity; 102 static const field complexity;
93 static const field proper; 103 static const field proper;
104 static const field length;
94 105
95 operator filter() const 106 operator filter() const
96 { 107 {
@@ -123,8 +134,9 @@ namespace verbly {
123 134
124 int id_; 135 int id_;
125 std::string text_; 136 std::string text_;
126 int complexity_ ; 137 int complexity_;
127 bool proper_; 138 bool proper_;
139 int length_;
128 140
129 const database* db_; 141 const database* db_;
130 142