create the knowledge base structure

Este commit está contenido en:
2022-11-01 01:04:41 -03:00
padre 0c891dbf23
commit 723c45fc3c
Se han modificado 17 ficheros con 618 adiciones y 59 borrados

32
src/models/action.cpp Archivo normal
Ver fichero

@@ -0,0 +1,32 @@
#include "models/action.h"
const char* obelisk::Action::createTable()
{
return R"(
CREATE TABLE "action" (
"id" INTEGER NOT NULL UNIQUE,
"name" TEXT NOT NULL CHECK(trim(name) != '') UNIQUE,
PRIMARY KEY("id" AUTOINCREMENT)
);
)";
}
int obelisk::Action::getId()
{
return id_;
}
void obelisk::Action::setId(int id)
{
id_ = id;
}
std::string obelisk::Action::getName()
{
return name_;
}
void obelisk::Action::setName(std::string name)
{
name_ = name;
}

49
src/models/action.h Archivo normal
Ver fichero

@@ -0,0 +1,49 @@
#ifndef OBELISK_MODELS_ACTION_H
#define OBELISK_MODELS_ACTION_H
#include <string>
namespace obelisk
{
class Action
{
private:
int id_;
std::string name_;
public:
Action() :
id_(0),
name_("")
{
}
Action(int id) :
id_(id),
name_("")
{
}
Action(std::string name) :
id_(0),
name_(name)
{
}
Action(int id, std::string name) :
id_(id),
name_(name)
{
}
static const char* createTable();
int getId();
void setId(int id);
std::string getName();
void setName(std::string name);
};
} // namespace obelisk
#endif

Ver fichero

@@ -1,12 +1,14 @@
#include "models/entity.h"
obelisk::Entity::Entity()
const char* obelisk::Entity::createTable()
{
}
obelisk::Entity::Entity(std::string name)
{
name = name;
return R"(
CREATE TABLE "entity" (
"id" INTEGER NOT NULL UNIQUE,
"name" TEXT NOT NULL CHECK(trim(name) != '') UNIQUE,
PRIMARY KEY("id" AUTOINCREMENT)
);
)";
}
int obelisk::Entity::getId()
@@ -26,5 +28,5 @@ std::string obelisk::Entity::getName()
void obelisk::Entity::setName(std::string name)
{
name_ = name_;
name_ = name;
}

Ver fichero

@@ -12,8 +12,31 @@ namespace obelisk
std::string name_;
public:
Entity();
Entity(std::string name);
Entity() :
id_(0),
name_("")
{
}
Entity(int id) :
id_(id),
name_("")
{
}
Entity(std::string name) :
id_(0),
name_(name)
{
}
Entity(int id, std::string name) :
id_(id),
name_(name)
{
}
static const char* createTable();
int getId();
void setId(int id);

57
src/models/fact.cpp Archivo normal
Ver fichero

@@ -0,0 +1,57 @@
#include "models/fact.h"
const char* obelisk::Fact::createTable()
{
return R"(
CREATE TABLE "fact" (
"id" INTEGER NOT NULL UNIQUE,
"left_entity" INTEGER NOT NULL,
"right_entity" INTEGER NOT NULL,
"verb" INTEGER NOT NULL,
PRIMARY KEY("id" AUTOINCREMENT),
FOREIGN KEY("verb") REFERENCES "verb"("id") ON DELETE RESTRICT,
FOREIGN KEY("right_entity") REFERENCES "entity"("id") ON DELETE RESTRICT,
FOREIGN KEY("left_entity") REFERENCES "entity"("id") ON DELETE RESTRICT
);
)";
}
int obelisk::Fact::getId()
{
return id_;
}
void obelisk::Fact::setId(int id)
{
id_ = id;
}
obelisk::Entity obelisk::Fact::getLeftEntity()
{
return leftEntity_;
}
void obelisk::Fact::setLeftEntity(obelisk::Entity leftEntity)
{
leftEntity_ = leftEntity;
}
obelisk::Entity obelisk::Fact::getRightEntity()
{
return rightEntity_;
}
void obelisk::Fact::setRightEntity(obelisk::Entity rightEntity)
{
rightEntity_ = rightEntity;
}
obelisk::Verb obelisk::Fact::getVerb()
{
return verb_;
}
void obelisk::Fact::setVerb(obelisk::Verb verb)
{
verb_ = verb;
}

73
src/models/fact.h Archivo normal
Ver fichero

