From 02c187fd3141203024b6f359ec714c0b804583c0 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 19 Mar 2016 14:40:21 -0400 Subject: Nouns with any uppercase letters are now considered proper --- generator/generator.cpp | 12 +++++++++--- generator/schema.sql | 3 ++- lib/noun.cpp | 16 ++++++++++++++-- lib/noun.h | 4 ++++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/generator/generator.cpp b/generator/generator.cpp index faef5f7..de369a4 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "progress.h" struct verb { @@ -525,9 +526,9 @@ int main(int argc, char** argv) { if (nouns.count(word) == 1) { - query = "INSERT INTO nouns (singular, plural) VALUES (?, ?)"; + query = "INSERT INTO nouns (singular, proper, plural) VALUES (?, ?, ?)"; } else { - query = "INSERT INTO nouns (singular) VALUES (?)"; + query = "INSERT INTO nouns (singular, proper) VALUES (?, ?)"; } break; @@ -576,9 +577,14 @@ int main(int argc, char** argv) { case 1: // Noun { + auto sing = nouns[word].singular; + sqlite3_bind_int(ppstmt, 2, (std::any_of(std::begin(sing), std::end(sing), [] (char ch) { + return isupper(ch); + }) ? 1 : 0)); + if (nouns.count(word) == 1) { - sqlite3_bind_text(ppstmt, 2, nouns[word].plural.c_str(), nouns[word].plural.length(), SQLITE_STATIC); + sqlite3_bind_text(ppstmt, 3, nouns[word].plural.c_str(), nouns[word].plural.length(), SQLITE_STATIC); } break; diff --git a/generator/schema.sql b/generator/schema.sql index b4efe0a..8e1e822 100644 --- a/generator/schema.sql +++ b/generator/schema.sql @@ -52,7 +52,8 @@ DROP TABLE IF EXISTS `nouns`; CREATE TABLE `nouns` ( `noun_id` INTEGER PRIMARY KEY, `singular` VARCHAR(32) NOT NULL, - `plural` VARCHAR(32) + `plural` VARCHAR(32), + `proper` INTEGER(1) NOT NULL ); DROP TABLE IF EXISTS `hypernymy`; diff --git a/lib/noun.cpp b/lib/noun.cpp index 43fda2e..81e6613 100644 --- a/lib/noun.cpp +++ b/lib/noun.cpp @@ -330,6 +330,13 @@ namespace verbly { return *this; } + noun_query& noun_query::is_instance(bool _arg) + { + _is_instance = _arg; + + return *this; + } + noun_query& noun_query::instance_of(const noun& _noun) { _instance_of.push_back(_noun); @@ -644,12 +651,17 @@ namespace verbly { if (_is_proper) { - conditions.push_back("noun_id IN (SELECT instance_id FROM instantiation)"); + conditions.push_back("proper = 1"); } if (_is_not_proper) { - conditions.push_back("noun_id NOT IN (SELECT instance_id FROM instantiation)"); + conditions.push_back("proper = 0"); + } + + if (_is_instance) + { + conditions.push_back("noun_id IN (SELECT instance_id FROM instantiation)"); } if (!_instance_of.empty()) diff --git a/lib/noun.h b/lib/noun.h index da76866..fbc2f9e 100644 --- a/lib/noun.h +++ b/lib/noun.h @@ -79,6 +79,8 @@ namespace verbly { noun_query& is_proper(bool _arg); noun_query& is_not_proper(bool _arg); + + noun_query& is_instance(bool _arg); noun_query& instance_of(const noun& _noun); noun_query& not_instance_of(const noun& _noun); @@ -149,6 +151,8 @@ namespace verbly { bool _is_proper = false; bool _is_not_proper = false; + + bool _is_instance = false; std::list _instance_of; std::list _not_instance_of; -- cgit 1.4.1