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.cpp | 317 ++-------------------------------------------------------- 1 file changed, 9 insertions(+), 308 deletions(-) (limited to 'lib/frame.cpp') diff --git a/lib/frame.cpp b/lib/frame.cpp index ccec81b..bc3f842 100644 --- a/lib/frame.cpp +++ b/lib/frame.cpp @@ -1,320 +1,21 @@ -#include "verbly.h" +#include "frame.h" +#include namespace verbly { - frame::selrestr::type frame::selrestr::get_type() const - { - return _type; - } - - frame::selrestr::selrestr(const selrestr& other) - { - _type = other._type; - - switch (_type) - { - case frame::selrestr::type::singleton: - { - _singleton.pos = other._singleton.pos; - new(&_singleton.restriction) std::string(other._singleton.restriction); - - break; - } - - case frame::selrestr::type::group: - { - new(&_group.children) std::list(other._group.children); - _group.orlogic = other._group.orlogic; - - break; - } - - case frame::selrestr::type::empty: - { - // Nothing! - - break; - } - } - } - - frame::selrestr::~selrestr() - { - switch (_type) - { - case frame::selrestr::type::singleton: - { - using string_type = std::string; - _singleton.restriction.~string_type(); - - break; - } - - case frame::selrestr::type::group: - { - using list_type = std::list; - _group.children.~list_type(); - - break; - } - - case frame::selrestr::type::empty: - { - // Nothing! - - break; - } - } - } - - frame::selrestr& frame::selrestr::operator=(const selrestr& other) - { - this->~selrestr(); - - _type = other._type; - - switch (_type) - { - case frame::selrestr::type::singleton: - { - _singleton.pos = other._singleton.pos; - new(&_singleton.restriction) std::string(other._singleton.restriction); - - break; - } - - case frame::selrestr::type::group: - { - new(&_group.children) std::list(other._group.children); - _group.orlogic = other._group.orlogic; - - break; - } - - case frame::selrestr::type::empty: - { - // Nothing! - - break; - } - } - - return *this; - } - - frame::selrestr::selrestr() : _type(frame::selrestr::type::empty) - { - - } - - frame::selrestr::selrestr(std::string restriction, bool pos) : _type(frame::selrestr::type::singleton) - { - new(&_singleton.restriction) std::string(restriction); - _singleton.pos = pos; - } - - std::string frame::selrestr::get_restriction() const - { - assert(_type == frame::selrestr::type::singleton); - - return _singleton.restriction; - } - - bool frame::selrestr::get_pos() const - { - assert(_type == frame::selrestr::type::singleton); - - return _singleton.pos; - } - - frame::selrestr::selrestr(std::list children, bool orlogic) : _type(frame::selrestr::type::group) - { - new(&_group.children) std::list(children); - _group.orlogic = orlogic; - } - - std::list frame::selrestr::get_children() const - { - assert(_type == frame::selrestr::type::group); - - return _group.children; - } - - std::list::const_iterator frame::selrestr::begin() const - { - assert(_type == frame::selrestr::type::group); - - return _group.children.begin(); - } - - std::list::const_iterator frame::selrestr::end() const - { - assert(_type == frame::selrestr::type::group); - - return _group.children.end(); - } - - bool frame::selrestr::get_orlogic() const - { - assert(_type == frame::selrestr::type::group); - - return _group.orlogic; - } - - frame::part::type frame::part::get_type() const - { - return _type; - } - - frame::part::part() - { - - } + const object frame::objectType = object::frame; - frame::part::part(const part& other) - { - _type = other._type; - - switch (_type) - { - case frame::part::type::noun_phrase: - { - 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 frame::part::type::literal_preposition: - { - new(&_literal_preposition.choices) std::vector(other._literal_preposition.choices); - - break; - } - - case frame::part::type::selection_preposition: - { - new(&_selection_preposition.preprestrs) std::vector(other._selection_preposition.preprestrs); - - break; - } - - case frame::part::type::literal: - { - new(&_literal.lexval) std::string(other._literal.lexval); - - break; - } - - default: - { - // Nothing! - - break; - } - } - } + const std::list frame::select = {"frame_id", "data"}; - frame::part::~part() - { - switch (_type) - { - case frame::part::type::noun_phrase: - { - 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 frame::part::type::literal_preposition: - { - using vector_type = std::vector; - _literal_preposition.choices.~vector_type(); - - break; - } - - case frame::part::type::selection_preposition: - { - using vector_type = std::vector; - _selection_preposition.preprestrs.~vector_type(); - - break; - } - - case frame::part::type::literal: - { - using string_type = std::string; - _literal.lexval.~string_type(); - - break; - } - - default: - { - // Nothing! - - break; - } - } - } + const field frame::id = field::integerField(object::frame, "frame_id"); - std::string frame::part::get_role() const - { - assert(_type == frame::part::type::noun_phrase); - - return _noun_phrase.role; - } + const field frame::group = field::joinThrough(object::frame, "frame_id", object::group, "groups_frames", "group_id"); - frame::selrestr frame::part::get_selrestrs() const + frame::frame(const database& db, sqlite3_stmt* row) : db_(&db), valid_(true) { - assert(_type == frame::part::type::noun_phrase); + id_ = sqlite3_column_int(row, 0); - return _noun_phrase.selrestrs; - } - - std::set frame::part::get_synrestrs() const - { - assert(_type == frame::part::type::noun_phrase); - - return _noun_phrase.synrestrs; - } - - std::vector frame::part::get_choices() const - { - assert(_type == frame::part::type::literal_preposition); - - return _literal_preposition.choices; - } - - std::vector frame::part::get_preprestrs() const - { - assert(_type == frame::part::type::selection_preposition); - - return _selection_preposition.preprestrs; - } - - std::string frame::part::get_literal() const - { - assert(_type == frame::part::type::literal); - - return _literal.lexval; - } - - std::vector frame::parts() const - { - return _parts; - } - - std::map frame::roles() const - { - return _roles; + // TODO: Initialize frame data from row. } }; -- cgit 1.4.1