@@ -0,0 +1,73 @@
#ifndef OBELISK_MODELS_FACT_H
#define OBELISK_MODELS_FACT_H
#include "models/entity.h"
#include "models/verb.h"
#include <string>
namespace obelisk
{
class Fact
{
private:
int id_;
obelisk::Entity leftEntity_;
obelisk::Entity rightEntity_;
obelisk::Verb verb_;
public:
Fact() :
id_(0),
leftEntity_(),
rightEntity_(),
verb_()
{
}
Fact(int id) :
id_(id),
leftEntity_(),
rightEntity_(),
verb_()
{
}
Fact(obelisk::Entity leftEntity,
obelisk::Entity rightEntity,
obelisk::Verb verb) :
id_(0),
leftEntity_(leftEntity),
rightEntity_(rightEntity),
verb_(verb)
{
}
Fact(int id,
obelisk::Entity leftEntity,
obelisk::Entity rightEntity,
obelisk::Verb verb) :
id_(id),
leftEntity_(leftEntity),
rightEntity_(rightEntity),
verb_(verb)
{
}
static const char* createTable();
int getId();
void setId(int id);
obelisk::Entity getLeftEntity();
void setLeftEntity(obelisk::Entity leftEntity);
obelisk::Entity getRightEntity();
void setRightEntity(obelisk::Entity leftEntity);
obelisk::Verb getVerb();
void setVerb(obelisk::Verb verb);
};
} // namespace obelisk
#endif

8
src/models/meson.build Archivo normal
Ver fichero

@@ -0,0 +1,8 @@
obelisk_model_sources = files(
'action.cpp',
'entity.cpp',
'fact.cpp',
'rule.cpp',
'suggest_action.cpp',
'verb.cpp'
)

45
src/models/rule.cpp Archivo normal
Ver fichero

@@ -0,0 +1,45 @@
#include "models/rule.h"
const char* obelisk::Rule::createTable()
{
return R"(
CREATE TABLE "rule" (
"id" INTEGER NOT NULL UNIQUE,
"fact" INTEGER NOT NULL,
"reason" INTEGER NOT NULL CHECK("reason" != "fact"),
PRIMARY KEY("id" AUTOINCREMENT),
FOREIGN KEY("fact") REFERENCES "fact"("id") ON DELETE RESTRICT,
FOREIGN KEY("reason") REFERENCES "fact"("id") ON DELETE RESTRICT
);
)";
}
int obelisk::Rule::getId()
{
return id_;
}
void obelisk::Rule::setId(int id)
{
id_ = id;
}
obelisk::Fact obelisk::Rule::getFact()
{
return fact_;
}
void obelisk::Rule::setFact(obelisk::Fact fact)
{
fact_ = fact;
}
obelisk::Fact obelisk::Rule::getReason()
{
return reason_;
}
void obelisk::Rule::setReason(obelisk::Fact reason)
{
reason_ = reason;
}

59
src/models/rule.h Archivo normal
Ver fichero

@@ -0,0 +1,59 @@
#ifndef OBELISK_MODELS_RULE_H
#define OBELISK_MODELS_RULE_H
#include "models/fact.h"
#include <string>
namespace obelisk
{
class Rule
{
private:
int id_;
obelisk::Fact fact_;
obelisk::Fact reason_;
public:
Rule() :
id_(0),
fact_(),
reason_()
{
}
Rule(int id) :
id_(id),
fact_(),
reason_()
{
}
Rule(obelisk::Fact fact, obelisk::Fact reason) :
id_(0),
fact_(fact),
reason_(reason)
{
}
Rule(int id, obelisk::Fact fact, obelisk::Fact reason) :
id_(id),
fact_(fact),
reason_(reason)
{
}
static const char* createTable();
int getId();
void setId(int id);
obelisk::Fact getFact();
void setFact(obelisk::Fact fact);
obelisk::Fact getReason();
void setReason(obelisk::Fact reason);
};
} // namespace obelisk
#endif

57
src/models/suggest_action.cpp Archivo normal
Ver fichero

