From 6746da6edd7d9d50efe374eabbb79a3cac882d81 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 16 Jan 2017 18:02:50 -0500 Subject: Started structural rewrite The new object structure was designed to build on the existing WordNet structure, while also adding in all of the data that we get from other sources. More information about this can be found on the project wiki. The generator has already been completely rewritten to generate a datafile that uses the new structure. In addition, a number of indexes are created, which does double the size of the datafile, but also allows for much faster lookups. Finally, the new generator is written modularly and is a lot more readable than the old one. The verbly interface to the new object structure has mostly been completed, but has not been tested fully. There is a completely new search API which utilizes a lot of operator overloading; documentation on how to use it should go up at some point. Token processing and verb frames are currently unimplemented. Source for these have been left in the repository for now. --- lib/database.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 lib/database.cpp (limited to 'lib/database.cpp') diff --git a/lib/database.cpp b/lib/database.cpp new file mode 100644 index 0000000..351b93d --- /dev/null +++ b/lib/database.cpp @@ -0,0 +1,79 @@ +#include "database.h" +#include +#include +#include "query.h" + +namespace verbly { + + database::database(std::string path) + { + if (sqlite3_open_v2(path.c_str(), &ppdb_, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) + { + // We still have to free the resources allocated. In the event that + // allocation failed, ppdb will be null and sqlite3_close_v2 will just + // ignore it. + std::string errmsg(sqlite3_errmsg(ppdb_)); + sqlite3_close_v2(ppdb_); + + throw database_error("Could not open verbly datafile", errmsg); + } + } + + database::database(database&& other) : database() + { + swap(*this, other); + } + + database& database::operator=(database&& other) + { + swap(*this, other); + + return *this; + } + + void swap(database& first, database& second) + { + std::swap(first.ppdb_, second.ppdb_); + } + + database::~database() + { + sqlite3_close_v2(ppdb_); + } + + query database::notions(filter where, bool random, int limit) const + { + return query(*this, ppdb_, std::move(where), random, limit); + } + + query database::words(filter where, bool random, int limit) const + { + return query(*this, ppdb_, std::move(where), random, limit); + } + + query database::groups(filter where, bool random, int limit) const + { + return query(*this, ppdb_, std::move(where), random, limit); + } + + query database::frames(filter where, bool random, int limit) const + { + return query(*this, ppdb_, std::move(where), random, limit); + } + + query database::lemmas(filter where, bool random, int limit) const + { + return query(*this, ppdb_, std::move(where), random, limit); + } + + query
database::forms(filter where, bool random, int limit) const + { + return query(*this, ppdb_, std::move(where), random, limit); + } + + query database::pronunciations(filter where, bool random, int limit) const + { + return query(*this, ppdb_, std::move(where), random, limit); + } + +}; -- cgit 1.4.1