Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smem str constants #501

Draft
wants to merge 6 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions Core/CLI/src/cli_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,18 @@ void print_symbol(agent* thisAgent, const char* arg, bool print_filename, bool i
if (lLti_id)
{
lLti_id = thisAgent->SMem->lti_exists(lLti_id);
if (lLti_id == NIL)
{
thisAgent->outputManager->printa_sf(thisAgent, "LTI %s not found in semantic memory.", lexeme.string());
break;
}
}
else
{
// Treat the rest of the token as an LTI alias
std::string lti_alias(lexeme.string());
lti_alias = lti_alias.substr(1);
lLti_id = thisAgent->SMem->get_lti_with_alias(lti_alias);
}
if (lLti_id == NIL)
{
thisAgent->outputManager->printa_sf(thisAgent, "LTI %s not found in semantic memory.", lexeme.string());
break;
}
}
thisAgent->SMem->attach();
Expand Down
16 changes: 16 additions & 0 deletions Core/CLI/src/cli_smem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ bool CommandLineInterface::DoSMem(const char pOp, const std::string* pArg1, cons
lti_id = thisAgent->SMem->lti_exists(lexer.current_lexeme.int_val);
}
}
else if (lexer.current_lexeme.type == STR_CONSTANT_LEXEME)
{
if (thisAgent->SMem->connected())
{
std::string lti_alias = lexer.current_lexeme.string();
lti_id = thisAgent->SMem->get_lti_with_alias(lti_alias);
}
}

if (lti_id == NIL)
{
Expand Down Expand Up @@ -426,6 +434,14 @@ bool CommandLineInterface::DoSMem(const char pOp, const std::string* pArg1, cons
lti_id = thisAgent->SMem->lti_exists(lexer.current_lexeme.int_val);
}
}
else if (lexer.current_lexeme.type == STR_CONSTANT_LEXEME)
{
if (thisAgent->SMem->connected())
{
std::string lti_alias = lexer.current_lexeme.string();
lti_id = thisAgent->SMem->get_lti_with_alias(lti_alias);
}
}

if (lti_id == NIL)
{
Expand Down
8 changes: 8 additions & 0 deletions Core/CLI/src/cli_visualize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ bool CommandLineInterface::DoVisualize(const std::string* pArg1, const std::stri
lti_id = thisAgent->SMem->lti_exists(lexer.current_lexeme.int_val);
}
}
else if (lexer.current_lexeme.type == STR_CONSTANT_LEXEME)
{
if (thisAgent->SMem->connected())
{
std::string lti_alias = lexer.current_lexeme.string();
lti_id = thisAgent->SMem->get_lti_with_alias(lti_alias);
}
}

if (lti_id == NIL)
{
Expand Down
1 change: 0 additions & 1 deletion Core/SoarKernel/src/semantic_memory/semantic_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,6 @@ SMem_Manager::SMem_Manager(agent* myAgent)
smem_context_additions = new std::set<uint64_t>();
smem_context_removals = new std::set<uint64_t>();
smem_edges_to_update = new smem_update_map();

};

void SMem_Manager::clean_up_for_agent_deletion()
Expand Down
5 changes: 5 additions & 0 deletions Core/SoarKernel/src/semantic_memory/semantic_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class SMem_Manager

/* Methods for smem CLI commands*/
uint64_t lti_exists(uint64_t pLTI_ID);
uint64_t get_lti_with_alias(const std::string& lti_alias);
bool CLI_add(const char* str_to_LTMs, std::string** err_msg);
bool CLI_query(const char* ltms, std::string** err_msg, std::string** result_message, uint64_t number_to_retrieve);
bool CLI_remove(const char* ltms, std::string** err_msg, std::string** result_message, bool force = false);
Expand Down Expand Up @@ -161,6 +162,10 @@ class SMem_Manager
double lti_calc_base(uint64_t pLTI_ID, int64_t time_now, uint64_t n = 0, uint64_t activations_first = 0);
id_set print_LTM(uint64_t pLTI_ID, double lti_act, std::string* return_val, std::list<uint64_t>* history = NIL);

/* Methods for LTI aliases */
uint64_t add_new_lti_with_alias(const std::string& lti_alias);
uint64_t get_or_add_lti_with_alias(const std::string& lti_alias);