@@ -0,0 +1,57 @@
#include "models/suggest_action.h"
const char* obelisk::SuggestAction::createTable()
{
return R"(
CREATE TABLE "suggest_action" (
"id" INTEGER NOT NULL UNIQUE,
"fact" INTEGER NOT NULL,
"true_action" INTEGER NOT NULL,
"false_action" INTEGER NOT NULL,
PRIMARY KEY("id" AUTOINCREMENT),
FOREIGN KEY("fact") REFERENCES "fact"("id") ON DELETE RESTRICT,
FOREIGN KEY("true_action") REFERENCES "action"("id") ON DELETE RESTRICT,
FOREIGN KEY("false_action") REFERENCES "action"("id") ON DELETE RESTRICT
);
)";
}
int obelisk::SuggestAction::getId()
{
return id_;
}
void obelisk::SuggestAction::setId(int id)
{
id_ = id;
}
obelisk::Fact obelisk::SuggestAction::getFact()
{
return fact_;
}
void obelisk::SuggestAction::setFact(obelisk::Fact fact)
{
fact_ = fact;
}
obelisk::Action obelisk::SuggestAction::getTrueAction()
{
return trueAction_;
}
void obelisk::SuggestAction::setTrueAction(obelisk::Action trueAction)
{
trueAction_ = trueAction;
}
obelisk::Action obelisk::SuggestAction::getFalseAction()
{
return falseAction_;
}
void obelisk::SuggestAction::setFalseAction(obelisk::Action falseAction)
{
falseAction_ = falseAction;
}

73
src/models/suggest_action.h Archivo normal
Ver fichero

@@ -0,0 +1,73 @@
#ifndef OBELISK_MODELS_SUGGEST_ACTION_H
#define OBELISK_MODELS_SUGGEST_ACTION_H
#include "models/action.h"
#include "models/fact.h"
#include <string>
namespace obelisk
{
class SuggestAction
{
private:
int id_;
obelisk::Fact fact_;
obelisk::Action trueAction_;
obelisk::Action falseAction_;
public:
SuggestAction() :
id_(0),
fact_(),
trueAction_(),
falseAction_()
{
}
SuggestAction(int id) :
id_(id),
fact_(),
trueAction_(),
falseAction_()
{
}
SuggestAction(obelisk::Fact fact,
obelisk::Action trueAction,
obelisk::Action falseAction) :
id_(0),
fact_(fact),
trueAction_(trueAction),
falseAction_(falseAction)
{
}
SuggestAction(int id,
obelisk::Fact fact,
obelisk::Action trueAction,
obelisk::Action falseAction) :
id_(id),
fact_(fact),
trueAction_(trueAction),
falseAction_(falseAction)
{
}
static const char* createTable();
int getId();
void setId(int id);
obelisk::Fact getFact();
void setFact(obelisk::Fact fact);
obelisk::Action getTrueAction();
void setTrueAction(obelisk::Action trueAction);
obelisk::Action getFalseAction();
void setFalseAction(obelisk::Action falseAction);
};
} // namespace obelisk
#endif

Ver fichero

@@ -1,18 +1,14 @@
#include "models/verb.h"
obelisk::Verb::Verb()
const char* obelisk::Verb::createTable()
{
}
obelisk::Verb::Verb(std::string verb)
{
verb_ = verb;
}
obelisk::Verb::Verb(int id, std::string verb)
{
id_ = id;
verb_ = verb;
return R"(
CREATE TABLE "verb" (
"id" INTEGER NOT NULL UNIQUE,
"name" TEXT NOT NULL CHECK(trim(name) != "") UNIQUE,
PRIMARY KEY("id" AUTOINCREMENT)
);
)";
}
int obelisk::Verb::getId()
@@ -25,12 +21,12 @@ void obelisk::Verb::setId(int id)
id_ = id;
}
std::string obelisk::Verb::getVerb()
std::string obelisk::Verb::getName()
{
return verb_;
return name_;
}
void obelisk::Verb::setVerb(std::string verb)
void obelisk::Verb::setName(std::string name)
{
verb_ = verb;
name_ = name;
}

Ver fichero

@@ -9,18 +9,40 @@ namespace obelisk
{
private:
int id_;
std::string verb_;
std::string name_;
public:
Verb();
Verb(std::string verb);
Verb(int id, std::string verb);
Verb() :
id_(0),
name_("")
{
}
Verb(int id) :
id_(id),
name_("")
{
}
Verb(std::string name) :
id_(0),
name_(name)
{
}
Verb(int id, std::string name) :
id_(id),
name_(name)
{
}
static const char* createTable();
int getId();
void setId(int id);
std::string getVerb();
void setVerb(std::string verb);
std::string getName();
void setName(std::string name);
};
} // namespace obelisk