diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-28 12:59:42 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-28 12:59:42 -0500 |
commit | a7645346293ed6a912c26d0c50b6f7943f1f3072 (patch) | |
tree | d4d144e03a5e2dfcebbad2692fa71e790719d8fd /lib/part.h | |
parent | 6ba8989bbbd497f949a3e8b17abed1d0bd048347 (diff) | |
download | verbly-a7645346293ed6a912c26d0c50b6f7943f1f3072.tar.gz verbly-a7645346293ed6a912c26d0c50b6f7943f1f3072.tar.bz2 verbly-a7645346293ed6a912c26d0c50b6f7943f1f3072.zip |
Restructured verb frame schema to be more queryable
Groups are much less significant now, and they no longer have a database table, nor are they considered a top level object anymore. Instead of containing their own role data, that data is folded into the frames so that it's easier to query; as a result, each group has its own copy of the frames that it contains. Additionally, parts are considered top level objects now, and you can query for frames based on attributes of their indexed parts. Synrestrs are also contained in their own table now, so that parts can be filtered against their synrestrs; they are however not considered top level objects. Created a new type of field, the "join where" or "condition join" field, which is a normal join field that has a built in condition on a specified field. This is used to allow creating multiple distinct join fields from one object to another. This is required for the lemma::form and frame::part joins, because filters for forms of separate inflections should not be coalesced; similarly, filters on differently indexed frame parts should not be coalesced. Queries can now be ordered, ascending or descending, by a field, in addition to randomly as before. This is necessary for accessing the parts of a verb frame in the correct order, but may be useful to an end user as well. Fixed a bug with statement generation in that condition groups were not being surrounded in parentheses, which made mixing OR groups and AND groups generate inaccurate statements. This has been fixed; additionally, parentheses are not placed around the top level condition, and nested condition groups with the same logic type are coalesced, to make query strings as easy to read as possible. Also simplified the form::lemma field; it no longer conditions on the inflection of the form like the lemma::form field does. Also added a debug flag to statement::getQueryString that makes it return a query string with all of the bindings filled in, for debug use only.
Diffstat (limited to 'lib/part.h')
-rw-r--r-- | lib/part.h | 64 |
1 files changed, 52 insertions, 12 deletions
diff --git a/lib/part.h b/lib/part.h index 3a15638..9a01312 100644 --- a/lib/part.h +++ b/lib/part.h | |||
@@ -4,21 +4,20 @@ | |||
4 | #include <string> | 4 | #include <string> |
5 | #include <vector> | 5 | #include <vector> |
6 | #include <set> | 6 | #include <set> |
7 | #include <list> | ||
7 | #include "selrestr.h" | 8 | #include "selrestr.h" |
9 | #include "field.h" | ||
10 | #include "filter.h" | ||
11 | #include "enums.h" | ||
12 | |||
13 | struct sqlite3_stmt; | ||
8 | 14 | ||
9 | namespace verbly { | 15 | namespace verbly { |
10 | 16 | ||
17 | class database; | ||
18 | |||
11 | class part { | 19 | class part { |
12 | public: | 20 | public: |
13 | enum class type { | ||
14 | invalid = -1, | ||
15 | noun_phrase = 0, | ||
16 | verb = 1, | ||
17 | preposition = 2, | ||
18 | adjective = 3, | ||
19 | adverb = 4, | ||
20 | literal = 5 | ||
21 | }; | ||
22 | 21 | ||
23 | // Static factories | 22 | // Static factories |
24 | 23 | ||
@@ -40,6 +39,10 @@ namespace verbly { | |||
40 | { | 39 | { |
41 | } | 40 | } |
42 | 41 | ||
42 | // Construct from database | ||
43 | |||
44 | part(const database& db, sqlite3_stmt* row); | ||
45 | |||
43 | // Copy and move constructors | 46 | // Copy and move constructors |
44 | 47 | ||
45 | part(const part& other); | 48 | part(const part& other); |
@@ -60,7 +63,12 @@ namespace verbly { | |||
60 | 63 | ||
61 | // General accessors | 64 | // General accessors |
62 | 65 | ||
63 | type getType() const | 66 | operator bool() const |
67 | { | ||
68 | return (type_ != part_type::invalid); | ||
69 | } | ||
70 | |||
71 | part_type getType() const | ||
64 | { | 72 | { |
65 | return type_; | 73 | return type_; |
66 | } | 74 | } |
@@ -85,11 +93,43 @@ namespace verbly { | |||
85 | 93 | ||
86 | std::string getLiteralValue() const; | 94 | std::string getLiteralValue() const; |
87 | 95 | ||
96 | // Type info | ||
97 | |||
98 | static const object objectType; | ||
99 | |||
100 | static const std::list<std::string> select; | ||
101 | |||
102 | // Query fields | ||
103 | |||
104 | static const field index; | ||
105 | static const field type; | ||
106 | |||
107 | static const field role; | ||
108 | |||
109 | // Relationships to other objects | ||
110 | |||
111 | static const field frame; | ||
112 | |||
113 | // Noun synrestr relationship | ||
114 | |||
115 | class synrestr_field { | ||
116 | public: | ||
117 | |||
118 | filter operator%=(std::string synrestr) const; | ||
119 | |||
120 | private: | ||
121 | |||
122 | static const field synrestrJoin; | ||
123 | static const field synrestrField; | ||
124 | }; | ||
125 | |||
126 | static const synrestr_field synrestr; | ||
127 | |||
88 | private: | 128 | private: |
89 | 129 | ||
90 | // Private constructors | 130 | // Private constructors |
91 | 131 | ||
92 | part(type t) : type_(t) | 132 | part(part_type t) : type_(t) |
93 | { | 133 | { |
94 | } | 134 | } |
95 | 135 | ||
@@ -108,7 +148,7 @@ namespace verbly { | |||
108 | std::string literal_; | 148 | std::string literal_; |
109 | }; | 149 | }; |
110 | 150 | ||
111 | type type_ = type::invalid; | 151 | part_type type_ = part_type::invalid; |
112 | 152 | ||
113 | }; | 153 | }; |
114 | 154 | ||