summary refs log tree commit diff stats
path: root/generator/group.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-02-05 08:56:39 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-02-05 08:56:39 -0500
commite4fa0cb86d97c23c24cd7bdd62c23f03eed312da (patch)
tree70a20fdf684b1724659196a7de8d21a4a6ca194f /generator/group.cpp
parentbea3673ae1b3d19585dec56e96dbcd8a56b96e6d (diff)
downloadverbly-e4fa0cb86d97c23c24cd7bdd62c23f03eed312da.tar.gz
verbly-e4fa0cb86d97c23c24cd7bdd62c23f03eed312da.tar.bz2
verbly-e4fa0cb86d97c23c24cd7bdd62c23f03eed312da.zip
Flattened selrestrs
Now, selrestrs are, instead of logically being a tree of
positive/negative restrictions that are ANDed/ORed together, they are a
flat set of positive restrictions that are ORed together. They are
stored as strings in a table called selrestrs, just like synrestrs,
which makes them a lot more queryable now as well. This change required
some changes to the VerbNet data, because we needed to consolidate any
ANDed clauses into single selrestrs, as well as convert any negative
selrestrs into positive ones. The changes made are detailed on the wiki.

Preposition choices are now encoded as comma-separated lists instead of
using JSON. This change, along with the selrestrs one, allows us to
remove verbly's dependency on nlohmann::json.
Diffstat (limited to 'generator/group.cpp')
-rw-r--r--generator/group.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/generator/group.cpp b/generator/group.cpp index aa28d42..5b23578 100644 --- a/generator/group.cpp +++ b/generator/group.cpp
@@ -1,10 +1,10 @@
1#include "group.h" 1#include "group.h"
2#include <stdexcept> 2#include <stdexcept>
3#include <list> 3#include <list>
4#include <json.hpp>
5#include "database.h" 4#include "database.h"
6#include "field.h" 5#include "field.h"
7#include "frame.h" 6#include "frame.h"
7#include "../lib/util.h"
8 8
9namespace verbly { 9namespace verbly {
10 namespace generator { 10 namespace generator {
@@ -83,16 +83,22 @@ namespace verbly {
83 { 83 {
84 fields.emplace_back("role", p.getNounRole()); 84 fields.emplace_back("role", p.getNounRole());
85 85
86 selrestr partSelrestr; 86 // Short interlude to serialize the selrestrs
87 if (p.getNounSelrestrs().getType() != selrestr::type::empty) 87 std::set<std::string> partSelrestrs = p.getNounSelrestrs();
88 if (partSelrestrs.empty() && arg.hasRole(p.getNounRole()))
88 { 89 {
89 partSelrestr = p.getNounSelrestrs(); 90 partSelrestrs = arg.getRole(p.getNounRole()).getSelrestrs();
90 } else if (arg.hasRole(p.getNounRole()))
91 {
92 partSelrestr = arg.getRole(p.getNounRole()).getSelrestrs();
93 } 91 }
94 92
95 fields.emplace_back("selrestrs", partSelrestr.toJson().dump()); 93 for (const std::string& s : partSelrestrs)
94 {
95 std::list<field> selrestrFields;
96
97 selrestrFields.emplace_back("part_id", p.getId());
98 selrestrFields.emplace_back("selrestr", s);
99
100 db.insertIntoTable("selrestrs", std::move(selrestrFields));
101 }
96 102
97 // Short interlude to serialize the synrestrs 103 // Short interlude to serialize the synrestrs
98 for (const std::string& s : p.getNounSynrestrs()) 104 for (const std::string& s : p.getNounSynrestrs())
@@ -110,7 +116,10 @@ namespace verbly {
110 116
111 case part::type::preposition: 117 case part::type::preposition:
112 { 118 {
113 fields.emplace_back("prepositions", nlohmann::json(p.getPrepositionChoices()).dump()); 119 std::set<std::string> setChoices = p.getPrepositionChoices();
120 std::string serializedChoices = implode(std::begin(setChoices), std::end(setChoices), ",");
121
122 fields.emplace_back("prepositions", std::move(serializedChoices));
114 fields.emplace_back("preposition_literality", p.isPrepositionLiteral() ? 1 : 0); 123 fields.emplace_back("preposition_literality", p.isPrepositionLiteral() ? 1 : 0);
115 124
116 break; 125 break;