summary refs log tree commit diff stats
path: root/generator/part.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-01-28 12:59:42 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-01-28 12:59:42 -0500
commita7645346293ed6a912c26d0c50b6f7943f1f3072 (patch)
treed4d144e03a5e2dfcebbad2692fa71e790719d8fd /generator/part.cpp
parent6ba8989bbbd497f949a3e8b17abed1d0bd048347 (diff)
downloadverbly-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 'generator/part.cpp')
-rw-r--r--generator/part.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/generator/part.cpp b/generator/part.cpp index 8a75ed4..07618a8 100644 --- a/generator/part.cpp +++ b/generator/part.cpp
@@ -4,6 +4,8 @@
4namespace verbly { 4namespace verbly {
5 namespace generator { 5 namespace generator {
6 6
7 int part::nextId_ = 0;
8
7 part part::createNounPhrase(std::string role, selrestr selrestrs, std::set<std::string> synrestrs) 9 part part::createNounPhrase(std::string role, selrestr selrestrs, std::set<std::string> synrestrs)
8 { 10 {
9 part p(type::noun_phrase); 11 part p(type::noun_phrase);
@@ -49,9 +51,52 @@ namespace verbly {
49 return p; 51 return p;
50 } 52 }
51 53
54 part part::duplicate(const part& other)
55 {
56 part result(other.type_);
57
58 switch (result.type_)
59 {
60 case type::noun_phrase:
61 {
62 new(&result.noun_phrase_.role) std::string(other.noun_phrase_.role);
63 new(&result.noun_phrase_.selrestrs) selrestr(other.noun_phrase_.selrestrs);
64 new(&result.noun_phrase_.synrestrs) std::set<std::string>(other.noun_phrase_.synrestrs);
65
66 break;
67 }
68
69 case type::preposition:
70 {
71 new(&result.preposition_.choices) std::set<std::string>(other.preposition_.choices);
72 result.preposition_.literal = other.preposition_.literal;
73
74 break;
75 }
76
77 case type::literal:
78 {
79 new(&result.literal_) std::string(other.literal_);
80
81 break;
82 }
83
84 case type::verb:
85 case type::adjective:
86 case type::adverb:
87 case type::invalid:
88 {
89 break;
90 }
91 }
92
93 return result;
94 }
95
52 part::part(const part& other) 96 part::part(const part& other)
53 { 97 {
54 type_ = other.type_; 98 type_ = other.type_;
99 id_ = other.id_;
55 100
56 switch (type_) 101 switch (type_)
57 { 102 {
@@ -106,6 +151,7 @@ namespace verbly {
106 using type = part::type; 151 using type = part::type;
107 152
108 type tempType = first.type_; 153 type tempType = first.type_;
154 int tempId = first.id_;
109 std::string tempRole; 155 std::string tempRole;
110 selrestr tempSelrestrs; 156 selrestr tempSelrestrs;
111 std::set<std::string> tempSynrestrs; 157 std::set<std::string> tempSynrestrs;
@@ -151,6 +197,7 @@ namespace verbly {
151 first.~part(); 197 first.~part();
152 198
153 first.type_ = second.type_; 199 first.type_ = second.type_;
200 first.id_ = second.id_;
154 201
155 switch (first.type_) 202 switch (first.type_)
156 { 203 {
@@ -190,6 +237,7 @@ namespace verbly {
190 second.~part(); 237 second.~part();
191 238
192 second.type_ = tempType; 239 second.type_ = tempType;
240 second.id_ = tempId;
193 241
194 switch (second.type_) 242 switch (second.type_)
195 { 243 {