/* Methods for retrieving an LTM structure to be installed in STM */
void add_triple_to_recall_buffer(symbol_triple_list& my_list, Symbol* id, Symbol* attr, Symbol* value);
void install_buffered_triple_list(Symbol* state, wme_set& cue_wmes, symbol_triple_list& my_list, bool meta, bool stripLTILinks = false);
Expand Down
120 changes: 81 additions & 39 deletions Core/SoarKernel/src/semantic_memory/smem_cli_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,28 @@ bool SMem_Manager::CLI_query(const char* ltms_str, std::string** err_msg, std::s
}
else if (lexer.current_lexeme.type == AT_LEXEME)
{
lexer.get_lexeme();
lexer.get_lexeme(); // consume the @ symbol

// Look up the LTI's id (either integer value or string alias)
uint64_t value_id = 0;
if (lexer.current_lexeme.type != INT_CONSTANT_LEXEME)
if (lexer.current_lexeme.type == INT_CONSTANT_LEXEME)
{
value_id = lexer.current_lexeme.int_val;
}
else if (lexer.current_lexeme.type == STR_CONSTANT_LEXEME)
{
std::string lti_alias = lexer.current_lexeme.string();
value_id = get_lti_with_alias(lti_alias);
}
else
{
good_cue = false;
(*err_msg)->append("Error: @ must be followed by an integer to be a long-term identifier.\n");
(*err_msg)->append("Error: @ must be followed by an integer or string alias to be a long-term identifier.\n");
break;
}
value_id = lti_exists(lexer.current_lexeme.int_val);
if (value_id == NIL)

// Make sure the LTI exists
if (!lti_exists(value_id))
{
good_cue = false;
(*err_msg)->append("Error: LTI was not found.\n");
Expand All @@ -296,7 +308,7 @@ bool SMem_Manager::CLI_query(const char* ltms_str, std::string** err_msg, std::s
{
/* Not sure what we'd want to use here. Will create an identifier for now with lti_id */
value = thisAgent->symbolManager->make_new_identifier('L', 1);
value->id->LTI_ID = lexer.current_lexeme.int_val;
value->id->LTI_ID = value_id;
value->id->smem_valid = smem_validation;
}
lexer.get_lexeme();
Expand Down Expand Up @@ -496,13 +508,19 @@ bool SMem_Manager::CLI_remove(const char* ltms_str, std::string** err_msg, std::
{
lti_id = lexer.current_lexeme.int_val;
}
else if (lexer.current_lexeme.type == STR_CONSTANT_LEXEME)
{
// String constant, use a look-up table to convert string alias to id
const std::string lti_alias = lexer.current_lexeme.string();
lti_id = get_lti_with_alias(lti_alias);
}
else
{
good_command = false;
(*err_msg)->append("Error: The lti id must be an integer.\n");
(*err_msg)->append("Error: The lti id must be an integer or string alias.\n");
}

if (!lti_exists(lti_id))
if (good_command && !lti_exists(lti_id))
{
good_command = false;
(*err_msg)->append("Error: No LTI found for that id.\n");
Expand Down Expand Up @@ -669,17 +687,26 @@ bool SMem_Manager::CLI_remove(const char* ltms_str, std::string** err_msg, std::
else if (lexer.current_lexeme.type == AT_LEXEME)
{
lexer.get_lexeme();

uint64_t value_id;
if (lexer.current_lexeme.type == INT_CONSTANT_LEXEME)
{
value = get_current_iSTI_for_LTI(lexer.current_lexeme.int_val, NO_WME_LEVEL);
lexer.get_lexeme();
value_id = lexer.current_lexeme.int_val;
}
else if (lexer.current_lexeme.type == STR_CONSTANT_LEXEME)
{
// String constant, use a look-up table to convert string alias to id
const std::string lti_alias = lexer.current_lexeme.string();
value_id = get_lti_with_alias(lti_alias);
}
else
{
(*err_msg)->append("Error: '@' should be followed by an integer lti id.\n");
(*err_msg)->append("Error: '@' should be followed by an integer lti id or string alias.\n");
good_command = false;
break;
}
value = get_current_iSTI_for_LTI(value_id, NO_WME_LEVEL);
lexer.get_lexeme();
}
else
{
Expand Down Expand Up @@ -844,10 +871,20 @@ bool SMem_Manager::parse_add_clause(soar::Lexer* lexer, str_to_ltm_map* str_to_L
{
lexer->get_lexeme();

good_at = (lexer->current_lexeme.type == INT_CONSTANT_LEXEME);
good_at = (lexer->current_lexeme.type == INT_CONSTANT_LEXEME || lexer->current_lexeme.type == STR_CONSTANT_LEXEME);
if (good_at)
{
l_ltm->lti_id = lexer->current_lexeme.int_val;
if (lexer->current_lexeme.type == INT_CONSTANT_LEXEME)
{
// Integer constant, just use number as id
l_ltm->lti_id = static_cast<uint64_t>(lexer->current_lexeme.int_val);
}
else
{
// String constant, use a look-up table to convert string alias to id
const std::string lti_alias = lexer->current_lexeme.string();
l_ltm->lti_id = get_or_add_lti_with_alias(lti_alias);
}
}
}

Expand All @@ -858,7 +895,10 @@ bool SMem_Manager::parse_add_clause(soar::Lexer* lexer, str_to_ltm_map* str_to_L
l_ltm_name.append(lexer->current_lexeme.string());
l_ltm->lti_id = NIL;
} else {
good_at = ((lexer->current_lexeme.type == INT_CONSTANT_LEXEME) || (lexer->current_lexeme.type == IDENTIFIER_LEXEME));
good_at = ((lexer->current_lexeme.type == INT_CONSTANT_LEXEME)
|| (lexer->current_lexeme.type == STR_CONSTANT_LEXEME)
|| (lexer->current_lexeme.type == IDENTIFIER_LEXEME)); // Is this possible?

get_lti_name(l_ltm->lti_id, l_ltm_name);
}
if (good_at)
Expand Down Expand Up @@ -968,40 +1008,42 @@ bool SMem_Manager::parse_add_clause(soar::Lexer* lexer, str_to_ltm_map* str_to_L
}
else if ((lexer->current_lexeme.type == AT_LEXEME) || (lexer->current_lexeme.type == VARIABLE_LEXEME))
{
bool mistakenLTI = false;
uint64_t given_lti_id = 0; // When the author gives a specific LTI id value (either @1343 or @red)
if (lexer->current_lexeme.type == VARIABLE_LEXEME)
{
temp_key2.assign(lexer->current_lexeme.string());
}

good_at = false;
if (lexer->current_lexeme.type == AT_LEXEME)
{
lexer->get_lexeme();
if (lexer->current_lexeme.type == STR_CONSTANT_LEXEME)
if (lexer->current_lexeme.type == INT_CONSTANT_LEXEME)
{
// Integer constant, just use number as id
given_lti_id = static_cast<uint64_t>(lexer->current_lexeme.int_val);
good_at = true;
}
else if (lexer->current_lexeme.type == STR_CONSTANT_LEXEME)
{
std::string fixedString("|@");
fixedString.append(lexer->current_lexeme.string());
fixedString.push_back('|');
l_ltm_value = new ltm_value;
l_ltm_value->val_const.val_type = value_const_t;
l_ltm_value->val_const.val_value = thisAgent->symbolManager->make_str_constant(fixedString.c_str());
mistakenLTI = true;
} else {
good_at = (lexer->current_lexeme.type == INT_CONSTANT_LEXEME);
// String constant, use a look-up table to convert string alias to id
const std::string lti_alias = lexer->current_lexeme.string();
given_lti_id = get_or_add_lti_with_alias(lti_alias);
good_at = true;
}
}

if (good_at && !mistakenLTI)
if (good_at && given_lti_id != 0) {
temp_key2.clear();
get_lti_name(given_lti_id, temp_key2);
}
}

if (good_at || (lexer->current_lexeme.type == VARIABLE_LEXEME))
{
// create new value
l_ltm_value = new ltm_value;
l_ltm_value->val_lti.val_type = value_lti_t;

// get key
if (lexer->current_lexeme.type == VARIABLE_LEXEME)
{
temp_key2.assign(lexer->current_lexeme.string());
} else {
assert ((lexer->current_lexeme.type == INT_CONSTANT_LEXEME) || (lexer->current_lexeme.type == IDENTIFIER_LEXEME));
temp_key2.clear();
get_lti_name(static_cast<uint64_t>(lexer->current_lexeme.int_val), temp_key2);
}

// search for an existing ltm
str_to_ltm_map::iterator p = str_to_LTMs->find((temp_key2));

Expand All @@ -1017,9 +1059,9 @@ bool SMem_Manager::parse_add_clause(soar::Lexer* lexer, str_to_ltm_map* str_to_L
l_ltm_temp->slots = NIL;
// l_ltm_temp->soar_id = NIL;

if (lexer->current_lexeme.type == INT_CONSTANT_LEXEME)
if (given_lti_id != 0)
{
l_ltm_temp->lti_id = static_cast<uint64_t>(lexer->current_lexeme.int_val);
l_ltm_temp->lti_id = given_lti_id;
/* May want to verify that this is a legitimate id in the smem database */
//l_ltm_temp->lti_id = lti_exists(static_cast<uint64_t>(lexer->current_lexeme.int_val));
//if (l_ltm_temp->lti_id == NIL)
Expand Down
Loading
Loading