summary refs log tree commit diff stats
path: root/lib/database.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-02-05 08:56:39 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-02-05 08:56:39 -0500
commite4fa0cb86d97c23c24cd7bdd62c23f03eed312da (patch)
tree70a20fdf684b1724659196a7de8d21a4a6ca194f /lib/database.cpp
parentbea3673ae1b3d19585dec56e96dbcd8a56b96e6d (diff)
downloadverbly-e4fa0cb86d97c23c24cd7bdd62c23f03eed312da.tar.gz
verbly-e4fa0cb86d97c23c24cd7bdd62c23f03eed312da.tar.bz2
verbly-e4fa0cb86d97c23c24cd7bdd62c23f03eed312da.zip
Flattened selrestrs
Now, selrestrs are, instead of logically being a tree of
positive/negative restrictions that are ANDed/ORed together, they are a
flat set of positive restrictions that are ORed together. They are
stored as strings in a table called selrestrs, just like synrestrs,
which makes them a lot more queryable now as well. This change required
some changes to the VerbNet data, because we needed to consolidate any
ANDed clauses into single selrestrs, as well as convert any negative
selrestrs into positive ones. The changes made are detailed on the wiki.

Preposition choices are now encoded as comma-separated lists instead of
using JSON. This change, along with the selrestrs one, allows us to
remove verbly's dependency on nlohmann::json.
Diffstat (limited to 'lib/database.cpp')
-rw-r--r--lib/database.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/database.cpp b/lib/database.cpp index 563ec31..c7b37ec 100644 --- a/lib/database.cpp +++ b/lib/database.cpp
@@ -76,6 +76,38 @@ namespace verbly {
76 return query<pronunciation>(*this, ppdb_, std::move(where), std::move(sortOrder), limit); 76 return query<pronunciation>(*this, ppdb_, std::move(where), std::move(sortOrder), limit);
77 } 77 }
78 78
79 std::set<std::string> database::selrestrs(int partId) const
80 {
81 std::string queryString = "SELECT selrestr FROM selrestrs WHERE part_id = ?";
82
83 sqlite3_stmt* ppstmt;
84 if (sqlite3_prepare_v2(ppdb_, queryString.c_str(), queryString.length(), &ppstmt, NULL) != SQLITE_OK)
85 {
86 std::string errorMsg = sqlite3_errmsg(ppdb_);
87 sqlite3_finalize(ppstmt);
88
89 throw database_error("Error preparing query", errorMsg);
90 }
91
92 if (sqlite3_bind_int(ppstmt, 1, partId) != SQLITE_OK)
93 {
94 std::string errorMsg = sqlite3_errmsg(ppdb_);
95 sqlite3_finalize(ppstmt);
96
97 throw database_error("Error binding value to query", errorMsg);
98 }
99
100 std::set<std::string> result;
101 while (sqlite3_step(ppstmt) == SQLITE_ROW)
102 {
103 result.insert(reinterpret_cast<const char*>(sqlite3_column_blob(ppstmt, 0)));
104 }
105
106 sqlite3_finalize(ppstmt);
107
108 return result;
109 }
110
79 std::set<std::string> database::synrestrs(int partId) const 111 std::set<std::string> database::synrestrs(int partId) const
80 { 112 {
81 std::string queryString = "SELECT synrestr FROM synrestrs WHERE part_id = ?"; 113 std::string queryString = "SELECT synrestr FROM synrestrs WHERE part_id = ?";