From 7ac00572f2edd9ec891ff5075475b81ee90d1994 Mon Sep 17 00:00:00 2001 From: marcocapozzoli Date: Tue, 26 May 2026 10:07:25 -0300 Subject: [PATCH 1/3] WIP --- src/db_adapter/ContextLoader.cc | 15 +- src/db_adapter/non_sql/Metta2AtomsMapper.cc | 70 ++++++++- src/db_adapter/non_sql/Metta2AtomsMapper.h | 8 +- src/db_adapter/non_sql/mork/BUILD | 1 + .../non_sql/mork/MorkMappingStrategy.cc | 57 ++++++- src/db_adapter/non_sql/mork/MorkWrapper.cc | 43 +++++- src/db_adapter/non_sql/mork/MorkWrapper.h | 5 +- src/tests/cpp/BUILD | 1 + src/tests/cpp/morkwrapper_test.cc | 143 ++++++++++++++++++ 9 files changed, 321 insertions(+), 22 deletions(-) create mode 100644 src/tests/cpp/morkwrapper_test.cc diff --git a/src/db_adapter/ContextLoader.cc b/src/db_adapter/ContextLoader.cc index 1a4c72f0..0d953219 100644 --- a/src/db_adapter/ContextLoader.cc +++ b/src/db_adapter/ContextLoader.cc @@ -47,6 +47,17 @@ vector ContextLoader::load_sql_queries(const string& file_path) { } vector ContextLoader::load_metta_queries(const string& file_path) { - RAISE_ERROR("ContextLoader::load_metta_queries() not implemented yet"); - return {}; + if (!fs::exists(file_path)) { + RAISE_ERROR("File " + file_path + " does not exist"); + } + + ifstream file(file_path); + + vector lines; + string line; + while (getline(file, line)) { + lines.push_back(line); + } + + return lines; } \ No newline at end of file diff --git a/src/db_adapter/non_sql/Metta2AtomsMapper.cc b/src/db_adapter/non_sql/Metta2AtomsMapper.cc index 5f43f93b..4f19c437 100644 --- a/src/db_adapter/non_sql/Metta2AtomsMapper.cc +++ b/src/db_adapter/non_sql/Metta2AtomsMapper.cc @@ -1,5 +1,9 @@ #include "Metta2AtomsMapper.h" +#include "Link.h" +#include "MettaParser.h" +#include "MettaParserActions.h" + #define LOG_LEVEL INFO_LEVEL #include "Logger.h" @@ -7,9 +11,8 @@ using namespace db_adapter; using namespace commons; using namespace atoms; -// ============================== +// --------------------------------------------------------------------------------------------- // Construction / destruction -// ============================== Metta2AtomsMapper::Metta2AtomsMapper() { RAISE_ERROR("Metta2AtomsMapper constructor not implemented yet"); @@ -17,11 +20,66 @@ Metta2AtomsMapper::Metta2AtomsMapper() { Metta2AtomsMapper::~Metta2AtomsMapper() {} -// ============================== +// --------------------------------------------------------------------------------------------- // Public -// ============================== const vector Metta2AtomsMapper::map(const DbInput& data) { - RAISE_ERROR("Metta2AtomsMapper::map() not implemented yet"); - return vector{}; + MettaExpression metta_expression = get(data); + + LOG_DEBUG("[Metta2AtomsMapper::map] Parsing MORK expression: " << metta_expression.expression); + + auto parser_actions = make_shared(); + MettaParser parser(metta_expression.expression, parser_actions); + parser.parse(); + + this->atoms.clear(); + + stack> element_stack = parser_actions->element_stack; + shared_ptr atom = element_stack.top(); + auto link_toplevel = dynamic_pointer_cast(atom); + + this->collect_atoms(this->atoms, link_toplevel->handle(), parser_actions); + +#if LOG_LEVEL >= DEBUG_LEVEL + LOG_DEBUG("The expression " << metta_expression.expression + << " has been mapped to the following atoms:"); + + for (const auto& atom : this->atoms) { + LOG_DEBUG("-> " << atom->to_string()); + } +#endif + + return this->atoms; +} + +void Metta2AtomsMapper::collect_atoms(vector& output, + const string& handle, + shared_ptr parser_actions) { + shared_ptr atom = parser_actions->handle_to_atom[handle]; + if (atom != nullptr) { + if (Atom::is_node(*atom)) { + output.push_back(atom.get()); + } else { + this->collect_atoms_recursive(output, dynamic_pointer_cast(atom), parser_actions); + } + } +} + +// --------------------------------------------------------------------------------------------- +// Private + +void Metta2AtomsMapper::collect_atoms_recursive(vector& output, + shared_ptr link, + shared_ptr parser_actions) { + for (string& target_handle : link->targets) { + shared_ptr atom = parser_actions->handle_to_atom[target_handle]; + if (atom != nullptr) { + if (Atom::is_node(*atom)) { + output.push_back(atom.get()); + } else { + this->collect_atoms_recursive(output, dynamic_pointer_cast(atom), parser_actions); + } + } + } + output.push_back(link.get()); } \ No newline at end of file diff --git a/src/db_adapter/non_sql/Metta2AtomsMapper.h b/src/db_adapter/non_sql/Metta2AtomsMapper.h index cc38be36..ba52ec85 100644 --- a/src/db_adapter/non_sql/Metta2AtomsMapper.h +++ b/src/db_adapter/non_sql/Metta2AtomsMapper.h @@ -6,6 +6,7 @@ #include "Atom.h" #include "DatabaseMapper.h" #include "DatabaseTypes.h" +#include "Link.h" #include "MettaMapping.h" #include "MettaParserActions.h" @@ -21,10 +22,15 @@ class Metta2AtomsMapper : public DatabaseMapper { ~Metta2AtomsMapper() override; const vector map(const DbInput& data) override; + void collect_atoms(vector& output, + const string& handle, + shared_ptr parser_actions); private: vector atoms; - shared_ptr parser_actions; + void collect_atoms_recursive(vector& output, + shared_ptr link, + shared_ptr parser_actions); }; } // namespace db_adapter \ No newline at end of file diff --git a/src/db_adapter/non_sql/mork/BUILD b/src/db_adapter/non_sql/mork/BUILD index da674241..e792545b 100644 --- a/src/db_adapter/non_sql/mork/BUILD +++ b/src/db_adapter/non_sql/mork/BUILD @@ -47,6 +47,7 @@ cc_library( deps = [ ":mork_wrapper", "//commons:commons_lib", + "//db_adapter:context_loader", "//db_adapter:database_mapping_strategy", ], ) diff --git a/src/db_adapter/non_sql/mork/MorkMappingStrategy.cc b/src/db_adapter/non_sql/mork/MorkMappingStrategy.cc index 055630d8..5344425e 100644 --- a/src/db_adapter/non_sql/mork/MorkMappingStrategy.cc +++ b/src/db_adapter/non_sql/mork/MorkMappingStrategy.cc @@ -1,8 +1,16 @@ #include "MorkMappingStrategy.h" +#include + +#include "ContextLoader.h" +#include "Utils.h" + using namespace std; +using namespace commons; using namespace db_adapter; +namespace fs = std::filesystem; + // ============================== // Construction / destruction // ============================== @@ -11,7 +19,7 @@ db_adapter::MorkMappingStrategy::MorkMappingStrategy(const JsonConfig& config, shared_ptr conn, shared_ptr queue) : DatabaseMappingStrategy(conn), config(config) { - this->wrapper = make_shared(*conn, queue); + this->wrapper = make_shared(conn, queue); } // ============================== @@ -19,11 +27,50 @@ db_adapter::MorkMappingStrategy::MorkMappingStrategy(const JsonConfig& config, // ============================ vector MorkMappingStrategy::create_tasks() { - RAISE_ERROR("MorkMappingStrategy::create_tasks() not implemented yet"); - return vector{}; + vector file_paths = + this->config.at_path("adapterdb.context_mapping_paths").get_or>({}); + + vector tasks; + + if (file_paths.empty()) { + LOG_INFO( + "No context mapping files specified in config at adapterdb.context_mapping_paths. The " + "entire database will be mapped."); + tasks.push_back(MappingTask{"map_all_database", nullopt}); + } else { + for (const auto& path : file_paths) { + fs::path p(path); + string ext = p.extension().string(); + + if (ext != ".metta") { + RAISE_ERROR("Unsupported mapping file type: " + ext + " for file: " + path); + } + + auto queries_metta = ContextLoader::load_metta_queries(path); + + if (!queries_metta.empty()) { + for (size_t i = 0; i < queries_metta.size(); i++) { + LOG_DEBUG("Query " << (i + 1) << ": " << queries_metta[i]); + tasks.push_back(MappingTask{"custom_query_" + to_string(i), queries_metta[i]}); + } + } + + LOG_DEBUG(to_string(queries_metta.size()) + " queries were loaded from the query file."); + } + } + return tasks; } void MorkMappingStrategy::execute_task(const MappingTask& task) { - RAISE_ERROR("MorkMappingStrategy::execute_task() not implemented yet"); - return; + string query = ""; + + if (task.context == nullopt) { + LOG_DEBUG("Executing task: " << task.task_name << " with no specific query context"); + query = "$all"; + } else { + LOG_DEBUG("Executing task: " << task.task_name + << " with query context: " << task.context.value()); + query = task.context.value(); + } + this->wrapper->map(query); } diff --git a/src/db_adapter/non_sql/mork/MorkWrapper.cc b/src/db_adapter/non_sql/mork/MorkWrapper.cc index 08e16bdd..673d553a 100644 --- a/src/db_adapter/non_sql/mork/MorkWrapper.cc +++ b/src/db_adapter/non_sql/mork/MorkWrapper.cc @@ -14,16 +14,47 @@ using namespace db_adapter; // Construction / destruction // ============================== -MorkWrapper::MorkWrapper(MorkConnection& conn, +MorkWrapper::MorkWrapper(shared_ptr conn, shared_ptr output_queue, MAPPER_TYPE mapper_type) - : DatabaseWrapper(conn, MapperFactory::create(mapper_type)), conn(conn), output_queue(output_queue) { - RAISE_ERROR("MorkWrapper constructor not implemented yet"); -} + : DatabaseWrapper(*conn, MapperFactory::create(mapper_type)), + conn(conn), + output_queue(output_queue) {} MorkWrapper::~MorkWrapper() {} void MorkWrapper::map(const string& metta_query) { - RAISE_ERROR("MorkWrapper::map() not implemented yet"); - return; + vector metta_expressions = this->conn->query(metta_query); + + if (metta_expressions.empty()) { + RAISE_ERROR("No results returned from MORK query: " + metta_query); + } + + for (const auto& expr : metta_expressions) { + LOG_DEBUG("Mapping MORK expression: " << expr); + + vector atoms; + + try { + MettaExpression metta_expr{expr}; + atoms = this->mapper->map(DbInput{metta_expr}); + LOG_DEBUG("Mapped " << atoms.size() << " atoms from MORK expression"); + } catch (const exception& e) { + RAISE_ERROR("Error mapping MORK expression: " + expr + " : " + string(e.what())); + return; + } + + if (atoms.empty()) { + RAISE_ERROR("No atoms mapped from MORK expression: " + expr); + } + + std::queue* batch_queue = new std::queue(); + + for (const auto& atom : atoms) { + batch_queue->push(atom); + } + + unique_lock lock(this->api_mutex); + this->output_queue->enqueue((void*) batch_queue); + } } diff --git a/src/db_adapter/non_sql/mork/MorkWrapper.h b/src/db_adapter/non_sql/mork/MorkWrapper.h index 25a2b4d3..72daafa3 100644 --- a/src/db_adapter/non_sql/mork/MorkWrapper.h +++ b/src/db_adapter/non_sql/mork/MorkWrapper.h @@ -14,7 +14,7 @@ namespace db_adapter { class MorkWrapper : public DatabaseWrapper { public: - MorkWrapper(MorkConnection& conn, + MorkWrapper(shared_ptr conn, shared_ptr output_queue, MAPPER_TYPE mapper_type = MAPPER_TYPE::METTA2ATOMS); ~MorkWrapper(); @@ -22,7 +22,8 @@ class MorkWrapper : public DatabaseWrapper { void map(const string& metta_query); private: - MorkConnection& conn; + mutex api_mutex; + shared_ptr conn; shared_ptr output_queue; }; diff --git a/src/tests/cpp/BUILD b/src/tests/cpp/BUILD index db587a02..25dece17 100644 --- a/src/tests/cpp/BUILD +++ b/src/tests/cpp/BUILD @@ -892,6 +892,7 @@ cc_test( deps = [ "//atomdb:atomdb_singleton", "//db_adapter:db_adapter_lib", + "//metta:metta_lib", "//tests/cpp/test_commons:test_atomdb_json_config", "@com_github_google_googletest//:gtest_main", "@mbedtls", diff --git a/src/tests/cpp/morkwrapper_test.cc b/src/tests/cpp/morkwrapper_test.cc new file mode 100644 index 00000000..23333b1a --- /dev/null +++ b/src/tests/cpp/morkwrapper_test.cc @@ -0,0 +1,143 @@ +#include "MorkWrapper.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Atom.h" +#include "AtomDBAPITypes.h" +#include "AtomDBSingleton.h" +#include "BoundedSharedQueue.h" +#include "ContextLoader.h" +#include "DatabaseOrchestrator.h" +#include "DatabaseTypes.h" +#include "DedicatedThread.h" +#include "Logger.h" +#include "MettaParser.h" +#include "MettaParserActions.h" +#include "Node.h" +#include "Processor.h" +#include "TestAtomDBJsonConfig.h" + +using namespace std; +using namespace atomdb; +using namespace db_adapter; +using namespace atoms; +using namespace processor; + +class MorkWrapperTest : public ::testing::Test { + protected: + string TEST_HOST = "localhost"; + int TEST_PORT = 40022; + + string INVALID_HOST = "invalid.host"; + int INVALID_PORT = 99999; + + void SetUp() override{}; + + void TearDown() override { this->conn->stop(); }; + + unordered_set read_atoms_from_queue(shared_ptr q) { + unordered_set atom_handles; + + while (true) { + if (q->empty()) break; + void* raw_ptr = q->dequeue(); + std::queue* batch_queue = static_cast*>(raw_ptr); + + if (batch_queue != nullptr) { + while (!batch_queue->empty()) { + Atom* atom = batch_queue->front(); + batch_queue->pop(); + if (atom != nullptr) { + if (atom_handles.find(atom->handle()) == atom_handles.end()) { + atom_handles.insert(atom->handle()); + } + } + // delete atom; + } + delete batch_queue; + } + } + + return atom_handles; + }; + + shared_ptr create_wrapper(shared_ptr queue = nullptr) { + if (!queue) { + queue = make_shared(); + } + auto conn = create_db_connection(); + return make_shared(conn, queue); + }; + + shared_ptr create_db_connection() { + this->conn = make_shared("mork-test-conn", TEST_HOST, TEST_PORT); + this->conn->setup(); + this->conn->start(); + return this->conn; + }; + + shared_ptr conn; +}; + +TEST_F(MorkWrapperTest, MapInvalidQuery) { + auto queue = make_shared(); + auto wrapper = create_wrapper(queue); + + EXPECT_THROW({ wrapper->map("(Fake $F)"); }, runtime_error); +} + +TEST_F(MorkWrapperTest, MapNoAtomsMapped) { + auto queue = make_shared(); + auto wrapper = create_wrapper(queue); + + string metta_query = "(Similarity \"ent\" $y)"; + EXPECT_THROW({ wrapper->map(metta_query); }, runtime_error); +} + +TEST_F(MorkWrapperTest, Map) { + auto queue = make_shared(); + auto wrapper = create_wrapper(queue); + + vector metta_queries = {"(Similarity \"ent\" $x)"}; + + shared_ptr pa = make_shared(); + bool error_occurred = false; + int count = 0; + for (const auto& metta_query : metta_queries) { + count++; + try { + wrapper->map(metta_query); + } catch (const exception& e) { + LOG_ERROR("Erro na linha [" << count << "] expressao: [" << metta_query << "] - " + << e.what()); + error_occurred = true; + } + if (!error_occurred) { + LOG_INFO("Successfully mapped MORK query: " << metta_query); + } else { + LOG_ERROR("Error mapping MORK query: " << metta_query); + } + error_occurred = false; + } + + LOG_INFO("Mapped " << count << " MORK expressions"); + + unordered_set atoms = read_atoms_from_queue(queue); + + size_t expected_atom_count = 3; + ASSERT_EQ(atoms.size(), expected_atom_count); +} + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} From 0af6e88ed5021722d4179e3ef3d1941270a3f8e0 Mon Sep 17 00:00:00 2001 From: marcocapozzoli Date: Tue, 26 May 2026 12:17:29 -0300 Subject: [PATCH 2/3] Refactor Metta2AtomsMapper and MorkWrapper to use shared_ptr for Atom --- src/db_adapter/non_sql/Metta2AtomsMapper.cc | 12 +-- src/db_adapter/non_sql/Metta2AtomsMapper.h | 8 +- src/db_adapter/non_sql/mork/MorkWrapper.cc | 7 +- src/tests/cpp/morkwrapper_test.cc | 93 +++++++++++++-------- 4 files changed, 71 insertions(+), 49 deletions(-) diff --git a/src/db_adapter/non_sql/Metta2AtomsMapper.cc b/src/db_adapter/non_sql/Metta2AtomsMapper.cc index 30373691..8dd39902 100644 --- a/src/db_adapter/non_sql/Metta2AtomsMapper.cc +++ b/src/db_adapter/non_sql/Metta2AtomsMapper.cc @@ -21,7 +21,7 @@ Metta2AtomsMapper::~Metta2AtomsMapper() {} // --------------------------------------------------------------------------------------------- // Public -const vector Metta2AtomsMapper::map(const DbInput& data) { +vector> Metta2AtomsMapper::map(const DbInput& data) { MettaExpression metta_expression = get(data); LOG_DEBUG("[Metta2AtomsMapper::map] Parsing MORK expression: " << metta_expression.expression); @@ -50,13 +50,13 @@ const vector Metta2AtomsMapper::map(const DbInput& data) { return this->atoms; } -void Metta2AtomsMapper::collect_atoms(vector& output, +void Metta2AtomsMapper::collect_atoms(vector>& output, const string& handle, shared_ptr parser_actions) { shared_ptr atom = parser_actions->handle_to_atom[handle]; if (atom != nullptr) { if (Atom::is_node(*atom)) { - output.push_back(atom.get()); + output.push_back(atom); } else { this->collect_atoms_recursive(output, dynamic_pointer_cast(atom), parser_actions); } @@ -66,18 +66,18 @@ void Metta2AtomsMapper::collect_atoms(vector& output, // --------------------------------------------------------------------------------------------- // Private -void Metta2AtomsMapper::collect_atoms_recursive(vector& output, +void Metta2AtomsMapper::collect_atoms_recursive(vector>& output, shared_ptr link, shared_ptr parser_actions) { for (string& target_handle : link->targets) { shared_ptr atom = parser_actions->handle_to_atom[target_handle]; if (atom != nullptr) { if (Atom::is_node(*atom)) { - output.push_back(atom.get()); + output.push_back(atom); } else { this->collect_atoms_recursive(output, dynamic_pointer_cast(atom), parser_actions); } } } - output.push_back(link.get()); + output.push_back(link); } \ No newline at end of file diff --git a/src/db_adapter/non_sql/Metta2AtomsMapper.h b/src/db_adapter/non_sql/Metta2AtomsMapper.h index ba52ec85..3e05631f 100644 --- a/src/db_adapter/non_sql/Metta2AtomsMapper.h +++ b/src/db_adapter/non_sql/Metta2AtomsMapper.h @@ -21,14 +21,14 @@ class Metta2AtomsMapper : public DatabaseMapper { Metta2AtomsMapper(); ~Metta2AtomsMapper() override; - const vector map(const DbInput& data) override; - void collect_atoms(vector& output, + vector> map(const DbInput& data) override; + void collect_atoms(vector>& output, const string& handle, shared_ptr parser_actions); private: - vector atoms; - void collect_atoms_recursive(vector& output, + vector> atoms; + void collect_atoms_recursive(vector>& output, shared_ptr link, shared_ptr parser_actions); }; diff --git a/src/db_adapter/non_sql/mork/MorkWrapper.cc b/src/db_adapter/non_sql/mork/MorkWrapper.cc index 2ce668f5..8573c679 100644 --- a/src/db_adapter/non_sql/mork/MorkWrapper.cc +++ b/src/db_adapter/non_sql/mork/MorkWrapper.cc @@ -34,12 +34,12 @@ void MorkWrapper::map(const string& metta_query) { for (const auto& expr : metta_expressions) { LOG_DEBUG("Mapping MORK expression: " << expr); - vector atoms; + vector> atoms; try { MettaExpression metta_expr{expr}; atoms = this->mapper->map(DbInput{metta_expr}); - LOG_DEBUG("Mapped " << atoms.size() << " atoms from MORK expression"); + LOG_INFO("Mapped " << atoms.size() << " atoms from MORK expression"); } catch (const exception& e) { RAISE_ERROR("Error mapping MORK expression: " + expr + " : " + string(e.what())); return; @@ -49,9 +49,10 @@ void MorkWrapper::map(const string& metta_query) { RAISE_ERROR("No atoms mapped from MORK expression: " + expr); } - std::queue* batch_queue = new std::queue(); + std::queue>* batch_queue = new std::queue>(); for (const auto& atom : atoms) { + LOG_INFO("Insert into the queue: " << atom->to_string()); batch_queue->push(atom); } diff --git a/src/tests/cpp/morkwrapper_test.cc b/src/tests/cpp/morkwrapper_test.cc index 23333b1a..edf293fe 100644 --- a/src/tests/cpp/morkwrapper_test.cc +++ b/src/tests/cpp/morkwrapper_test.cc @@ -44,30 +44,29 @@ class MorkWrapperTest : public ::testing::Test { void TearDown() override { this->conn->stop(); }; - unordered_set read_atoms_from_queue(shared_ptr q) { - unordered_set atom_handles; + vector> read_atoms_from_queue(shared_ptr q) { + vector> atoms; while (true) { if (q->empty()) break; void* raw_ptr = q->dequeue(); - std::queue* batch_queue = static_cast*>(raw_ptr); + std::queue>* batch_queue = + static_cast>*>(raw_ptr); if (batch_queue != nullptr) { while (!batch_queue->empty()) { - Atom* atom = batch_queue->front(); + shared_ptr atom = batch_queue->front(); batch_queue->pop(); if (atom != nullptr) { - if (atom_handles.find(atom->handle()) == atom_handles.end()) { - atom_handles.insert(atom->handle()); - } + LOG_INFO("Read atom from queue: " << atom->to_string()); + atoms.push_back(atom); } - // delete atom; } delete batch_queue; } } - return atom_handles; + return atoms; }; shared_ptr create_wrapper(shared_ptr queue = nullptr) { @@ -88,53 +87,75 @@ class MorkWrapperTest : public ::testing::Test { shared_ptr conn; }; -TEST_F(MorkWrapperTest, MapInvalidQuery) { +TEST_F(MorkWrapperTest, MapNoResults) { auto queue = make_shared(); auto wrapper = create_wrapper(queue); EXPECT_THROW({ wrapper->map("(Fake $F)"); }, runtime_error); } -TEST_F(MorkWrapperTest, MapNoAtomsMapped) { +TEST_F(MorkWrapperTest, MapSuccess) { auto queue = make_shared(); auto wrapper = create_wrapper(queue); - string metta_query = "(Similarity \"ent\" $y)"; - EXPECT_THROW({ wrapper->map(metta_query); }, runtime_error); -} - -TEST_F(MorkWrapperTest, Map) { - auto queue = make_shared(); - auto wrapper = create_wrapper(queue); - - vector metta_queries = {"(Similarity \"ent\" $x)"}; + vector metta_queries = { + "(Similarity \"ent\" $h)", + "(Inheritance \"human\" $m)", + }; - shared_ptr pa = make_shared(); - bool error_occurred = false; - int count = 0; for (const auto& metta_query : metta_queries) { - count++; try { wrapper->map(metta_query); + LOG_DEBUG("Successfully mapped MORK query: " << metta_query); } catch (const exception& e) { - LOG_ERROR("Erro na linha [" << count << "] expressao: [" << metta_query << "] - " - << e.what()); - error_occurred = true; - } - if (!error_occurred) { - LOG_INFO("Successfully mapped MORK query: " << metta_query); - } else { LOG_ERROR("Error mapping MORK query: " << metta_query); } - error_occurred = false; } - LOG_INFO("Mapped " << count << " MORK expressions"); - - unordered_set atoms = read_atoms_from_queue(queue); + vector> atoms = read_atoms_from_queue(queue); - size_t expected_atom_count = 3; + size_t expected_atom_count = 8; ASSERT_EQ(atoms.size(), expected_atom_count); + + vector ordered_handles; + vector> nodes; + vector> links; + for (const auto& atom : atoms) { + ordered_handles.push_back(atom->to_string()); + if (atom->arity() == 0) { + nodes.push_back(dynamic_pointer_cast(atom)); + } else { + links.push_back(dynamic_pointer_cast(atom)); + } + } + + ASSERT_EQ(nodes.size(), 6); + ASSERT_EQ(links.size(), 2); + + shared_ptr node_human = make_shared("Symbol", "\"human\""); + shared_ptr node_ent = make_shared("Symbol", "\"ent\""); + shared_ptr node_mammal = make_shared("Symbol", "\"mammal\""); + shared_ptr node_similarity = make_shared("Symbol", "Similarity"); + shared_ptr node_inheritance = make_shared("Symbol", "Inheritance"); + shared_ptr link_similarity_ent_human = make_shared( + "Expression", + vector{node_similarity->handle(), node_ent->handle(), node_human->handle()}, + true); + shared_ptr link_inheritance_human_mammal = make_shared( + "Expression", + vector{node_inheritance->handle(), node_human->handle(), node_mammal->handle()}, + true); + + vector expected_ordered_handle = {node_similarity->to_string(), + node_ent->to_string(), + node_human->to_string(), + link_similarity_ent_human->to_string(), + node_inheritance->to_string(), + node_human->to_string(), + node_mammal->to_string(), + link_inheritance_human_mammal->to_string()}; + + ASSERT_EQ(ordered_handles, expected_ordered_handle); } int main(int argc, char** argv) { From 8af4d3b8025e549f98984cc36505cf143410e6f0 Mon Sep 17 00:00:00 2001 From: marcocapozzoli Date: Tue, 26 May 2026 12:21:10 -0300 Subject: [PATCH 3/3] Change log level --- src/db_adapter/non_sql/mork/MorkWrapper.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db_adapter/non_sql/mork/MorkWrapper.cc b/src/db_adapter/non_sql/mork/MorkWrapper.cc index 8573c679..e8484f5b 100644 --- a/src/db_adapter/non_sql/mork/MorkWrapper.cc +++ b/src/db_adapter/non_sql/mork/MorkWrapper.cc @@ -39,7 +39,7 @@ void MorkWrapper::map(const string& metta_query) { try { MettaExpression metta_expr{expr}; atoms = this->mapper->map(DbInput{metta_expr}); - LOG_INFO("Mapped " << atoms.size() << " atoms from MORK expression"); + LOG_DEBUG("Mapped " << atoms.size() << " atoms from MORK expression"); } catch (const exception& e) { RAISE_ERROR("Error mapping MORK expression: " + expr + " : " + string(e.what())); return;