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. --- lib/notion.h | 200 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 lib/notion.h (limited to 'lib/notion.h') diff --git a/lib/notion.h b/lib/notion.h new file mode 100644 index 0000000..a180d73 --- /dev/null +++ b/lib/notion.h @@ -0,0 +1,200 @@ +#ifndef NOTION_H_FD1C7646 +#define NOTION_H_FD1C7646 + +#include +#include +#include "field.h" +#include "filter.h" + +struct sqlite3_stmt; + +namespace verbly { + + class database; + + class notion { + public: + + // Default constructor + + notion() = default; + + // Construct from database + + notion(const database& db, sqlite3_stmt* row); + + // Accessors + + operator bool() const + { + return valid_; + } + + int getId() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized notion"); + } + + return id_; + } + + part_of_speech getPartOfSpeech() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized notion"); + } + + return partOfSpeech_; + } + + bool hasWnid() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized notion"); + } + + return hasWnid_; + } + + int getWnid() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized notion"); + } + + if (!hasWnid_) + { + throw std::domain_error("Notion has no wnid"); + } + + return wnid_; + } + + bool hasNumOfImages() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized notion"); + } + + return hasNumOfImages_; + } + + int getNumOfImages() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized notion"); + } + + if (!hasNumOfImages_) + { + throw std::domain_error("Notion does not have a number of images"); + } + + return numOfImages_; + } + + // Convenience + + std::string getImageNetUrl() const; + + // Type info + + static const object objectType; + + static const std::list select; + + // Query fields + + static const field id; + static const field partOfSpeech; + static const field wnid; + static const field numOfImages; + + operator filter() const + { + return (id == id_); + } + + // Relationships with other objects + + static const field word; + + // Relationships with self + + static const field hypernyms; + static const field hyponyms; + + static const field fullHypernyms; + static const field fullHyponyms; + + static const field instances; + static const field classes; + + static const field memberMeronyms; + static const field memberHolonyms; + + static const field fullMemberMeronyms; + static const field fullMemberHolonyms; + + static const field partMeronyms; + static const field partHolonyms; + + static const field fullPartMeronyms; + static const field fullPartHolonyms; + + static const field substanceMeronyms; + static const field substanceHolonyms; + + static const field fullSubstanceMeronyms; + static const field fullSubstanceHolonyms; + + static const field variants; + static const field attributes; + + static const field similarAdjectives; + + static const field entails; + static const field entailedBy; + + static const field causes; + static const field effects; + + // Preposition group relationship + + class preposition_group_field { + public: + + filter operator==(std::string groupName) const; + + private: + + static const field isA; + static const field groupNameField; + }; + + static const preposition_group_field prepositionGroup; + + private: + bool valid_ = false; + + int id_; + part_of_speech partOfSpeech_; + bool hasWnid_ = false; + int wnid_; + bool hasNumOfImages_ = false; + int numOfImages_; + + const database* db_; + + }; + +}; + +#endif /* end of include guard: NOTION_H_FD1C7646 */ -- cgit 1.4.1