From 6746da6edd7d9d50efe374eabbb79a3cac882d81 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 16 Jan 2017 18:02:50 -0500 Subject: Started structural rewrite The new object structure was designed to build on the existing WordNet structure, while also adding in all of the data that we get from other sources. More information about this can be found on the project wiki. The generator has already been completely rewritten to generate a datafile that uses the new structure. In addition, a number of indexes are created, which does double the size of the datafile, but also allows for much faster lookups. Finally, the new generator is written modularly and is a lot more readable than the old one. The verbly interface to the new object structure has mostly been completed, but has not been tested fully. There is a completely new search API which utilizes a lot of operator overloading; documentation on how to use it should go up at some point. Token processing and verb frames are currently unimplemented. Source for these have been left in the repository for now. --- generator/notion.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 generator/notion.cpp (limited to 'generator/notion.cpp') diff --git a/generator/notion.cpp b/generator/notion.cpp new file mode 100644 index 0000000..290d982 --- /dev/null +++ b/generator/notion.cpp @@ -0,0 +1,85 @@ +#include "notion.h" +#include +#include +#include "database.h" +#include "field.h" + +namespace verbly { + namespace generator { + + int notion::nextId_ = 0; + + notion::notion( + part_of_speech partOfSpeech) : + id_(nextId_++), + partOfSpeech_(partOfSpeech) + { + } + + notion::notion( + part_of_speech partOfSpeech, + int wnid) : + id_(nextId_++), + partOfSpeech_(partOfSpeech), + wnid_(wnid), + hasWnid_(true) + { + } + + void notion::incrementNumOfImages() + { + // 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; + } + + database& operator<<(database& db, const notion& arg) + { + // First, serialize the notion + { + std::list fields; + + fields.emplace_back("notion_id", arg.getId()); + fields.emplace_back("part_of_speech", static_cast(arg.getPartOfSpeech())); + + if (arg.hasWnid()) + { + fields.emplace_back("wnid", arg.getWnid()); + + if (arg.getPartOfSpeech() == part_of_speech::noun) + { + fields.emplace_back("images", arg.getNumOfImages()); + } + } + + 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)); + } + } + + return db; + } + + }; +}; -- cgit 1.4.1