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/frame.h | 178 +++++++++++++++++++++++------------------------------------- 1 file changed, 69 insertions(+), 109 deletions(-) (limited to 'lib/frame.h') diff --git a/lib/frame.h b/lib/frame.h index fa57e1b..68a4346 100644 --- a/lib/frame.h +++ b/lib/frame.h @@ -1,118 +1,78 @@ -#ifndef FRAME_H_9A5D90FE -#define FRAME_H_9A5D90FE +#ifndef FRAME_H_EA29065A +#define FRAME_H_EA29065A + +#include +#include +#include "field.h" +#include "filter.h" + +struct sqlite3_stmt; namespace verbly { - class frame_query; - + class database; + class frame { - public: - class selrestr { - public: - enum class type { - empty, - singleton, - group - }; - - type get_type() const; - selrestr(const selrestr& other); - ~selrestr(); - selrestr& operator=(const selrestr& other); - - // Empty - selrestr(); - - // Singleton - selrestr(std::string restriction, bool pos); - std::string get_restriction() const; - bool get_pos() const; - - // Group - selrestr(std::list children, bool orlogic); - std::list get_children() const; - std::list::const_iterator begin() const; - std::list::const_iterator end() const; - bool get_orlogic() const; - - private: - union { - struct { - bool pos; - std::string restriction; - } _singleton; - struct { - std::list children; - bool orlogic; - } _group; - }; - type _type; - }; + public: + + // Default constructor + + frame() = default; + + // Construct from database + + frame(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 frame"); + } - class part { - public: - enum class type { - noun_phrase, - verb, - literal_preposition, - selection_preposition, - adjective, - adverb, - literal - }; - - type get_type() const; - part(const part& other); - ~part(); - - // Noun phrase - std::string get_role() const; - selrestr get_selrestrs() const; - std::set get_synrestrs() const; - - // Literal preposition - std::vector get_choices() const; - - // Selection preposition - std::vector get_preprestrs() const; - - // Literal - std::string get_literal() const; - - private: - friend class frame_query; - - part(); - - union { - struct { - std::string role; - selrestr selrestrs; - std::set synrestrs; - } _noun_phrase; - struct { - std::vector choices; - } _literal_preposition; - struct { - std::vector preprestrs; - } _selection_preposition; - struct { - std::string lexval; - } _literal; - }; - type _type; - }; + return id_; + } + + // Type info + + static const object objectType; + + static const std::list select; + + // Query fields + + static const field id; + + operator filter() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized frame"); + } - std::vector parts() const; - std::map roles() const; - - private: - friend class frame_query; - - std::vector _parts; - std::map _roles; + return (id == id_); + } + + // Relationships to other objects + + static const field group; + + private: + bool valid_ = false; + + int id_; + + const database* db_; + }; - + }; -#endif /* end of include guard: FRAME_H_9A5D90FE */ +#endif /* end of include guard: FRAME_H_EA29065A */ -- cgit 1.4.1