From e1fa4a088dd95caef22045f905a9d5d22b71bef0 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 24 Jan 2017 21:50:39 -0500 Subject: Whitespace changes --- generator/database.cpp | 14 +++--- generator/database.h | 2 +- generator/field.h | 12 ++--- generator/frame.h | 38 +++++++------- generator/generator.h | 108 +++++++++++++++++++-------------------- generator/group.cpp | 46 ++++++++--------- generator/group.h | 52 +++++++++---------- generator/main.cpp | 2 +- generator/notion.cpp | 14 +++--- generator/notion.h | 8 +-- generator/part.cpp | 134 ++++++++++++++++++++++++------------------------- generator/part.h | 74 +++++++++++++-------------- generator/progress.h | 16 +++--- generator/word.cpp | 8 +-- generator/word.h | 10 ++-- 15 files changed, 269 insertions(+), 269 deletions(-) (limited to 'generator') diff --git a/generator/database.cpp b/generator/database.cpp index c7e4cfa..188fa2a 100644 --- a/generator/database.cpp +++ b/generator/database.cpp @@ -73,19 +73,19 @@ namespace verbly { { sqlite3_close_v2(ppdb_); } - + void database::runQuery(std::string query) { // This can only happen when doing bad things with move semantics. assert(ppdb_ != nullptr); - + sqlite3_stmt* ppstmt; if (sqlite3_prepare_v2(ppdb_, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK) { throw sqlite3_error("Error writing to database", sqlite3_errmsg(ppdb_)); } - + int result = sqlite3_step(ppstmt); sqlite3_finalize(ppstmt); @@ -99,10 +99,10 @@ namespace verbly { { // This can only happen when doing bad things with move semantics. assert(ppdb_ != nullptr); - + // This shouldn't happen. assert(!fields.empty()); - + std::list fieldNames; std::list qs; for (field& f : fields) @@ -110,7 +110,7 @@ namespace verbly { fieldNames.push_back(f.getName()); qs.push_back("?"); } - + std::ostringstream query; query << "INSERT INTO "; query << table; @@ -119,7 +119,7 @@ namespace verbly { query << ") VALUES ("; query << implode(std::begin(qs), std::end(qs), ", "); query << ")"; - + std::string query_str = query.str(); sqlite3_stmt* ppstmt; diff --git a/generator/database.h b/generator/database.h index 15cdff5..7906304 100644 --- a/generator/database.h +++ b/generator/database.h @@ -52,7 +52,7 @@ namespace verbly { ~database(); // Actions - + void runQuery(std::string query); void insertIntoTable(std::string table, std::list fields); diff --git a/generator/field.h b/generator/field.h index 1fbabfc..aaca3fa 100644 --- a/generator/field.h +++ b/generator/field.h @@ -32,27 +32,27 @@ namespace verbly { ~field(); // Generic accessors - + type getType() const { return type_; } - + std::string getName() const { return name_; } // Integer - + field(std::string name, int arg); - + int getInteger() const; // String - + field(std::string name, std::string arg); - + std::string getString() const; private: diff --git a/generator/frame.h b/generator/frame.h index 411ce6c..764564d 100644 --- a/generator/frame.h +++ b/generator/frame.h @@ -6,53 +6,53 @@ namespace verbly { namespace generator { - + class database; - + class frame { public: - + // Aliases - + using const_iterator = std::list::const_iterator; - + // Constructor - + frame(); - + // Mutators - + void push_back(part fp); - + // Accessors - + int getId() const { return id_; } - + const_iterator begin() const { return std::begin(parts_); } - + const_iterator end() const { return std::end(parts_); } - + private: - + static int nextId_; - + const int id_; - + std::list parts_; - + }; - + database& operator<<(database& db, const frame& arg); - + }; }; diff --git a/generator/generator.h b/generator/generator.h index c829c21..8352693 100644 --- a/generator/generator.h +++ b/generator/generator.h @@ -16,17 +16,17 @@ #include "frame.h" namespace verbly { - + enum class part_of_speech; class selrestr; - + namespace generator { - + class generator { public: - + // Constructor - + generator( std::string verbNetPath, std::string agidPath, @@ -34,95 +34,95 @@ namespace verbly { std::string cmudictPath, std::string imageNetPath, std::string outputPath); - + // Action - + void run(); - + private: - + // Subroutines - + void readWordNetSynsets(); - + void readAdjectivePositioning(); - + void readImageNetUrls(); - + void readWordNetSenseKeys(); - + void readVerbNet(); - + void readAgidInflections(); - + void readPrepositions(); - + void readCmudictPronunciations(); - + void writeSchema(); - + void dumpObjects(); - + void readWordNetAntonymy(); - + void readWordNetVariation(); - + void readWordNetClasses(); - + void readWordNetCausality(); - + void readWordNetEntailment(); - + void readWordNetHypernymy(); - + void readWordNetInstantiation(); - + void readWordNetMemberMeronymy(); - + void readWordNetPartMeronymy(); - + void readWordNetSubstanceMeronymy(); - + void readWordNetPertainymy(); - + void readWordNetSpecification(); - + void readWordNetSimilarity(); - + // Helpers - + std::list readFile(std::string path); - + inline part_of_speech partOfSpeechByWnid(int wnid); - + notion& createNotion(part_of_speech partOfSpeech); - + notion& lookupOrCreateNotion(int wnid); - + lemma& lookupOrCreateLemma(std::string base_form); - + form& lookupOrCreateForm(std::string text); - + template word& createWord(Args&&... args); - + group& createGroup(xmlNodePtr top); - + selrestr parseSelrestr(xmlNodePtr top); - + // Input - + std::string verbNetPath_; std::string agidPath_; std::string wordNetPath_; std::string cmudictPath_; std::string imageNetPath_; - + // Output - + database db_; - + // Data - + std::list notions_; std::list words_; std::list lemmas_; @@ -130,22 +130,22 @@ namespace verbly { std::list pronunciations_; std::list frames_; std::list groups_; - + // Indexes - + std::map notionByWnid_; std::map> wordsByWnid_; std::map, word*> wordByWnidAndWnum_; std::map> wordsByBaseForm_; std::map lemmaByBaseForm_; std::map formByText_; - + // Caches - + std::map wnSenseKeys_; - + }; - + }; }; diff --git a/generator/group.cpp b/generator/group.cpp index 334c2aa..cebe2b9 100644 --- a/generator/group.cpp +++ b/generator/group.cpp @@ -8,37 +8,37 @@ namespace verbly { namespace generator { - + int group::nextId_ = 0; - + group::group() : id_(nextId_++) { } - + void group::setParent(const group& parent) { // Adding a group to itself is nonsensical. assert(&parent != this); - + parent_ = &parent; } - + void group::addRole(role r) { std::string name = r.getName(); roles_[name] = std::move(r); roleNames_.insert(std::move(name)); } - + void group::addFrame(const frame& f) { frames_.insert(&f); } - + std::set group::getRoles() const { std::set fullRoles = roleNames_; - + if (hasParent()) { for (std::string name : getParent().getRoles()) @@ -46,10 +46,10 @@ namespace verbly { fullRoles.insert(name); } } - + return fullRoles; } - + const role& group::getRole(std::string name) const { if (roles_.count(name)) @@ -62,11 +62,11 @@ namespace verbly { throw std::invalid_argument("Specified role not found in verb group"); } } - + std::set group::getFrames() const { std::set fullFrames = frames_; - + if (hasParent()) { for (const frame* f : getParent().getFrames()) @@ -74,47 +74,47 @@ namespace verbly { fullFrames.insert(f); } } - + return fullFrames; } - + database& operator<<(database& db, const group& arg) { // Serialize the group first { std::list fields; fields.emplace_back("group_id", arg.getId()); - + nlohmann::json jsonRoles; for (std::string name : arg.getRoles()) { const role& r = arg.getRole(name); - + nlohmann::json jsonRole; jsonRole["type"] = name; jsonRole["selrestrs"] = r.getSelrestrs().toJson(); - + jsonRoles.emplace_back(std::move(jsonRole)); } fields.emplace_back("data", jsonRoles.dump()); - + db.insertIntoTable("groups", std::move(fields)); } - + // Then, serialize the group/frame relationship for (const frame* f : arg.getFrames()) { std::list fields; - + fields.emplace_back("group_id", arg.getId()); fields.emplace_back("frame_id", f->getId()); - + db.insertIntoTable("groups_frames", std::move(fields)); } - + return db; } - + }; }; diff --git a/generator/group.h b/generator/group.h index 5084ea4..83f40c2 100644 --- a/generator/group.h +++ b/generator/group.h @@ -9,71 +9,71 @@ namespace verbly { namespace generator { - + class frame; class database; - + class group { public: - + // Constructor - + group(); - + // Mutators - + void setParent(const group& parent); - + void addRole(role r); - + void addFrame(const frame& f); - + // Accessors - + int getId() const { return id_; } - + bool hasParent() const { return (parent_ != nullptr); } - + const group& getParent() const { // Calling code should always call hasParent first assert(parent_ != nullptr); - + return *parent_; } - + std::set getRoles() const; - + const role& getRole(std::string name) const; - + std::set getFrames() const; - + private: - + static int nextId_; - + const int id_; - + const group* parent_ = nullptr; std::map roles_; std::set frames_; - + // Caches - + std::set roleNames_; - + }; - + // Serializer - + database& operator<<(database& db, const group& arg); - + }; }; diff --git a/generator/main.cpp b/generator/main.cpp index 827c963..1b07706 100644 --- a/generator/main.cpp +++ b/generator/main.cpp @@ -20,7 +20,7 @@ int main(int argc, char** argv) try { verbly::generator::generator app(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); - + try { app.run(); diff --git a/generator/notion.cpp b/generator/notion.cpp index 290d982..1878ba9 100644 --- a/generator/notion.cpp +++ b/generator/notion.cpp @@ -30,15 +30,15 @@ namespace verbly { { // Calling code should always call hasWnid and check that the notion is a noun first. assert(hasWnid_ && (partOfSpeech_ == part_of_speech::noun)); - + numOfImages_++; } - + void notion::setPrepositionGroups(std::list groups) { // Calling code should always check that the notion is a preposition first. assert(partOfSpeech_ == part_of_speech::preposition); - + prepositionGroups_ = groups; } @@ -54,7 +54,7 @@ namespace verbly { if (arg.hasWnid()) { fields.emplace_back("wnid", arg.getWnid()); - + if (arg.getPartOfSpeech() == part_of_speech::noun) { fields.emplace_back("images", arg.getNumOfImages()); @@ -63,17 +63,17 @@ namespace verbly { db.insertIntoTable("notions", std::move(fields)); } - + // Next, serialize the is_a relationship if this is a preposition if (arg.getPartOfSpeech() == part_of_speech::preposition) { for (std::string group : arg.getPrepositionGroups()) { std::list fields; - + fields.emplace_back("notion_id", arg.getId()); fields.emplace_back("groupname", group); - + db.insertIntoTable("is_a", std::move(fields)); } } diff --git a/generator/notion.h b/generator/notion.h index cc64c48..6e38497 100644 --- a/generator/notion.h +++ b/generator/notion.h @@ -23,7 +23,7 @@ namespace verbly { // Mutators void incrementNumOfImages(); - + void setPrepositionGroups(std::list groups); // Accessors @@ -37,7 +37,7 @@ namespace verbly { { return partOfSpeech_; } - + bool hasWnid() const { return hasWnid_; @@ -58,12 +58,12 @@ namespace verbly { return numOfImages_; } - + std::list getPrepositionGroups() const { // Calling code should always check that the notion is a preposition first. assert(partOfSpeech_ == part_of_speech::preposition); - + return prepositionGroups_; } diff --git a/generator/part.cpp b/generator/part.cpp index b69ec65..8a75ed4 100644 --- a/generator/part.cpp +++ b/generator/part.cpp @@ -3,56 +3,56 @@ namespace verbly { namespace generator { - + part part::createNounPhrase(std::string role, selrestr selrestrs, std::set synrestrs) { part p(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_.synrestrs) std::set(std::move(synrestrs)); - + return p; } - + part part::createVerb() { return part(type::verb); } - + part part::createPreposition(std::set choices, bool literal) { part p(type::preposition); - + new(&p.preposition_.choices) std::set(std::move(choices)); p.preposition_.literal = literal; - + return p; } - + part part::createAdjective() { return part(type::adjective); } - + part part::createAdverb() { return part(type::adverb); } - + part part::createLiteral(std::string value) { part p(type::literal); - + new(&p.literal_) std::string(std::move(value)); - + return p; } - + part::part(const part& other) { type_ = other.type_; - + switch (type_) { case type::noun_phrase: @@ -60,25 +60,25 @@ namespace verbly { new(&noun_phrase_.role) std::string(other.noun_phrase_.role); new(&noun_phrase_.selrestrs) selrestr(other.noun_phrase_.selrestrs); new(&noun_phrase_.synrestrs) std::set(other.noun_phrase_.synrestrs); - + break; } - + case type::preposition: { new(&preposition_.choices) std::set(other.preposition_.choices); preposition_.literal = other.preposition_.literal; - + break; } - + case type::literal: { new(&literal_) std::string(other.literal_); - + break; } - + case type::verb: case type::adjective: case type::adverb: @@ -88,23 +88,23 @@ namespace verbly { } } } - + part::part(part&& other) : part() { swap(*this, other); } - + part& part::operator=(part other) { swap(*this, other); - + return *this; } - + void swap(part& first, part& second) { using type = part::type; - + type tempType = first.type_; std::string tempRole; selrestr tempSelrestrs; @@ -112,7 +112,7 @@ namespace verbly { std::set tempChoices; bool tempPrepLiteral; std::string tempLiteralValue; - + switch (tempType) { case type::noun_phrase: @@ -120,25 +120,25 @@ namespace verbly { tempRole = std::move(first.noun_phrase_.role); tempSelrestrs = std::move(first.noun_phrase_.selrestrs); tempSynrestrs = std::move(first.noun_phrase_.synrestrs); - + break; } - + case type::preposition: { tempChoices = std::move(first.preposition_.choices); tempPrepLiteral = first.preposition_.literal; - + break; } - + case type::literal: { tempLiteralValue = std::move(first.literal_); - + break; } - + case type::verb: case type::adjective: case type::adverb: @@ -147,11 +147,11 @@ namespace verbly { break; } } - + first.~part(); - + first.type_ = second.type_; - + switch (first.type_) { case type::noun_phrase: @@ -159,25 +159,25 @@ namespace verbly { 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_.synrestrs) std::set(std::move(second.noun_phrase_.synrestrs)); - + break; } - + case type::preposition: { new(&first.preposition_.choices) std::set(std::move(second.preposition_.choices)); first.preposition_.literal = second.preposition_.literal; - + break; } - + case type::literal: { new(&first.literal_) std::string(std::move(second.literal_)); - + break; } - + case type::verb: case type::adjective: case type::adverb: @@ -186,11 +186,11 @@ namespace verbly { break; } } - + second.~part(); - + second.type_ = tempType; - + switch (second.type_) { case type::noun_phrase: @@ -198,25 +198,25 @@ namespace verbly { new(&second.noun_phrase_.role) std::string(std::move(tempRole)); new(&second.noun_phrase_.selrestrs) selrestr(std::move(tempSelrestrs)); new(&second.noun_phrase_.synrestrs) std::set(std::move(tempSynrestrs)); - + break; } - + case type::preposition: { new(&second.preposition_.choices) std::set(std::move(tempChoices)); second.preposition_.literal = tempPrepLiteral; - + break; } - + case type::literal: { new(&second.literal_) std::string(std::move(tempLiteralValue)); - + break; } - + case type::verb: case type::adjective: case type::adverb: @@ -226,7 +226,7 @@ namespace verbly { } } } - + part::~part() { switch (type_) @@ -235,32 +235,32 @@ namespace verbly { { using string_type = std::string; using set_type = std::set; - + noun_phrase_.role.~string_type(); noun_phrase_.selrestrs.~selrestr(); noun_phrase_.synrestrs.~set_type(); - + break; } - + case type::preposition: { using set_type = std::set; - + preposition_.choices.~set_type(); - + break; } - + case type::literal: { using string_type = std::string; - + literal_.~string_type(); - + break; } - + case type::verb: case type::adjective: case type::adverb: @@ -270,7 +270,7 @@ namespace verbly { } } } - + std::string part::getNounRole() const { if (type_ == type::noun_phrase) @@ -280,7 +280,7 @@ namespace verbly { throw std::domain_error("part::getNounRole is only valid for noun phrase parts"); } } - + selrestr part::getNounSelrestrs() const { if (type_ == type::noun_phrase) @@ -290,7 +290,7 @@ namespace verbly { throw std::domain_error("part::getNounSelrestrs is only valid for noun phrase parts"); } } - + std::set part::getNounSynrestrs() const { if (type_ == type::noun_phrase) @@ -300,7 +300,7 @@ namespace verbly { throw std::domain_error("part::getNounSynrestrs is only valid for noun phrase parts"); } } - + std::set part::getPrepositionChoices() const { if (type_ == type::preposition) @@ -310,7 +310,7 @@ namespace verbly { throw std::domain_error("part::getPrepositionChoices is only valid for preposition parts"); } } - + bool part::isPrepositionLiteral() const { if (type_ == type::preposition) @@ -320,7 +320,7 @@ namespace verbly { throw std::domain_error("part::isPrepositionLiteral is only valid for preposition parts"); } } - + std::string part::getLiteralValue() const { if (type_ == type::literal) @@ -330,6 +330,6 @@ namespace verbly { throw std::domain_error("part::getLiteralValue is only valid for literal parts"); } } - + }; }; diff --git a/generator/part.h b/generator/part.h index 86d5d57..b010f62 100644 --- a/generator/part.h +++ b/generator/part.h @@ -7,7 +7,7 @@ namespace verbly { namespace generator { - + class part { public: enum class type { @@ -19,78 +19,78 @@ namespace verbly { adverb = 4, literal = 5 }; - + // Static factories - + static part createNounPhrase(std::string role, selrestr selrestrs, std::set synrestrs); - + static part createVerb(); - + static part createPreposition(std::set choices, bool literal); - + static part createAdjective(); - + static part createAdverb(); - + static part createLiteral(std::string value); - + // Copy and move constructors - + part(const part& other); - + part(part&& other); - + // Assignment - + part& operator=(part other); - + // Swap - + friend void swap(part& first, part& second); - + // Destructor - + ~part(); - + // General accessors - + type getType() const { return type_; } - + // Noun phrase accessors - + std::string getNounRole() const; - + selrestr getNounSelrestrs() const; - + std::set getNounSynrestrs() const; - + // Preposition accessors - + std::set getPrepositionChoices() const; - + bool isPrepositionLiteral() const; - + // Literal accessors - + std::string getLiteralValue() const; - + private: - + // Private constructors - + part() { } - + part(type t) : type_(t) { } - + // Data - + union { struct { std::string role; @@ -103,11 +103,11 @@ namespace verbly { } preposition_; std::string literal_; }; - + type type_ = type::invalid; - + }; - + }; }; diff --git a/generator/progress.h b/generator/progress.h index fcb680d..76cde48 100644 --- a/generator/progress.h +++ b/generator/progress.h @@ -5,20 +5,20 @@ namespace verbly { namespace generator { - + class progress { private: std::string message; int total; int cur = 0; int lprint = 0; - + public: progress(std::string message, int total) : message(message), total(total) { std::cout << message << " 0%" << std::flush; } - + void update(int val) { if (val <= total) @@ -27,29 +27,29 @@ namespace verbly { } else { cur = total; } - + int pp = cur * 100 / total; if (pp != lprint) { lprint = pp; - + std::cout << "\b\b\b\b" << std::right; std::cout.width(3); std::cout << pp << "%" << std::flush; } } - + void update() { update(cur+1); } - + ~progress() { std::cout << "\b\b\b\b100%" << std::endl; } }; - + }; }; diff --git a/generator/word.cpp b/generator/word.cpp index 8ba3ce2..b3fc490 100644 --- a/generator/word.cpp +++ b/generator/word.cpp @@ -37,7 +37,7 @@ namespace verbly { { adjectivePosition_ = adjectivePosition; } - + void word::setVerbGroup(const group& verbGroup) { verbGroup_ = &verbGroup; @@ -46,7 +46,7 @@ namespace verbly { database& operator<<(database& db, const word& arg) { std::list fields; - + fields.emplace_back("word_id", arg.getId()); fields.emplace_back("notion_id", arg.getNotion().getId()); fields.emplace_back("lemma_id", arg.getLemma().getId()); @@ -55,13 +55,13 @@ namespace verbly { { fields.emplace_back("tag_count", arg.getTagCount()); } - + if ((arg.getNotion().getPartOfSpeech() == part_of_speech::adjective) && (arg.getAdjectivePosition() != positioning::undefined)) { fields.emplace_back("position", static_cast(arg.getAdjectivePosition())); } - + if ((arg.getNotion().getPartOfSpeech() == part_of_speech::verb) && (arg.hasVerbGroup())) { diff --git a/generator/word.h b/generator/word.h index 1d77ed3..a994ec3 100644 --- a/generator/word.h +++ b/generator/word.h @@ -24,7 +24,7 @@ namespace verbly { // Mutators void setAdjectivePosition(positioning adjectivePosition); - + void setVerbGroup(const group& verbGroup); // Accessors @@ -58,7 +58,7 @@ namespace verbly { { return hasTagCount_; } - + int getTagCount() const { // Calling code should always call hasTagCount first. @@ -71,17 +71,17 @@ namespace verbly { { return adjectivePosition_; } - + bool hasVerbGroup() const { return (verbGroup_ != nullptr); } - + const group& getVerbGroup() const { // Calling code should always call hasVerbGroup first. assert(verbGroup_ != nullptr); - + return *verbGroup_; } -- cgit 1.4.1