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