summary refs log tree commit diff stats
path: root/lib/word.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/word.h')
-rw-r--r--lib/word.h193
1 files changed, 159 insertions, 34 deletions
diff --git a/lib/word.h b/lib/word.h index 08797a3..f71dad9 100644 --- a/lib/word.h +++ b/lib/word.h
@@ -1,48 +1,173 @@
1#ifndef WORD_H_8FC89498 1#ifndef WORD_H_DF91B1B4
2#define WORD_H_8FC89498 2#define WORD_H_DF91B1B4
3
4#include <stdexcept>
5#include <map>
6#include "field.h"
7#include "filter.h"
8#include "notion.h"
9#include "lemma.h"
10#include "group.h"
11
12struct sqlite3_stmt;
3 13
4namespace verbly { 14namespace verbly {
5 15
6 class rhyme { 16 class database;
7 public: 17
8 rhyme(std::string prerhyme, std::string phonemes); 18 class word {
19 public:
20
21 // Default constructor
22
23 word() = default;
24
25 // Construct from database
26
27 word(const database& db, sqlite3_stmt* row);
28
29 // Accessors
30
31 operator bool() const
32 {
33 return valid_;
34 }
35
36 int getId() const
37 {
38 if (!valid_)
39 {
40 throw std::domain_error("Bad access to uninitialized word");
41 }
9 42
10 std::string get_prerhyme() const; 43 return id_;
11 std::string get_rhyme() const; 44 }
45
46 bool hasTagCount() const
47 {
48 if (!valid_)
49 {
50 throw std::domain_error("Bad access to uninitialized word");
51 }
12 52
13 bool operator==(const rhyme& other) const; 53 return hasTagCount_;
54 }
55
56 int getTagCount() const
57 {
58 if (!valid_)
59 {
60 throw std::domain_error("Bad access to uninitialized word");
61 }
14 62
15 private: 63 if (!hasTagCount_)
16 std::string _prerhyme; 64 {
17 std::string _rhyme; 65 throw std::domain_error("Word has no tag count");
18 }; 66 }
19
20 class word {
21 protected:
22 const data* _data;
23 int _id;
24 bool _valid = false;
25 67
26 std::list<std::list<std::string>> pronunciations; 68 return tagCount_;
27 std::list<rhyme> rhymes; 69 }
70
71 bool hasAdjectivePositioning() const
72 {
73 if (!valid_)
74 {
75 throw std::domain_error("Bad access to uninitialized word");
76 }
28 77
29 word(); 78 return (adjectivePosition_ != positioning::undefined);
30 word(const data& _data, int _id); 79 }
80
81 positioning getAdjectivePosition() const
82 {
83 if (!valid_)
84 {
85 throw std::domain_error("Bad access to uninitialized word");
86 }
31 87
32 friend class adjective_query; 88 if (adjectivePosition_ == positioning::undefined)
33 friend class verb_query; 89 {
34 friend class noun_query; 90 throw std::domain_error("Word has no adjective position");
35 friend class adverb_query; 91 }
36 friend class frame_query;
37 friend class preposition_query;
38
39 public:
40 virtual std::string base_form() const = 0;
41 92
42 std::list<rhyme> get_rhymes() const; 93 return adjectivePosition_;
43 bool starts_with_vowel_sound() const; 94 }
95
96 const notion& getNotion() const;
97
98 const lemma& getLemma() const;
99
100 // Convenience accessors
101
102 std::string getBaseForm() const;
103
104 std::list<std::string> getInflections(inflection infl) const;
105
106 // Type info
107
108 static const object objectType;
109
110 static const std::list<std::string> select;
111
112 // Query fields
113
114 static const field id;
115 static const field tagCount;
116 static const field adjectivePosition;
117
118 operator filter() const
119 {
120 return (id == id_);
121 }
122
123 // Relationships with other objects
124
125 static const field notion;
126 static const field lemma;
127 static const field group;
128
129 // Relationships with self
130
131 static const field antonyms;
132
133 static const field specifications;
134 static const field generalizations;
135
136 static const field pertainyms;
137 static const field antiPertainyms;
138
139 static const field mannernyms;
140 static const field antiMannernyms;
141
142 static const field usageTerms;
143 static const field usageDomains;
144
145 static const field topicalTerms;
146 static const field topicalDomains;
147
148 static const field regionalTerms;
149 static const field regionalDomains;
150
151 private:
152 bool valid_ = false;
153
154 int id_;
155 bool hasTagCount_ = false;
156 int tagCount_;
157 positioning adjectivePosition_ = positioning::undefined;
158 int notionId_;
159 int lemmaId_;
160 bool hasGroup_ = false;
161 int groupId_;
162
163 const database* db_;
164
165 mutable class notion notion_;
166 mutable class lemma lemma_;
167 mutable class group group_;
168
44 }; 169 };
45 170
46}; 171};
47 172
48#endif /* end of include guard: WORD_H_8FC89498 */ 173#endif /* end of include guard: WORD_H_DF91B1B4 */