summary refs log tree commit diff stats
path: root/lib/notion.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-01-16 18:02:50 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-01-16 18:02:50 -0500
commit6746da6edd7d9d50efe374eabbb79a3cac882d81 (patch)
treeff20917e08b08d36b9541c1371106596e7bec442 /lib/notion.h
parent4af7e55733098ca42f75a4ffaca1b0f6bab4dd36 (diff)
downloadverbly-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/notion.h')
-rw-r--r--lib/notion.h200
1 files changed, 200 insertions, 0 deletions
diff --git a/lib/notion.h b/lib/notion.h new file mode 100644 index 0000000..a180d73 --- /dev/null +++ b/lib/notion.h
@@ -0,0 +1,200 @@
1#ifndef NOTION_H_FD1C7646
2#define NOTION_H_FD1C7646
3
4#include <stdexcept>
5#include <string>
6#include "field.h"
7#include "filter.h"
8
9struct sqlite3_stmt;
10
11namespace verbly {
12
13 class database;
14
15 class notion {
16 public:
17
18 // Default constructor
19
20 notion() = default;
21
22 // Construct from database
23
24 notion(const database& db, sqlite3_stmt* row);
25
26 // Accessors
27
28 operator bool() const
29 {
30 return valid_;
31 }
32
33 int getId() const
34 {
35 if (!valid_)
36 {
37 throw std::domain_error("Bad access to uninitialized notion");
38 }
39
40 return id_;
41 }
42
43 part_of_speech getPartOfSpeech() const
44 {
45 if (!valid_)
46 {
47 throw std::domain_error("Bad access to uninitialized notion");
48 }
49
50 return partOfSpeech_;
51 }
52
53 bool hasWnid() const
54 {
55 if (!valid_)
56 {
57 throw std::domain_error("Bad access to uninitialized notion");
58 }
59
60 return hasWnid_;
61 }
62
63 int getWnid() const
64 {
65 if (!valid_)
66 {
67 throw std::domain_error("Bad access to uninitialized notion");
68 }
69
70 if (!hasWnid_)
71 {
72 throw std::domain_error("Notion has no wnid");
73 }
74
75 return wnid_;
76 }
77
78 bool hasNumOfImages() const
79 {
80 if (!valid_)
81 {
82 throw std::domain_error("Bad access to uninitialized notion");
83 }
84
85 return hasNumOfImages_;
86 }
87
88 int getNumOfImages() const
89 {
90 if (!valid_)
91 {
92 throw std::domain_error("Bad access to uninitialized notion");
93 }
94
95 if (!hasNumOfImages_)
96 {
97 throw std::domain_error("Notion does not have a number of images");
98 }
99
100 return numOfImages_;
101 }
102
103 // Convenience
104
105 std::string getImageNetUrl() const;
106
107 // Type info
108
109 static const object objectType;
110
111 static const std::list<std::string> select;
112
113 // Query fields
114
115 static const field id;
116 static const field partOfSpeech;
117 static const field wnid;
118 static const field numOfImages;
119
120 operator filter() const
121 {
122 return (id == id_);
123 }
124
125 // Relationships with other objects
126
127 static const field word;
128
129 // Relationships with self
130
131 static const field hypernyms;
132 static const field hyponyms;
133
134 static const field fullHypernyms;
135 static const field fullHyponyms;
136
137 static const field instances;
138 static const field classes;
139
140 static const field memberMeronyms;
141 static const field memberHolonyms;
142
143 static const field fullMemberMeronyms;
144 static const field fullMemberHolonyms;
145
146 static const field partMeronyms;
147 static const field partHolonyms;
148
149 static const field fullPartMeronyms;
150 static const field fullPartHolonyms;
151
152 static const field substanceMeronyms;
153 static const field substanceHolonyms;
154
155 static const field fullSubstanceMeronyms;
156 static const field fullSubstanceHolonyms;
157
158 static const field variants;
159 static const field attributes;
160
161 static const field similarAdjectives;
162
163 static const field entails;
164 static const field entailedBy;
165
166 static const field causes;
167 static const field effects;
168
169 // Preposition group relationship
170
171 class preposition_group_field {
172 public:
173
174 filter operator==(std::string groupName) const;
175
176 private:
177
178 static const field isA;
179 static const field groupNameField;
180 };
181
182 static const preposition_group_field prepositionGroup;
183
184 private:
185 bool valid_ = false;
186
187 int id_;
188 part_of_speech partOfSpeech_;
189 bool hasWnid_ = false;
190 int wnid_;
191 bool hasNumOfImages_ = false;
192 int numOfImages_;
193
194 const database* db_;
195
196 };
197
198};
199
200#endif /* end of include guard: NOTION_H_FD1C7646 */