From 50d15136eef75ef27b49302f75d444e715ae73a7 Mon Sep 17 00:00:00 2001 From: Aaron Mininger Date: Thu, 5 Sep 2024 09:05:08 -0400 Subject: [PATCH 1/4] Added an initial in-memory implementation of smem LTI aliases in --add commands --- .../src/semantic_memory/semantic_memory.cpp | 1 - .../src/semantic_memory/semantic_memory.h | 4 + .../src/semantic_memory/smem_cli_commands.cpp | 90 +++++++++++++------ .../src/semantic_memory/smem_structs.h | 4 + 4 files changed, 70 insertions(+), 29 deletions(-) diff --git a/Core/SoarKernel/src/semantic_memory/semantic_memory.cpp b/Core/SoarKernel/src/semantic_memory/semantic_memory.cpp index 17323b8e8a..623ffcba23 100644 --- a/Core/SoarKernel/src/semantic_memory/semantic_memory.cpp +++ b/Core/SoarKernel/src/semantic_memory/semantic_memory.cpp @@ -730,7 +730,6 @@ SMem_Manager::SMem_Manager(agent* myAgent) smem_context_additions = new std::set(); smem_context_removals = new std::set(); smem_edges_to_update = new smem_update_map(); - }; void SMem_Manager::clean_up_for_agent_deletion() diff --git a/Core/SoarKernel/src/semantic_memory/semantic_memory.h b/Core/SoarKernel/src/semantic_memory/semantic_memory.h index b77bb18b95..bc7cabf94b 100644 --- a/Core/SoarKernel/src/semantic_memory/semantic_memory.h +++ b/Core/SoarKernel/src/semantic_memory/semantic_memory.h @@ -122,6 +122,9 @@ class SMem_Manager smem_stat_container* statistics; soar_module::sqlite_database* DB; + alias_to_id_map lti_alias_map; + + /* Temporary maps used when creating an instance of an LTM */ id_to_sym_map lti_to_sti_map; sym_to_id_map iSti_to_lti_map; @@ -160,6 +163,7 @@ class SMem_Manager double lti_activate(uint64_t pLTI_ID, bool add_access, uint64_t num_edges = SMEM_ACT_MAX, double touches = 1, bool increment_timer = true); 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* history = NIL); + uint64_t get_id_for_lti_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); diff --git a/Core/SoarKernel/src/semantic_memory/smem_cli_commands.cpp b/Core/SoarKernel/src/semantic_memory/smem_cli_commands.cpp index 01cf4d4005..e9375bcd34 100644 --- a/Core/SoarKernel/src/semantic_memory/smem_cli_commands.cpp +++ b/Core/SoarKernel/src/semantic_memory/smem_cli_commands.cpp @@ -822,6 +822,25 @@ Symbol* SMem_Manager::parse_constant_attr(soar::Lexeme* lexeme) return return_val; } +uint64_t SMem_Manager::get_id_for_lti_alias(const std::string& lti_alias) { + // Look up an LTI alias in the map, or create a new one + // (mapping from a string constant to an id) + //thisAgent->outputManager->printa_sf(thisAgent, "Looking up alias |%s|\n", lti_alias.c_str()); + alias_to_id_map::iterator alias_iter = lti_alias_map.find(lti_alias); + if (alias_iter != lti_alias_map.end()) + { + //thisAgent->outputManager->printa_sf(thisAgent, " Found it! %u\n", alias_iter->second); + return alias_iter->second; + } + else + { + uint64_t new_id = add_new_LTI(); + //thisAgent->outputManager->printa_sf(thisAgent, " Made a new one: %u\n", new_id); + lti_alias_map[lti_alias] = new_id; + return new_id; + } +} + bool SMem_Manager::parse_add_clause(soar::Lexer* lexer, str_to_ltm_map* str_to_LTMs, ltm_set* newbies) { bool return_val = false; @@ -844,10 +863,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(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_id_for_lti_alias(lti_alias); + } } } @@ -858,7 +887,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) @@ -968,40 +1000,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(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_id_for_lti_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(lexer->current_lexeme.int_val), temp_key2); - } - // search for an existing ltm str_to_ltm_map::iterator p = str_to_LTMs->find((temp_key2)); @@ -1017,9 +1051,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(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(lexer->current_lexeme.int_val)); //if (l_ltm_temp->lti_id == NIL) diff --git a/Core/SoarKernel/src/semantic_memory/smem_structs.h b/Core/SoarKernel/src/semantic_memory/smem_structs.h index 0df14efdee..de90e688e8 100644 --- a/Core/SoarKernel/src/semantic_memory/smem_structs.h +++ b/Core/SoarKernel/src/semantic_memory/smem_structs.h @@ -94,6 +94,10 @@ typedef struct smem_edge_update_struct typedef std::unordered_map> smem_update_map; +// Mapping from constant string aliases to integer ids +// for hard-coded LTIs in smem --add commands (such as @red) +typedef std::map alias_to_id_map; + typedef union ltm_value_union { struct ltm_value_const val_const; From d7d201d7030c0da6daf1c85c83a357599356e27c Mon Sep 17 00:00:00 2001 From: Aaron Mininger Date: Mon, 9 Sep 2024 14:19:58 -0400 Subject: [PATCH 2/4] Implemented LTI aliases as a database feature (stored in smem_lti_alias table) --- .../src/semantic_memory/semantic_memory.h | 9 +-- .../src/semantic_memory/smem_cli_commands.cpp | 72 ++++++++++--------- .../src/semantic_memory/smem_db.cpp | 51 +++++++++++++ Core/SoarKernel/src/semantic_memory/smem_db.h | 3 + .../src/semantic_memory/smem_structs.h | 2 +- 5 files changed, 100 insertions(+), 37 deletions(-) diff --git a/Core/SoarKernel/src/semantic_memory/semantic_memory.h b/Core/SoarKernel/src/semantic_memory/semantic_memory.h index bc7cabf94b..8a1b57621d 100644 --- a/Core/SoarKernel/src/semantic_memory/semantic_memory.h +++ b/Core/SoarKernel/src/semantic_memory/semantic_memory.h @@ -122,9 +122,6 @@ class SMem_Manager smem_stat_container* statistics; soar_module::sqlite_database* DB; - alias_to_id_map lti_alias_map; - - /* Temporary maps used when creating an instance of an LTM */ id_to_sym_map lti_to_sti_map; sym_to_id_map iSti_to_lti_map; @@ -163,7 +160,11 @@ class SMem_Manager double lti_activate(uint64_t pLTI_ID, bool add_access, uint64_t num_edges = SMEM_ACT_MAX, double touches = 1, bool increment_timer = true); 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* history = NIL); - uint64_t get_id_for_lti_alias(const std::string& lti_alias); + + /* Methods for LTI aliases */ + uint64_t get_lti_with_alias(const std::string& lti_alias); + 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); diff --git a/Core/SoarKernel/src/semantic_memory/smem_cli_commands.cpp b/Core/SoarKernel/src/semantic_memory/smem_cli_commands.cpp index e9375bcd34..2e52a0baa1 100644 --- a/Core/SoarKernel/src/semantic_memory/smem_cli_commands.cpp +++ b/Core/SoarKernel/src/semantic_memory/smem_cli_commands.cpp @@ -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"); @@ -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(); @@ -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"); @@ -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 { @@ -822,25 +849,6 @@ Symbol* SMem_Manager::parse_constant_attr(soar::Lexeme* lexeme) return return_val; } -uint64_t SMem_Manager::get_id_for_lti_alias(const std::string& lti_alias) { - // Look up an LTI alias in the map, or create a new one - // (mapping from a string constant to an id) - //thisAgent->outputManager->printa_sf(thisAgent, "Looking up alias |%s|\n", lti_alias.c_str()); - alias_to_id_map::iterator alias_iter = lti_alias_map.find(lti_alias); - if (alias_iter != lti_alias_map.end()) - { - //thisAgent->outputManager->printa_sf(thisAgent, " Found it! %u\n", alias_iter->second); - return alias_iter->second; - } - else - { - uint64_t new_id = add_new_LTI(); - //thisAgent->outputManager->printa_sf(thisAgent, " Made a new one: %u\n", new_id); - lti_alias_map[lti_alias] = new_id; - return new_id; - } -} - bool SMem_Manager::parse_add_clause(soar::Lexer* lexer, str_to_ltm_map* str_to_LTMs, ltm_set* newbies) { bool return_val = false; @@ -875,7 +883,7 @@ bool SMem_Manager::parse_add_clause(soar::Lexer* lexer, str_to_ltm_map* str_to_L { // 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_id_for_lti_alias(lti_alias); + l_ltm->lti_id = get_or_add_lti_with_alias(lti_alias); } } } @@ -1020,7 +1028,7 @@ bool SMem_Manager::parse_add_clause(soar::Lexer* lexer, str_to_ltm_map* str_to_L { // 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_id_for_lti_alias(lti_alias); + given_lti_id = get_or_add_lti_with_alias(lti_alias); good_at = true; } diff --git a/Core/SoarKernel/src/semantic_memory/smem_db.cpp b/Core/SoarKernel/src/semantic_memory/smem_db.cpp index 81a03b78d4..30c09271ce 100644 --- a/Core/SoarKernel/src/semantic_memory/smem_db.cpp +++ b/Core/SoarKernel/src/semantic_memory/smem_db.cpp @@ -23,6 +23,7 @@ void smem_statement_container::create_tables() add_structure("CREATE TABLE smem_symbols_float (s_id INTEGER PRIMARY KEY, symbol_value REAL)"); add_structure("CREATE TABLE smem_symbols_string (s_id INTEGER PRIMARY KEY, symbol_value TEXT)"); add_structure("CREATE TABLE smem_lti (lti_id INTEGER PRIMARY KEY, total_augmentations INTEGER, activation_base_level REAL, activations_total REAL, activations_last INTEGER, activations_first INTEGER, activation_spread REAL, activation_value REAL, lti_augmentations INTEGER)"); + add_structure("CREATE TABLE smem_lti_alias (alias TEXT PRIMARY KEY, lti_id INTEGER)"); add_structure("CREATE TABLE smem_activation_history (lti_id INTEGER PRIMARY KEY, t1 INTEGER, t2 INTEGER, t3 INTEGER, t4 INTEGER, t5 INTEGER, t6 INTEGER, t7 INTEGER, t8 INTEGER, t9 INTEGER, t10 INTEGER, touch1 REAL, touch2 REAL, touch3 REAL, touch4 REAL, touch5 REAL, touch6 REAL, touch7 REAL, touch8 REAL, touch9 REAL, touch10 REAL)"); add_structure("CREATE TABLE smem_augmentations (lti_id INTEGER, attribute_s_id INTEGER, value_constant_s_id INTEGER, value_lti_id INTEGER, activation_value REAL, edge_weight REAL)"); add_structure("CREATE TABLE smem_attribute_frequency (attribute_s_id INTEGER PRIMARY KEY, edge_frequency INTEGER)"); @@ -122,6 +123,7 @@ void smem_statement_container::drop_tables(agent* new_agent) new_agent->SMem->DB->sql_execute("DROP TABLE IF EXISTS smem_symbols_float"); new_agent->SMem->DB->sql_execute("DROP TABLE IF EXISTS smem_symbols_string"); new_agent->SMem->DB->sql_execute("DROP TABLE IF EXISTS smem_lti"); + new_agent->SMem->DB->sql_execute("DROP TABLE IF EXISTS smem_lti_alias"); new_agent->SMem->DB->sql_execute("DROP TABLE IF EXISTS smem_activation_history"); new_agent->SMem->DB->sql_execute("DROP TABLE IF EXISTS smem_augmentations"); new_agent->SMem->DB->sql_execute("DROP TABLE IF EXISTS smem_attribute_frequency"); @@ -232,6 +234,15 @@ smem_statement_container::smem_statement_container(agent* new_agent): soar_modul lti_get_t = new soar_module::sqlite_statement(new_db, "SELECT lti_id FROM smem_lti WHERE activations_last=?"); add(lti_get_t); + // lti aliases + + lti_alias_add = new soar_module::sqlite_statement(new_db, "INSERT INTO smem_lti_alias (alias, lti_id) VALUES (?,?)"); + add(lti_alias_add); + + lti_alias_get_id = new soar_module::sqlite_statement(new_db, "SELECT lti_id FROM smem_lti_alias WHERE alias=?"); + add(lti_alias_get_id); + + // web_add = new soar_module::sqlite_statement(new_db, "INSERT INTO smem_augmentations (lti_id, attribute_s_id, value_constant_s_id, value_lti_id, activation_value, edge_weight) VALUES (?,?,?,?,?,?)"); @@ -1422,3 +1433,43 @@ uint64_t SMem_Manager::add_specific_LTI(uint64_t lti_id) return lti_id; } + +/** Returns the id of the LTI associated with the given string alias + * (or NIL if it does not exist) **/ +uint64_t SMem_Manager::get_lti_with_alias(const std::string& lti_alias) { + uint64_t lti_id = NIL; + + // Check to see if the alias already exists in the db + SQL->lti_alias_get_id->bind_text(1, static_cast(lti_alias.c_str())); + if (SQL->lti_alias_get_id->execute() == soar_module::row) + { + lti_id = static_cast(SQL->lti_alias_get_id->column_int(0)); + } + SQL->lti_alias_get_id->reinitialize(); + + return lti_id; +} + +/** Creates a new LTI and associates it with the given string alias + * returns the id of the newly created LTI **/ +uint64_t SMem_Manager::add_new_lti_with_alias(const std::string& lti_alias) { + // Create a new LTI + uint64_t lti_id = add_new_LTI(); + + // Add the alias record to the db + SQL->lti_alias_add->bind_text(1, static_cast(lti_alias.c_str())); + SQL->lti_alias_add->bind_int(2, static_cast(lti_id)); + SQL->lti_alias_add->execute(soar_module::op_reinit); + + return lti_id; +} + +/** Returns the id of the LTI associated with the given string alias + * (or creates a new LTI if one does not already exist) **/ +uint64_t SMem_Manager::get_or_add_lti_with_alias(const std::string& lti_alias) { + uint64_t lti_id = get_lti_with_alias(lti_alias); + if (lti_id == NIL) { + lti_id = add_new_lti_with_alias(lti_alias); + } + return lti_id; +} diff --git a/Core/SoarKernel/src/semantic_memory/smem_db.h b/Core/SoarKernel/src/semantic_memory/smem_db.h index eba184f013..48a2548d76 100644 --- a/Core/SoarKernel/src/semantic_memory/smem_db.h +++ b/Core/SoarKernel/src/semantic_memory/smem_db.h @@ -44,6 +44,9 @@ class smem_statement_container: public soar_module::sqlite_statement_container soar_module::sqlite_statement* lti_access_set; soar_module::sqlite_statement* lti_get_t; + soar_module::sqlite_statement* lti_alias_add; + soar_module::sqlite_statement* lti_alias_get_id; + soar_module::sqlite_statement* web_add; soar_module::sqlite_statement* web_truncate; soar_module::sqlite_statement* web_expand; diff --git a/Core/SoarKernel/src/semantic_memory/smem_structs.h b/Core/SoarKernel/src/semantic_memory/smem_structs.h index de90e688e8..8d80d549e0 100644 --- a/Core/SoarKernel/src/semantic_memory/smem_structs.h +++ b/Core/SoarKernel/src/semantic_memory/smem_structs.h @@ -96,7 +96,7 @@ typedef std::unordered_map> smem_update_m // Mapping from constant string aliases to integer ids // for hard-coded LTIs in smem --add commands (such as @red) -typedef std::map alias_to_id_map; +typedef std::map lti_alias_to_id_map; typedef union ltm_value_union { From ab6814b78aae906ce173cfa8384d8e8bcc31d54f Mon Sep 17 00:00:00 2001 From: Aaron Mininger Date: Wed, 11 Sep 2024 11:15:03 -0400 Subject: [PATCH 3/4] Extended smem cli commands history, export, and visualize to include LTI alises --- Core/CLI/src/cli_smem.cpp | 16 ++++++++++++++++ Core/CLI/src/cli_visualize.cpp | 8 ++++++++ .../src/semantic_memory/smem_structs.h | 4 ---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Core/CLI/src/cli_smem.cpp b/Core/CLI/src/cli_smem.cpp index c0e1343b74..75e3bacbad 100644 --- a/Core/CLI/src/cli_smem.cpp +++ b/Core/CLI/src/cli_smem.cpp @@ -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) { @@ -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) { diff --git a/Core/CLI/src/cli_visualize.cpp b/Core/CLI/src/cli_visualize.cpp index be54a26124..464095eaea 100644 --- a/Core/CLI/src/cli_visualize.cpp +++ b/Core/CLI/src/cli_visualize.cpp @@ -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) { diff --git a/Core/SoarKernel/src/semantic_memory/smem_structs.h b/Core/SoarKernel/src/semantic_memory/smem_structs.h index 8d80d549e0..0df14efdee 100644 --- a/Core/SoarKernel/src/semantic_memory/smem_structs.h +++ b/Core/SoarKernel/src/semantic_memory/smem_structs.h @@ -94,10 +94,6 @@ typedef struct smem_edge_update_struct typedef std::unordered_map> smem_update_map; -// Mapping from constant string aliases to integer ids -// for hard-coded LTIs in smem --add commands (such as @red) -typedef std::map lti_alias_to_id_map; - typedef union ltm_value_union { struct ltm_value_const val_const; From 419e60b3869091bfcaa39b6d5bf9f3f3945272fd Mon Sep 17 00:00:00 2001 From: Aaron Mininger Date: Thu, 12 Sep 2024 09:02:33 -0400 Subject: [PATCH 4/4] Added support for printing LTI's by their alias: print @color --- Core/CLI/src/cli_print.cpp | 17 ++++++++++++----- .../src/semantic_memory/semantic_memory.h | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Core/CLI/src/cli_print.cpp b/Core/CLI/src/cli_print.cpp index 19f2ffba6c..6a0332e398 100644 --- a/Core/CLI/src/cli_print.cpp +++ b/Core/CLI/src/cli_print.cpp @@ -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(); diff --git a/Core/SoarKernel/src/semantic_memory/semantic_memory.h b/Core/SoarKernel/src/semantic_memory/semantic_memory.h index 8a1b57621d..c77dd1361c 100644 --- a/Core/SoarKernel/src/semantic_memory/semantic_memory.h +++ b/Core/SoarKernel/src/semantic_memory/semantic_memory.h @@ -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); @@ -162,7 +163,6 @@ class SMem_Manager id_set print_LTM(uint64_t pLTI_ID, double lti_act, std::string* return_val, std::list* history = NIL); /* Methods for LTI aliases */ - uint64_t get_lti_with_alias(const std::string& lti_alias); 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);