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. --- generator/generator.cpp | 82 +++++++++++++------------------------------------ 1 file changed, 21 insertions(+), 61 deletions(-) (limited to 'generator/generator.cpp') diff --git a/generator/generator.cpp b/generator/generator.cpp index 4cc9f64..e125b4a 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp @@ -7,7 +7,6 @@ #include #include "../lib/enums.h" #include "progress.h" -#include "../lib/selrestr.h" #include "role.h" #include "part.h" #include "field.h" @@ -1303,12 +1302,20 @@ namespace verbly { std::string roleName = reinterpret_cast(key); xmlFree(key); - selrestr roleSelrestrs; + std::set roleSelrestrs; for (xmlNodePtr rolenode = roletopnode->xmlChildrenNode; rolenode != nullptr; rolenode = rolenode->next) { if (!xmlStrcmp(rolenode->name, reinterpret_cast("SELRESTRS"))) { - roleSelrestrs = parseSelrestr(rolenode); + for (xmlNodePtr selrestrnode = rolenode->xmlChildrenNode; selrestrnode != nullptr; selrestrnode = selrestrnode->next) + { + if (!xmlStrcmp(selrestrnode->name, reinterpret_cast("SELRESTR"))) + { + key = xmlGetProp(selrestrnode, reinterpret_cast("type")); + roleSelrestrs.insert(std::string(reinterpret_cast(key))); + xmlFree(key); + } + } } } @@ -1335,7 +1342,7 @@ namespace verbly { std::string partRole = reinterpret_cast(key); xmlFree(key); - selrestr partSelrestrs; + std::set partSelrestrs; std::set partSynrestrs; for (xmlNodePtr npnode = syntaxnode->xmlChildrenNode; npnode != nullptr; npnode = npnode->next) @@ -1351,11 +1358,17 @@ namespace verbly { xmlFree(key); } } - } - - if (!xmlStrcmp(npnode->name, reinterpret_cast("SELRESTRS"))) + } else if (!xmlStrcmp(npnode->name, reinterpret_cast("SELRESTRS"))) { - partSelrestrs = parseSelrestr(npnode); + for (xmlNodePtr selrestrnode = npnode->xmlChildrenNode; selrestrnode != nullptr; selrestrnode = selrestrnode->next) + { + if (!xmlStrcmp(selrestrnode->name, reinterpret_cast("SELRESTR"))) + { + key = xmlGetProp(selrestrnode, reinterpret_cast("type")); + partSelrestrs.insert(std::string(reinterpret_cast(key))); + xmlFree(key); + } + } } } @@ -1434,58 +1447,5 @@ namespace verbly { } } - selrestr generator::parseSelrestr(xmlNodePtr top) - { - xmlChar* key; - - if (!xmlStrcmp(top->name, reinterpret_cast("SELRESTRS"))) - { - if (xmlChildElementCount(top) == 0) - { - return {}; - } else if (xmlChildElementCount(top) == 1) - { - return parseSelrestr(xmlFirstElementChild(top)); - } else { - bool orlogic = false; - if (xmlHasProp(top, reinterpret_cast("logic"))) - { - key = xmlGetProp(top, reinterpret_cast("logic")); - if (!xmlStrcmp(key, reinterpret_cast("or"))) - { - orlogic = true; - } - - xmlFree(key); - } - - std::list children; - for (xmlNodePtr selrestr = top->xmlChildrenNode; selrestr != nullptr; selrestr = selrestr->next) - { - if (!xmlStrcmp(selrestr->name, reinterpret_cast("SELRESTRS")) - || !xmlStrcmp(selrestr->name, reinterpret_cast("SELRESTR"))) - { - children.push_back(parseSelrestr(selrestr)); - } - } - - return selrestr(children, orlogic); - } - } else if (!xmlStrcmp(top->name, reinterpret_cast("SELRESTR"))) - { - key = xmlGetProp(top, reinterpret_cast("Value")); - bool selPos = (std::string(reinterpret_cast(key)) == "+"); - xmlFree(key); - - key = xmlGetProp(top, reinterpret_cast("type")); - std::string selRestriction = reinterpret_cast(key); - xmlFree(key); - - return selrestr(selRestriction, selPos); - } else { - throw std::logic_error("Badly formatted selrestr"); - } - } - }; }; -- cgit 1.4.1