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/pronunciation.h | |
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/pronunciation.h')
-rw-r--r-- | lib/pronunciation.h | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/lib/pronunciation.h b/lib/pronunciation.h new file mode 100644 index 0000000..c7a1d4d --- /dev/null +++ b/lib/pronunciation.h | |||
@@ -0,0 +1,163 @@ | |||
1 | #ifndef PRONUNCIATION_H_C68F86B0 | ||
2 | #define PRONUNCIATION_H_C68F86B0 | ||
3 | |||
4 | #include <stdexcept> | ||
5 | #include <vector> | ||
6 | #include <string> | ||
7 | #include "field.h" | ||
8 | #include "filter.h" | ||
9 | |||
10 | struct sqlite3_stmt; | ||
11 | |||
12 | namespace verbly { | ||
13 | |||
14 | class form; | ||
15 | class lemma; | ||
16 | class word; | ||
17 | class database; | ||
18 | |||
19 | class pronunciation { | ||
20 | public: | ||
21 | |||
22 | // Default constructor | ||
23 | |||
24 | pronunciation() = default; | ||
25 | |||
26 | // Construct from database | ||
27 | |||
28 | pronunciation(const database& db, sqlite3_stmt* row); | ||
29 | |||
30 | // Accessors | ||
31 | |||
32 | operator bool() const | ||
33 | { | ||
34 | return valid_; | ||
35 | } | ||
36 | |||
37 | int getId() const | ||
38 | { | ||
39 | if (!valid_) | ||
40 | { | ||
41 | throw std::domain_error("Bad access to uninitialized pronunciation"); | ||
42 | } | ||
43 | |||
44 | return id_; | ||
45 | } | ||
46 | |||
47 | const std::vector<std::string>& getPhonemes() const | ||
48 | { | ||
49 | if (!valid_) | ||
50 | { | ||
51 | throw std::domain_error("Bad access to uninitialized pronunciation"); | ||
52 | } | ||
53 | |||
54 | return phonemes_; | ||
55 | } | ||
56 | |||
57 | int getSyllables() const | ||
58 | { | ||
59 | if (!valid_) | ||
60 | { | ||
61 | throw std::domain_error("Bad access to uninitialized pronunciation"); | ||
62 | } | ||
63 | |||
64 | return syllables_; | ||
65 | } | ||
66 | |||
67 | std::string getStress() const | ||
68 | { | ||
69 | if (!valid_) | ||
70 | { | ||
71 | throw std::domain_error("Bad access to uninitialized pronunciation"); | ||
72 | } | ||
73 | |||
74 | return stress_; | ||
75 | } | ||
76 | |||
77 | bool hasRhyme() const | ||
78 | { | ||
79 | if (!valid_) | ||
80 | { | ||
81 | throw std::domain_error("Bad access to uninitialized pronunciation"); | ||
82 | } | ||
83 | |||
84 | return hasRhyme_; | ||
85 | } | ||
86 | |||
87 | std::string getPrerhyme() const | ||
88 | { | ||
89 | if (!valid_) | ||
90 | { | ||
91 | throw std::domain_error("Bad access to uninitialized pronunciation"); | ||
92 | } | ||
93 | |||
94 | if (!hasRhyme_) | ||
95 | { | ||
96 | throw std::domain_error("This pronunciation has no rhyme"); | ||
97 | } | ||
98 | |||
99 | return prerhyme_; | ||
100 | } | ||
101 | |||
102 | std::string getRhyme() const | ||
103 | { | ||
104 | if (!valid_) | ||
105 | { | ||
106 | throw std::domain_error("Bad access to uninitialized pronunciation"); | ||
107 | } | ||
108 | |||
109 | if (!hasRhyme_) | ||
110 | { | ||
111 | throw std::domain_error("This pronunciation has no rhyme"); | ||
112 | } | ||
113 | |||
114 | return rhyme_; | ||
115 | } | ||
116 | |||
117 | // Type info | ||
118 | |||
119 | static const object objectType; | ||
120 | |||
121 | static const std::list<std::string> select; | ||
122 | |||
123 | // Query fields | ||
124 | |||
125 | static const field id; | ||
126 | static const field numOfSyllables; | ||
127 | static const field stress; | ||
128 | |||
129 | operator filter() const | ||
130 | { | ||
131 | return (id == id_); | ||
132 | } | ||
133 | |||
134 | static filter rhymesWith(const pronunciation& arg); | ||
135 | static filter rhymesWith(const class form& arg); | ||
136 | static filter rhymesWith(const lemma& arg); | ||
137 | static filter rhymesWith(const word& arg); | ||
138 | |||
139 | // Relationships to other objects | ||
140 | |||
141 | static const field form; | ||
142 | |||
143 | private: | ||
144 | bool valid_ = false; | ||
145 | |||
146 | int id_; | ||
147 | std::vector<std::string> phonemes_; | ||
148 | int syllables_; | ||
149 | std::string stress_; | ||
150 | bool hasRhyme_ = false; | ||
151 | std::string prerhyme_; | ||
152 | std::string rhyme_; | ||
153 | |||
154 | const database* db_; | ||
155 | |||
156 | static const field prerhyme; | ||
157 | static const field rhyme; | ||
158 | |||
159 | }; | ||
160 | |||
161 | }; | ||
162 | |||
163 | #endif /* end of include guard: PRONUNCIATION_H_C68F86B0 */ | ||