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/frame.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/frame.h')
-rw-r--r-- | lib/frame.h | 178 |
1 files changed, 69 insertions, 109 deletions
diff --git a/lib/frame.h b/lib/frame.h index fa57e1b..68a4346 100644 --- a/lib/frame.h +++ b/lib/frame.h | |||
@@ -1,118 +1,78 @@ | |||
1 | #ifndef FRAME_H_9A5D90FE | 1 | #ifndef FRAME_H_EA29065A |
2 | #define FRAME_H_9A5D90FE | 2 | #define FRAME_H_EA29065A |
3 | |||
4 | #include <stdexcept> | ||
5 | #include <list> | ||
6 | #include "field.h" | ||
7 | #include "filter.h" | ||
8 | |||
9 | struct sqlite3_stmt; | ||
3 | 10 | ||
4 | namespace verbly { | 11 | namespace verbly { |
5 | 12 | ||
6 | class frame_query; | 13 | class database; |
7 | 14 | ||
8 | class frame { | 15 | class frame { |
9 | public: | 16 | public: |
10 | class selrestr { | 17 | |
11 | public: | 18 | // Default constructor |
12 | enum class type { | 19 | |
13 | empty, | 20 | frame() = default; |
14 | singleton, | 21 | |
15 | group | 22 | // Construct from database |
16 | }; | 23 | |
17 | 24 | frame(const database& db, sqlite3_stmt* row); | |
18 | type get_type() const; | 25 | |
19 | selrestr(const selrestr& other); | 26 | // Accessors |
20 | ~selrestr(); | 27 | |
21 | selrestr& operator=(const selrestr& other); | 28 | operator bool() const |
22 | 29 | { | |
23 | // Empty | 30 | return valid_; |
24 | selrestr(); | 31 | } |
25 | 32 | ||
26 | // Singleton | 33 | int getId() const |
27 | selrestr(std::string restriction, bool pos); | 34 | { |
28 | std::string get_restriction() const; | 35 | if (!valid_) |
29 | bool get_pos() const; | 36 | { |
30 | 37 | throw std::domain_error("Bad access to uninitialized frame"); | |
31 | // Group | 38 | } |
32 | selrestr(std::list<selrestr> children, bool orlogic); | ||
33 | std::list<selrestr> get_children() const; | ||
34 | std::list<selrestr>::const_iterator begin() const; | ||
35 | std::list<selrestr>::const_iterator end() const; | ||
36 | bool get_orlogic() const; | ||
37 | |||
38 | private: | ||
39 | union { | ||
40 | struct { | ||
41 | bool pos; | ||
42 | std::string restriction; | ||
43 | } _singleton; | ||
44 | struct { | ||
45 | std::list<selrestr> children; | ||
46 | bool orlogic; | ||
47 | } _group; | ||
48 | }; | ||
49 | type _type; | ||
50 | }; | ||
51 | 39 | ||
52 | class part { | 40 | return id_; |
53 | public: | 41 | } |
54 | enum class type { | 42 | |
55 | noun_phrase, | 43 | // Type info |
56 | verb, | 44 | |
57 | literal_preposition, | 45 | static const object objectType; |
58 | selection_preposition, | 46 | |
59 | adjective, | 47 | static const std::list<std::string> select; |
60 | adverb, | 48 | |
61 | literal | 49 | // Query fields |
62 | }; | 50 | |
63 | 51 | static const field id; | |
64 | type get_type() const; | 52 | |
65 | part(const part& other); | 53 | operator filter() const |
66 | ~part(); | 54 | { |
67 | 55 | if (!valid_) | |
68 | // Noun phrase | 56 | { |
69 | std::string get_role() const; | 57 | throw std::domain_error("Bad access to uninitialized frame"); |
70 | selrestr get_selrestrs() const; | 58 | } |
71 | std::set<std::string> get_synrestrs() const; | ||
72 | |||
73 | // Literal preposition | ||
74 | std::vector<std::string> get_choices() const; | ||
75 | |||
76 | // Selection preposition | ||
77 | std::vector<std::string> get_preprestrs() const; | ||
78 | |||
79 | // Literal | ||
80 | std::string get_literal() const; | ||
81 | |||
82 | private: | ||
83 | friend class frame_query; | ||
84 | |||
85 | part(); | ||
86 | |||
87 | union { | ||
88 | struct { | ||
89 | std::string role; | ||
90 | selrestr selrestrs; | ||
91 | std::set<std::string> synrestrs; | ||
92 | } _noun_phrase; | ||
93 | struct { | ||
94 | std::vector<std::string> choices; | ||
95 | } _literal_preposition; | ||
96 | struct { | ||
97 | std::vector<std::string> preprestrs; | ||
98 | } _selection_preposition; | ||
99 | struct { | ||
100 | std::string lexval; | ||
101 | } _literal; | ||
102 | }; | ||
103 | type _type; | ||
104 | }; | ||
105 | 59 | ||
106 | std::vector<part> parts() const; | 60 | return (id == id_); |
107 | std::map<std::string, selrestr> roles() const; | 61 | } |
108 | 62 | ||
109 | private: | 63 | // Relationships to other objects |
110 | friend class frame_query; | 64 | |
111 | 65 | static const field group; | |
112 | std::vector<part> _parts; | 66 | |
113 | std::map<std::string, selrestr> _roles; | 67 | private: |
68 | bool valid_ = false; | ||
69 | |||
70 | int id_; | ||
71 | |||
72 | const database* db_; | ||
73 | |||
114 | }; | 74 | }; |
115 | 75 | ||
116 | }; | 76 | }; |
117 | 77 | ||
118 | #endif /* end of include guard: FRAME_H_9A5D90FE */ | 78 | #endif /* end of include guard: FRAME_H_EA29065A */ |