finish inserting the suggested actions

This commit is contained in:
2023-02-18 21:32:05 -03:00
parent 91cce4c170
commit d8ae5e1b95
4 changed files with 70 additions and 8 deletions

View File

@@ -153,6 +153,27 @@ void obelisk::KnowledgeBase::addFacts(std::vector<obelisk::Fact>& facts)
}
}
void obelisk::KnowledgeBase::addSuggestActions(std::vector<obelisk::SuggestAction>& suggestActions)
{
for (auto& suggestAction : suggestActions)
{
try
{
suggestAction.insert(dbConnection_);
}
catch (obelisk::DatabaseConstraintException& exception)
{
// ignore unique constraint error
if (std::strcmp(exception.what(),
"UNIQUE constraint failed: suggest_action.fact, suggest_action.true_action, suggest_action.false_action")
!= 0)
{
throw;
}
}
}
}
void obelisk::KnowledgeBase::getEntity(obelisk::Entity& entity)
{
entity.selectByName(dbConnection_);
@@ -173,6 +194,11 @@ void obelisk::KnowledgeBase::getFact(obelisk::Fact& fact)
fact.selectById(dbConnection_);
}
void obelisk::KnowledgeBase::getSuggestAction(obelisk::SuggestAction& suggestAction)
{
suggestAction.selectById(dbConnection_);
}
void obelisk::KnowledgeBase::getFloat(float& result1, float& result2, double var)
{
result1 = (float) var;

View File

@@ -111,7 +111,7 @@ namespace obelisk
void addActions(std::vector<obelisk::Action>& actions);
/**
* @brief Add facts to the database.
* @brief Add facts to the KnowledgeBase.
*
* @param[in,out] facts The facts to add. If the insert is
* successful it will have a row ID, if not the ID will be 0.
@@ -119,7 +119,16 @@ namespace obelisk
void addFacts(std::vector<obelisk::Fact>& facts);
/**
* @brief Get an entity object based on the ID it contains.
* @brief Add suggested actions to the KnowledgeBase.
*
* @param[in,out] suggestActions The suggested actions to add. If
* the insert is successful it will have a row ID, if not the ID
* will be 0.
*/
void addSuggestActions(std::vector<obelisk::SuggestAction>& suggestActions);
/**
* @brief Get an Entity object based on the ID it contains.
*
* @param[in,out] entity The Entity object should contain just the
* ID and the rest will be filled in.
@@ -127,7 +136,7 @@ namespace obelisk
void getEntity(obelisk::Entity& entity);
/**
* @brief Get a verb object based on the ID it contains.
* @brief Get a Verb object based on the ID it contains.
*
* @param[in,out] verb The Verb object should contain just the ID
* and the rest will be filled in.
@@ -135,7 +144,7 @@ namespace obelisk
void getVerb(obelisk::Verb& verb);
/**
* @brief Get an action based on the ID it contains.
* @brief Get an Action based on the ID it contains.
*
* @param[in] action The Action object should contain just the ID
* and the rest will be filled in.
@@ -143,13 +152,21 @@ namespace obelisk
void getAction(obelisk::Action& action);
/**
* @brief Get a fact object based on the ID it contains.
* @brief Get a Fact object based on the ID it contains.
*
* @param[in,out] fact The fact object should contain just the ID
* @param[in,out] fact The Fact object should contain just the ID
* and the rest will be filled in.
*/
void getFact(obelisk::Fact& fact);
/**
* @brief Get a SuggestAction based on the ID it contains.
*
* @param[in,out] suggestAction The SuggestAction object should
* contain just the ID and the rest will be filled in.
*/
void getSuggestAction(obelisk::SuggestAction& suggestAction);
/**
* @brief Take a float and divide it into 2 floats.
*