diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-16 18:02:50 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-16 18:02:50 -0500 |
commit | 6746da6edd7d9d50efe374eabbb79a3cac882d81 (patch) | |
tree | ff20917e08b08d36b9541c1371106596e7bec442 /lib/database.cpp | |
parent | 4af7e55733098ca42f75a4ffaca1b0f6bab4dd36 (diff) | |
download | verbly-6746da6edd7d9d50efe374eabbb79a3cac882d81.tar.gz verbly-6746da6edd7d9d50efe374eabbb79a3cac882d81.tar.bz2 verbly-6746da6edd7d9d50efe374eabbb79a3cac882d81.zip |
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.
Diffstat (limited to 'lib/database.cpp')
-rw-r--r-- | lib/database.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
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 @@ | |||
1 | #include "database.h" | ||
2 | #include <sqlite3.h> | ||
3 | #include <stdexcept> | ||
4 | #include "query.h" | ||
5 | |||
6 | namespace verbly { | ||
7 | |||
8 | database::database(std::string path) | ||
9 | { | ||
10 | if (sqlite3_open_v2(path.c_str(), &ppdb_, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) | ||
11 | { | ||
12 | // We still have to free the resources allocated. In the event that | ||
13 | // allocation failed, ppdb will be null and sqlite3_close_v2 will just | ||
14 | // ignore it. | ||
15 | std::string errmsg(sqlite3_errmsg(ppdb_)); | ||
16 | sqlite3_close_v2(ppdb_); | ||
17 | |||
18 | throw database_error("Could not open verbly datafile", errmsg); | ||
19 | } | ||
20 | } | ||
21 | |||
22 | database::database(database&& other) : database() | ||
23 | { | ||
24 | swap(*this, other); | ||
25 | } | ||
26 | |||
27 | database& database::operator=(database&& other) | ||
28 | { | ||
29 | swap(*this, other); | ||
30 | |||
31 | return *this; | ||
32 | } | ||
33 | |||
34 | void swap(database& first, database& second) | ||
35 | { | ||
36 | std::swap(first.ppdb_, second.ppdb_); | ||
37 | } | ||
38 | |||
39 | database::~database() | ||
40 | { | ||
41 | sqlite3_close_v2(ppdb_); | ||
42 | } | ||
43 | |||
44 | query<notion> database::notions(filter where, bool random, int limit) const | ||
45 | { | ||
46 | return query<notion>(*this, ppdb_, std::move(where), random, limit); | ||
47 | } | ||
48 | |||
49 | query<word> database::words(filter where, bool random, int limit) const | ||
50 | { | ||
51 | return query<word>(*this, ppdb_, std::move(where), random, limit); | ||
52 | } | ||
53 | |||
54 | query<group> database::groups(filter where, bool random, int limit) const | ||
55 | { | ||
56 | return query<group>(*this, ppdb_, std::move(where), random, limit); | ||
57 | } | ||
58 | |||
59 | query<frame> database::frames(filter where, bool random, int limit) const | ||
60 | { | ||
61 | return query<frame>(*this, ppdb_, std::move(where), random, limit); | ||
62 | } | ||
63 | |||
64 | query<lemma> database::lemmas(filter where, bool random, int limit) const | ||
65 | { | ||
66 | return query<lemma>(*this, ppdb_, std::move(where), random, limit); | ||
67 | } | ||
68 | |||
69 | query<form> database::forms(filter where, bool random, int limit) const | ||
70 | { | ||
71 | return query<form>(*this, ppdb_, std::move(where), random, limit); | ||
72 | } | ||
73 | |||
74 | query<pronunciation> database::pronunciations(filter where, bool random, int limit) const | ||
75 | { | ||
76 | return query<pronunciation>(*this, ppdb_, std::move(where), random, limit); | ||
77 | } | ||
78 | |||
79 | }; | ||