From e4fa0cb86d97c23c24cd7bdd62c23f03eed312da Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 5 Feb 2017 08:56:39 -0500 Subject: 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. --- lib/part.cpp | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'lib/part.cpp') diff --git a/lib/part.cpp b/lib/part.cpp index cbd951b..341d4bb 100644 --- a/lib/part.cpp +++ b/lib/part.cpp @@ -1,14 +1,14 @@ #include "part.h" #include #include -#include "selrestr.h" #include "database.h" +#include "util.h" namespace verbly { const object part::objectType = object::part; - const std::list part::select = {"part_id", "frame_id", "part_index", "type", "role", "selrestrs", "prepositions", "preposition_literality", "literal_value"}; + const std::list part::select = {"part_id", "frame_id", "part_index", "type", "role", "prepositions", "preposition_literality", "literal_value"}; const field part::index = field::integerField(object::part, "part_index"); const field part::type = field::integerField(object::part, "type"); @@ -17,17 +17,21 @@ namespace verbly { const field part::frames = field::joinField(object::part, "frame_id", object::frame); + const field part::selrestr_field::selrestrJoin = field::joinField(object::part, "part_id", "selrestrs"); + const field part::selrestr_field::selrestrField = field::stringField("selrestrs", "selrestr"); + const field part::synrestr_field::synrestrJoin = field::joinField(object::part, "part_id", "synrestrs"); const field part::synrestr_field::synrestrField = field::stringField("synrestrs", "synrestr"); + const part::selrestr_field part::selrestrs = {}; const part::synrestr_field part::synrestrs = {}; - part part::createNounPhrase(std::string role, selrestr selrestrs, std::set synrestrs) + part part::createNounPhrase(std::string role, std::set selrestrs, std::set synrestrs) { part p(part_type::noun_phrase); new(&p.noun_phrase_.role) std::string(std::move(role)); - new(&p.noun_phrase_.selrestrs) selrestr(std::move(selrestrs)); + new(&p.noun_phrase_.selrestrs) std::set(std::move(selrestrs)); new(&p.noun_phrase_.synrestrs) std::set(std::move(synrestrs)); return p; @@ -78,7 +82,7 @@ namespace verbly { case part_type::noun_phrase: { new(&noun_phrase_.role) std::string(reinterpret_cast(sqlite3_column_blob(row, 4))); - new(&noun_phrase_.selrestrs) selrestr(nlohmann::json::parse(reinterpret_cast(sqlite3_column_blob(row, 5)))); + new(&noun_phrase_.selrestrs) std::set(db.selrestrs(id)); new(&noun_phrase_.synrestrs) std::set(db.synrestrs(id)); break; @@ -86,22 +90,17 @@ namespace verbly { case part_type::preposition: { - new(&preposition_.choices) std::vector(); - preposition_.literal = (sqlite3_column_int(row, 7) == 1); - - std::string choicesJsonStr(reinterpret_cast(sqlite3_column_blob(row, 6))); - nlohmann::json choicesJson = nlohmann::json::parse(std::move(choicesJsonStr)); - for (const nlohmann::json& choiceJson : choicesJson) - { - preposition_.choices.push_back(choiceJson.get()); - } + std::string serializedChoices(reinterpret_cast(sqlite3_column_blob(row, 5))); + new(&preposition_.choices) std::vector(split>(serializedChoices, ",")); + + preposition_.literal = (sqlite3_column_int(row, 6) == 1); break; } case part_type::literal: { - new(&literal_) std::string(reinterpret_cast(sqlite3_column_blob(row, 8))); + new(&literal_) std::string(reinterpret_cast(sqlite3_column_blob(row, 7))); break; } @@ -125,7 +124,7 @@ namespace verbly { case part_type::noun_phrase: { new(&noun_phrase_.role) std::string(other.noun_phrase_.role); - new(&noun_phrase_.selrestrs) selrestr(other.noun_phrase_.selrestrs); + new(&noun_phrase_.selrestrs) std::set(other.noun_phrase_.selrestrs); new(&noun_phrase_.synrestrs) std::set(other.noun_phrase_.synrestrs); break; @@ -174,7 +173,7 @@ namespace verbly { type tempType = first.type_; std::string tempRole; - selrestr tempSelrestrs; + std::set tempSelrestrs; std::set tempSynrestrs; std::vector tempChoices; bool tempPrepLiteral; @@ -224,7 +223,7 @@ namespace verbly { case type::noun_phrase: { new(&first.noun_phrase_.role) std::string(std::move(second.noun_phrase_.role)); - new(&first.noun_phrase_.selrestrs) selrestr(std::move(second.noun_phrase_.selrestrs)); + new(&first.noun_phrase_.selrestrs) std::set(std::move(second.noun_phrase_.selrestrs)); new(&first.noun_phrase_.synrestrs) std::set(std::move(second.noun_phrase_.synrestrs)); break; @@ -263,7 +262,7 @@ namespace verbly { case type::noun_phrase: { new(&second.noun_phrase_.role) std::string(std::move(tempRole)); - new(&second.noun_phrase_.selrestrs) selrestr(std::move(tempSelrestrs)); + new(&second.noun_phrase_.selrestrs) std::set(std::move(tempSelrestrs)); new(&second.noun_phrase_.synrestrs) std::set(std::move(tempSynrestrs)); break; @@ -304,7 +303,7 @@ namespace verbly { using set_type = std::set; noun_phrase_.role.~string_type(); - noun_phrase_.selrestrs.~selrestr(); + noun_phrase_.selrestrs.~set_type(); noun_phrase_.synrestrs.~set_type(); break; @@ -348,7 +347,7 @@ namespace verbly { } } - selrestr part::getNounSelrestrs() const + std::set part::getNounSelrestrs() const { if (type_ == part_type::noun_phrase) { -- cgit 1.4.1