From ddbc1620f00bdb3fd5dadcf4d2770cf6975edafb Mon Sep 17 00:00:00 2001 From: Anna Makarenko Date: Tue, 17 Sep 2024 07:22:35 +0300 Subject: [PATCH 1/9] [refactor] Update agents API --- CMakeLists.txt | 1 - dependencies.cmake | 2 - .../problem-solver/cxx/.gitignore | 2 - .../cxx/identifiers-module/CMakeLists.txt | 3 - ...ain_system_idtfs_from_sc_to_file_agent.cpp | 86 +++++++++------ ...ain_system_idtfs_from_sc_to_file_agent.hpp | 13 +-- .../identifiers-module/identifiers_module.cpp | 30 +---- .../identifiers-module/identifiers_module.hpp | 8 -- .../keynodes/identifiers_keynodes.cpp | 15 --- .../keynodes/identifiers_keynodes.hpp | 11 +- .../cxx/sections-module/CMakeLists.txt | 3 - .../agent/add_section_agent.cpp | 103 +++++++++--------- .../agent/add_section_agent.hpp | 14 +-- .../agent/get_decomposition_agent.cpp | 80 +++++++------- .../agent/get_decomposition_agent.hpp | 15 +-- .../agent/remove_section_agent.cpp | 99 +++++++++-------- .../agent/remove_section_agent.hpp | 14 +-- .../builder/sections_builder.cpp | 6 +- .../keynodes/sections_keynodes.cpp | 24 ---- .../keynodes/sections_keynodes.hpp | 43 +++----- .../sections-module/subject_domain_module.cpp | 26 +---- .../sections-module/subject_domain_module.hpp | 8 -- .../sections-module/utils/sections_utils.cpp | 3 +- .../sections-module/utils/sections_utils.hpp | 2 - 24 files changed, 243 insertions(+), 368 deletions(-) delete mode 100644 platform-dependent-components/problem-solver/cxx/.gitignore delete mode 100644 platform-dependent-components/problem-solver/cxx/identifiers-module/keynodes/identifiers_keynodes.cpp delete mode 100644 platform-dependent-components/problem-solver/cxx/sections-module/keynodes/sections_keynodes.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 460feffe..19f051a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,6 @@ link_directories(${SC_BIN_PATH} ${SC_EXTENSIONS_DIRECTORY}) set(SC_MACHINE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/ostis-web-platform/sc-machine") set(CMAKE_MODULE_PATH "${SC_MACHINE_PATH}/cmake") -include("${CMAKE_MODULE_PATH}/codegen.cmake") if(${SC_CLANG_FORMAT_CODE}) include(${CMAKE_MODULE_PATH}/ClangFormat.cmake) diff --git a/dependencies.cmake b/dependencies.cmake index 1f9890ec..e646c8bc 100644 --- a/dependencies.cmake +++ b/dependencies.cmake @@ -9,8 +9,6 @@ macro(sc_target_dependencies) endmacro() macro(sc_linux_target_dependencies) - set(SC_CODEGEN_TOOL "${SC_BIN_PATH}/sc-code-generator") - find_package(nlohmann_json 3.2.0 REQUIRED) # for std::thread support diff --git a/platform-dependent-components/problem-solver/cxx/.gitignore b/platform-dependent-components/problem-solver/cxx/.gitignore deleted file mode 100644 index 15284d40..00000000 --- a/platform-dependent-components/problem-solver/cxx/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -lib -**/generated diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/CMakeLists.txt b/platform-dependent-components/problem-solver/cxx/identifiers-module/CMakeLists.txt index 2a4a136c..06c07805 100755 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/CMakeLists.txt +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/CMakeLists.txt @@ -3,7 +3,6 @@ set(IDENTIFIERS_MODULE_SRC "${CMAKE_CURRENT_LIST_DIR}") set(SOURCES "agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp" "agent/translate_main_system_idtfs_from_sc_to_file_agent.hpp" - "keynodes/identifiers_keynodes.cpp" "keynodes/identifiers_keynodes.hpp" "identifiers_module.cpp" "identifiers_module.hpp" @@ -20,8 +19,6 @@ target_include_directories(identifiers-module PUBLIC ${SC_KPM_SRC} ) -sc_codegen_ex(identifiers-module ${IDENTIFIERS_MODULE_SRC} ${IDENTIFIERS_MODULE_SRC}/generated) - if(${SC_CLANG_FORMAT_CODE}) target_clangformat_setup(identifiers-module) endif() diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp index 7897c024..d3e40dfe 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp @@ -5,28 +5,27 @@ */ #include "sc-agents-common/utils/CommonUtils.hpp" -#include "sc-agents-common/utils/AgentUtils.hpp" #include "keynodes/identifiers_keynodes.hpp" #include "translate_main_system_idtfs_from_sc_to_file_agent.hpp" using namespace identifiersModule; -SC_AGENT_IMPLEMENTATION(TranslateMainSystemIdtfsFromScToFileAgent) +ScResult TranslateMainSystemIdtfsFromScToFileAgent::DoProgram(ScActionInitiatedEvent const & event, ScAction & action) { - ScAddr const & actionAddr = otherAddr; + ScAddr const & actionAddr = event.GetOtherElement(); if (!CheckAction(actionAddr)) - return SC_RESULT_OK; + return action.FinishSuccessfully(); SC_LOG_DEBUG("TranslateMainSystemIdtfsFromScToFileAgent started"); - // TODO: replace by CoreKeynodes::nrel_system_identifier after release - ScAddr const & nrelSystemIdtf = m_memoryCtx.HelperFindBySystemIdtf("nrel_system_identifier"); + // TODO: replace by ScKeynodes::nrel_system_identifier after release + ScAddr const & nrelSystemIdtf = m_context.HelperFindBySystemIdtf("nrel_system_identifier"); std::stringstream streamIdtfs; ScIterator3Ptr const & iterator3PtrEdgeBelongsToNrelSystemIdtf = - m_memoryCtx.Iterator3(nrelSystemIdtf, ScType::EdgeAccessConstPosPerm, ScType::EdgeDCommonConst); + m_context.Iterator3(nrelSystemIdtf, ScType::EdgeAccessConstPosPerm, ScType::EdgeDCommonConst); ScAddr edgeBelongsToNrelSystemIdtf; ScAddr sourceOfEdgeBelongsToNrelSystemIdtf; @@ -38,29 +37,38 @@ SC_AGENT_IMPLEMENTATION(TranslateMainSystemIdtfsFromScToFileAgent) while (iterator3PtrEdgeBelongsToNrelSystemIdtf->Next()) { edgeBelongsToNrelSystemIdtf = iterator3PtrEdgeBelongsToNrelSystemIdtf->Get(2); - sourceOfEdgeBelongsToNrelSystemIdtf = m_memoryCtx.GetEdgeSource(edgeBelongsToNrelSystemIdtf); + sourceOfEdgeBelongsToNrelSystemIdtf = m_context.GetEdgeSource(edgeBelongsToNrelSystemIdtf); try { - systemIdentifier = GetSystemIdtfAndVerifyNode(m_memoryCtx, sourceOfEdgeBelongsToNrelSystemIdtf); - mainIdentifier = GetMainIdtfAndVerifyNode(m_memoryCtx, sourceOfEdgeBelongsToNrelSystemIdtf); + systemIdentifier = GetSystemIdtfAndVerifyNode(m_context, sourceOfEdgeBelongsToNrelSystemIdtf); + mainIdentifier = GetMainIdtfAndVerifyNode(m_context, sourceOfEdgeBelongsToNrelSystemIdtf); stringType = GetStrScType(sourceOfEdgeBelongsToNrelSystemIdtf); if (!systemIdentifier.empty() && !mainIdentifier.empty() && !stringType.empty()) { - streamIdtfs << "{\"" << mainIdentifier << "\", " - << "{\"" << systemIdentifier << "\", \"" << stringType << "\"}},\n"; + streamIdtfs << R"({")" + << mainIdentifier << + R"(", )" + << R"({")" + << systemIdentifier << + R"(", ")" + << stringType << + R"("}},\n)"; } } catch (utils::ScException const & exception) { SC_LOG_ERROR(exception.Description()); - utils::AgentUtils::finishAgentWork(&m_memoryCtx, actionAddr, false); - return SC_RESULT_ERROR; + + ScStructure result = m_context.GenerateStructure(); + result << actionAddr; + action.SetResult(false); + return action.FinishUnsuccessfully(); } } std::string strIdtfs(streamIdtfs.str()); - // Remove last symbols "," and "\n" + // Remove last symbols "," and "n" if (!strIdtfs.empty()) { strIdtfs.pop_back(); @@ -73,76 +81,81 @@ SC_AGENT_IMPLEMENTATION(TranslateMainSystemIdtfsFromScToFileAgent) bool const & resultOfWrite = WriteInFile(strIdtfs); if (resultOfWrite) + { SC_LOG_DEBUG("File has been created"); + SC_LOG_DEBUG("TranslateMainSystemIdtfsFromScToFileAgent finished"); + return action.FinishSuccessfully(); + } else + { SC_LOG_ERROR("File hasn't been created"); - utils::AgentUtils::finishAgentWork(&m_memoryCtx, actionAddr, resultOfWrite); - SC_LOG_DEBUG("TranslateMainSystemIdtfsFromScToFileAgent finished"); - return SC_RESULT_OK; + SC_LOG_DEBUG("TranslateMainSystemIdtfsFromScToFileAgent finished"); + return action.FinishUnsuccessfully(); + } +} + +ScAddr TranslateMainSystemIdtfsFromScToFileAgent::GetActionClass() const +{ + return IdentifiersKeynodes::action_find_identifiers; } bool TranslateMainSystemIdtfsFromScToFileAgent::CheckAction(ScAddr const & actionAddr) { - return m_memoryCtx.HelperCheckEdge( + return m_context.HelperCheckEdge( IdentifiersKeynodes::action_find_identifiers, actionAddr, ScType::EdgeAccessConstPosPerm); } std::string TranslateMainSystemIdtfsFromScToFileAgent::GetSystemIdtfAndVerifyNode( - ScMemoryContext & m_memoryCtx, + ScMemoryContext & m_context, ScAddr const & node) { std::string identifier; ScAddr identifierLink; - ScIterator5Ptr const & iterator5PtrCheckOnlyOneIdtf = m_memoryCtx.Iterator5( + ScIterator5Ptr const & iterator5PtrCheckOnlyOneIdtf = m_context.Iterator5( node, ScType::EdgeDCommonConst, ScType::LinkConst, ScType::EdgeAccessConstPosPerm, - m_memoryCtx.HelperFindBySystemIdtf("nrel_system_identifier")); + m_context.HelperFindBySystemIdtf("nrel_system_identifier")); if (iterator5PtrCheckOnlyOneIdtf->Next()) { identifierLink = iterator5PtrCheckOnlyOneIdtf->Get(2); if (iterator5PtrCheckOnlyOneIdtf->Next()) SC_THROW_EXCEPTION(utils::ScException, "You have more than one system identifier for " + identifier); - m_memoryCtx.GetLinkContent(identifierLink, identifier); + m_context.GetLinkContent(identifierLink, identifier); } return identifier; } std::string TranslateMainSystemIdtfsFromScToFileAgent::GetMainIdtfAndVerifyNode( - ScMemoryContext & m_memoryCtx, + ScMemoryContext & m_context, ScAddr const & node) { std::string identifier; ScAddr mainIdentifierLink; ScAddr mainAnotherIdentifierLink; - ScIterator5Ptr const & iterator5PtrCheckOnlyOneIdtf = m_memoryCtx.Iterator5( - node, - ScType::EdgeDCommonConst, - ScType::LinkConst, - ScType::EdgeAccessConstPosPerm, - scAgentsCommon::CoreKeynodes::nrel_main_idtf); + ScIterator5Ptr const & iterator5PtrCheckOnlyOneIdtf = m_context.Iterator5( + node, ScType::EdgeDCommonConst, ScType::LinkConst, ScType::EdgeAccessConstPosPerm, ScKeynodes::nrel_main_idtf); bool isLangRu; while (iterator5PtrCheckOnlyOneIdtf->Next()) { mainIdentifierLink = iterator5PtrCheckOnlyOneIdtf->Get(2); - isLangRu = m_memoryCtx.HelperCheckEdge( - scAgentsCommon::CoreKeynodes::lang_ru, mainIdentifierLink, ScType::EdgeAccessConstPosPerm); + isLangRu = m_context.HelperCheckEdge(ScKeynodes::lang_ru, mainIdentifierLink, ScType::EdgeAccessConstPosPerm); if (isLangRu) { while (iterator5PtrCheckOnlyOneIdtf->Next()) { mainAnotherIdentifierLink = iterator5PtrCheckOnlyOneIdtf->Get(2); - isLangRu = m_memoryCtx.HelperCheckEdge( - scAgentsCommon::CoreKeynodes::lang_ru, mainAnotherIdentifierLink, ScType::EdgeAccessConstPosPerm); + isLangRu = + m_context.HelperCheckEdge(ScKeynodes::lang_ru, mainAnotherIdentifierLink, ScType::EdgeAccessConstPosPerm); if (isLangRu) return identifier; } - m_memoryCtx.GetLinkContent(mainIdentifierLink, identifier); + m_context.GetLinkContent(mainIdentifierLink, identifier); break; } } @@ -152,7 +165,7 @@ std::string TranslateMainSystemIdtfsFromScToFileAgent::GetMainIdtfAndVerifyNode( std::string TranslateMainSystemIdtfsFromScToFileAgent::GetStrScType(ScAddr const & node) { std::string strType; - ScType const & type = m_memoryCtx.GetElementType(node); + ScType const & type = m_context.GetElementType(node); if (ScTypesOfNodesWithSCsClasses.count(type)) strType = ScTypesOfNodesWithSCsClasses[type]; else if (ScTypesOfEdgesWithSCsClasses.count(type)) @@ -164,6 +177,7 @@ bool TranslateMainSystemIdtfsFromScToFileAgent::WriteInFile(std::string const & { try { + SC_LOG_INFO(IDENTIFIERS_MODULE_PATH); std::ofstream file(IDENTIFIERS_MODULE_PATH "identifiers.txt"); if (file.is_open()) { diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.hpp b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.hpp index 47e99077..6536cec5 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.hpp +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.hpp @@ -6,17 +6,16 @@ #pragma once -#include "sc-memory/kpm/sc_agent.hpp" -#include "sc-agents-common/keynodes/coreKeynodes.hpp" - -#include "translate_main_system_idtfs_from_sc_to_file_agent.generated.hpp" +#include namespace identifiersModule { -class TranslateMainSystemIdtfsFromScToFileAgent : public ScAgent +class TranslateMainSystemIdtfsFromScToFileAgent : public ScActionInitiatedAgent { - SC_CLASS(Agent, Event(scAgentsCommon::CoreKeynodes::question_initiated, ScEvent::Type::AddOutputEdge)) - SC_GENERATED_BODY() +public: + ScAddr GetActionClass() const override; + + ScResult DoProgram(ScActionInitiatedEvent const & event, ScAction & action) override; std::map ScTypesOfNodesWithSCsClasses = { {ScType::Const, "sc_node"}, diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/identifiers_module.cpp b/platform-dependent-components/problem-solver/cxx/identifiers-module/identifiers_module.cpp index ab3d489b..454d51c6 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/identifiers_module.cpp +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/identifiers_module.cpp @@ -11,32 +11,4 @@ using namespace identifiersModule; -SC_IMPLEMENT_MODULE(IdentifiersModule) - -sc_result IdentifiersModule::InitializeImpl() -{ - if (!IdentifiersModule::InitGlobal()) - { - SC_LOG_ERROR("IdentifiersModule is deactivated"); - return SC_RESULT_ERROR; - } - - if (!IdentifiersKeynodes::InitGlobal()) - { - SC_LOG_ERROR("IdentifiersKeynodes is deactivated"); - return SC_RESULT_ERROR; - } - else - { - SC_AGENT_REGISTER(TranslateMainSystemIdtfsFromScToFileAgent); - } - - return SC_RESULT_OK; -} - -sc_result IdentifiersModule::ShutdownImpl() -{ - SC_AGENT_UNREGISTER(TranslateMainSystemIdtfsFromScToFileAgent); - - return SC_RESULT_OK; -} +SC_MODULE_REGISTER(IdentifiersModule)->Agent(); diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/identifiers_module.hpp b/platform-dependent-components/problem-solver/cxx/identifiers-module/identifiers_module.hpp index c6ef5e7f..bf5fd4ca 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/identifiers_module.hpp +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/identifiers_module.hpp @@ -8,19 +8,11 @@ #include "sc-memory/sc_module.hpp" -#include "identifiers_module.generated.hpp" - namespace identifiersModule { class IdentifiersModule : public ScModule { - SC_CLASS(LoadOrder(100)) - SC_GENERATED_BODY() - - sc_result InitializeImpl() override; - - sc_result ShutdownImpl() override; }; } // namespace identifiersModule diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/keynodes/identifiers_keynodes.cpp b/platform-dependent-components/problem-solver/cxx/identifiers-module/keynodes/identifiers_keynodes.cpp deleted file mode 100644 index b2f76bae..00000000 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/keynodes/identifiers_keynodes.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * This source file is part of an OSTIS project. For the latest info, see http://ostis.net - * Distributed under the MIT License - * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) - */ - -#include "identifiers_keynodes.hpp" - -#include "sc-memory/sc_memory.hpp" - -namespace identifiersModule -{ -ScAddr IdentifiersKeynodes::action_find_identifiers; - -} // namespace identifiersModule diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/keynodes/identifiers_keynodes.hpp b/platform-dependent-components/problem-solver/cxx/identifiers-module/keynodes/identifiers_keynodes.hpp index b9c36f7d..9ec63684 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/keynodes/identifiers_keynodes.hpp +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/keynodes/identifiers_keynodes.hpp @@ -5,23 +5,18 @@ */ #pragma once +#include #include "sc-memory/sc_addr.hpp" #include "sc-memory/sc_object.hpp" -#include "identifiers_keynodes.generated.hpp" - namespace identifiersModule { -class IdentifiersKeynodes : public ScObject +class IdentifiersKeynodes : public ScKeynodes { - SC_CLASS() - SC_GENERATED_BODY() - public: - SC_PROPERTY(Keynode("action_find_identifiers"), ForceCreate) - static ScAddr action_find_identifiers; + static inline ScKeynode const action_find_identifiers{"action_find_identifiers"}; }; } // namespace identifiersModule diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/CMakeLists.txt b/platform-dependent-components/problem-solver/cxx/sections-module/CMakeLists.txt index 569e3e30..b4462558 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/CMakeLists.txt +++ b/platform-dependent-components/problem-solver/cxx/sections-module/CMakeLists.txt @@ -21,7 +21,6 @@ set(SOURCES "builder/sections_builder.cpp" "constants/sections_aliases.cpp" "generator/sections_generator.cpp" - "keynodes/sections_keynodes.cpp" "utils/set_utils.cpp" "utils/sections_utils.cpp" ) @@ -37,8 +36,6 @@ target_include_directories(sections-module PUBLIC ${SC_KPM_SRC} ) -sc_codegen_ex(sections-module ${SECTIONS_MODULE_SRC} ${SECTIONS_MODULE_SRC}/generated) - if(${SC_CLANG_FORMAT_CODE}) target_clangformat_setup(sections-module) endif() diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp index 3330ebd6..2acbba4c 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp @@ -4,8 +4,6 @@ * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) */ -#include "sc-agents-common/keynodes/coreKeynodes.hpp" -#include "sc-agents-common/utils/AgentUtils.hpp" #include "sc-agents-common/utils/IteratorUtils.hpp" #include "sc-agents-common/utils/GenerationUtils.hpp" @@ -18,63 +16,66 @@ #include "add_section_agent.hpp" -using namespace scAgentsCommon; using namespace utils; namespace sectionsModule { -SC_AGENT_IMPLEMENTATION(AddSectionAgent) +ScResult AddSectionAgent::DoProgram(ScActionInitiatedEvent const & event, ScAction & action) { - ScAddr const & questionNode = m_memoryCtx.GetEdgeTarget(edgeAddr); + ScAddr const & questionNode = m_context.GetEdgeTarget(event.GetArc()); if (!CheckActionClass(questionNode)) - return SC_RESULT_OK; + return action.FinishSuccessfully(); SC_LOG_DEBUG("AddSectionAgent started"); - ScAddr sectionNameAddr = - IteratorUtils::getAnyByOutRelation(&m_memoryCtx, questionNode, scAgentsCommon::CoreKeynodes::rrel_1); - ScAddr parentSectionAddr = - IteratorUtils::getAnyByOutRelation(&m_memoryCtx, questionNode, scAgentsCommon::CoreKeynodes::rrel_2); - ScAddr langAddr = - IteratorUtils::getAnyByOutRelation(&m_memoryCtx, questionNode, scAgentsCommon::CoreKeynodes::rrel_3); + ScAddr sectionNameAddr = IteratorUtils::getAnyByOutRelation(&m_context, questionNode, ScKeynodes::rrel_1); + ScAddr parentSectionAddr = IteratorUtils::getAnyByOutRelation(&m_context, questionNode, ScKeynodes::rrel_2); + ScAddr langAddr = IteratorUtils::getAnyByOutRelation(&m_context, questionNode, ScKeynodes::rrel_3); - if (!m_memoryCtx.IsElement(sectionNameAddr)) + if (!m_context.IsElement(sectionNameAddr)) { SC_LOG_ERROR("AddSectionAgent: section identifier link not found."); - utils::AgentUtils::finishAgentWork(&m_memoryCtx, questionNode, false); - return SC_RESULT_ERROR_INVALID_PARAMS; + return action.FinishUnsuccessfully(); } - if (!m_memoryCtx.IsElement(langAddr)) + if (!m_context.IsElement(langAddr)) { SC_LOG_ERROR("AddSectionAgent: lang node not found."); - utils::AgentUtils::finishAgentWork(&m_memoryCtx, questionNode, false); - return SC_RESULT_ERROR_INVALID_PARAMS; + return action.FinishUnsuccessfully(); } std::string sectionName; - m_memoryCtx.GetLinkContent(sectionNameAddr, sectionName); - SC_LOG_DEBUG("AddSectionAgent: new section name is \"" + sectionName + "\"."); + m_context.GetLinkContent(sectionNameAddr, sectionName); + SC_LOG_DEBUG( + R"(AddSectionAgent: new section name is ")" + << sectionName << + R"(".)"); ScAddr sectionAddr; - if (m_memoryCtx.IsElement(parentSectionAddr)) + if (m_context.IsElement(parentSectionAddr)) sectionAddr = GenerateSection(sectionName, parentSectionAddr, langAddr); else sectionAddr = GenerateSection(sectionName, langAddr); - if (!m_memoryCtx.IsElement(sectionAddr)) + if (!m_context.IsElement(sectionAddr)) { SC_LOG_ERROR("AddSectionAgent: section is not generated."); - utils::AgentUtils::finishAgentWork(&m_memoryCtx, questionNode, false); - return SC_RESULT_ERROR; + return action.FinishUnsuccessfully(); } - - utils::AgentUtils::finishAgentWork(&m_memoryCtx, questionNode, (ScAddrVector){sectionAddr}, true); + ScStructure result = m_context.GenerateStructure(); + for (auto const & identifierNode : (ScAddrVector){sectionAddr}) + result << identifierNode; + action.SetResult(result); SC_LOG_DEBUG("AddSectionAgent finished"); - return SC_RESULT_OK; + return action.FinishSuccessfully(); +} + +ScAddr AddSectionAgent::GetActionClass() const +{ + return SectionsKeynodes::action_add_section; } bool AddSectionAgent::CheckActionClass(ScAddr const & actionNode) { - return m_memoryCtx.HelperCheckEdge(SectionsKeynodes::action_add_section, actionNode, ScType::EdgeAccessConstPosPerm); + return m_context.HelperCheckEdge(SectionsKeynodes::action_add_section, actionNode, ScType::EdgeAccessConstPosPerm); } ScAddr AddSectionAgent::GenerateSection( @@ -82,27 +83,27 @@ ScAddr AddSectionAgent::GenerateSection( ScAddr const & parentSection, ScAddr const & lang) { - ScAddr decompositionTuple = sections_utils::GetSectionDecompositionTuple(&m_memoryCtx, parentSection); - if (!m_memoryCtx.IsElement(decompositionTuple)) + ScAddr decompositionTuple = sections_utils::GetSectionDecompositionTuple(&m_context, parentSection); + if (!m_context.IsElement(decompositionTuple)) return {}; - ScAddr newSection = sections_utils::FindSectionByName(&m_memoryCtx, sectionName); - if (!m_memoryCtx.IsElement(newSection)) - newSection = sections_generator::GenerateSection(&m_memoryCtx, sectionName, lang, true); + ScAddr newSection = sections_utils::FindSectionByName(&m_context, sectionName); + if (!m_context.IsElement(newSection)) + newSection = sections_generator::GenerateSection(&m_context, sectionName, lang, true); else { - if (m_memoryCtx.HelperCheckEdge(decompositionTuple, newSection, ScType::EdgeAccessConstPosPerm) + if (m_context.HelperCheckEdge(decompositionTuple, newSection, ScType::EdgeAccessConstPosPerm) || parentSection == newSection) return {}; } - ScAddr lastSection = sections_utils::GetLastSubSection(&m_memoryCtx, decompositionTuple); - ScAddr newSectionArc = m_memoryCtx.CreateEdge(ScType::EdgeAccessConstPosPerm, decompositionTuple, newSection); - if (m_memoryCtx.IsElement(lastSection)) + ScAddr lastSection = sections_utils::GetLastSubSection(&m_context, decompositionTuple); + ScAddr newSectionArc = m_context.CreateEdge(ScType::EdgeAccessConstPosPerm, decompositionTuple, newSection); + if (m_context.IsElement(lastSection)) { SC_LOG_DEBUG( - "AddSectionAgent: last section system idtf is \"" + m_memoryCtx.HelperGetSystemIdtf(lastSection) + "\"."); - ScIterator5Ptr lastSectionIterator = m_memoryCtx.Iterator5( + "AddSectionAgent: last section system idtf is \"" + m_context.HelperGetSystemIdtf(lastSection) + "\"."); + ScIterator5Ptr lastSectionIterator = m_context.Iterator5( decompositionTuple, ScType::EdgeAccessConstPosPerm, lastSection, @@ -112,33 +113,33 @@ ScAddr AddSectionAgent::GenerateSection( { ScAddr previousSectionArc = lastSectionIterator->Get(1); ScAddr previousSectionTempArc = lastSectionIterator->Get(3); - m_memoryCtx.EraseElement(previousSectionTempArc); + m_context.EraseElement(previousSectionTempArc); utils::GenerationUtils::generateRelationBetween( - &m_memoryCtx, previousSectionArc, newSectionArc, CoreKeynodes::nrel_basic_sequence); - m_memoryCtx.CreateEdge(ScType::EdgeAccessConstPosTemp, SectionsKeynodes::rrel_last, newSectionArc); + &m_context, previousSectionArc, newSectionArc, ScKeynodes::nrel_basic_sequence); + m_context.CreateEdge(ScType::EdgeAccessConstPosTemp, SectionsKeynodes::rrel_last, newSectionArc); } } else { SC_LOG_DEBUG("AddSectionAgent: added section is new."); - m_memoryCtx.CreateEdge(ScType::EdgeAccessConstPosPerm, CoreKeynodes::rrel_1, newSectionArc); - m_memoryCtx.CreateEdge(ScType::EdgeAccessConstPosTemp, SectionsKeynodes::rrel_last, newSectionArc); + m_context.CreateEdge(ScType::EdgeAccessConstPosPerm, ScKeynodes::rrel_1, newSectionArc); + m_context.CreateEdge(ScType::EdgeAccessConstPosTemp, SectionsKeynodes::rrel_last, newSectionArc); } - sectionsModule::SetUtils::AddToSets(&m_memoryCtx, parentSection, {SectionsKeynodes::non_atomic_section}); - sectionsModule::SetUtils::RemoveFromSets(&m_memoryCtx, parentSection, {SectionsKeynodes::atomic_section}); - sectionsModule::SetUtils::RemoveFromSets(&m_memoryCtx, newSection, {SectionsKeynodes::removed_section}); + sectionsModule::SetUtils::AddToSets(&m_context, parentSection, {SectionsKeynodes::non_atomic_section}); + sectionsModule::SetUtils::RemoveFromSets(&m_context, parentSection, {SectionsKeynodes::atomic_section}); + sectionsModule::SetUtils::RemoveFromSets(&m_context, newSection, {SectionsKeynodes::removed_section}); return newSection; } ScAddr AddSectionAgent::GenerateSection(std::string const & sectionName, ScAddr const & lang) { - ScAddr section = sections_utils::FindSectionByName(&m_memoryCtx, sectionName); - if (!m_memoryCtx.IsElement(section)) - section = sections_generator::GenerateSection(&m_memoryCtx, sectionName, lang, true); + ScAddr section = sections_utils::FindSectionByName(&m_context, sectionName); + if (!m_context.IsElement(section)) + section = sections_generator::GenerateSection(&m_context, sectionName, lang, true); else - sectionsModule::SetUtils::RemoveFromSets(&m_memoryCtx, section, {SectionsKeynodes::removed_section}); + sectionsModule::SetUtils::RemoveFromSets(&m_context, section, {SectionsKeynodes::removed_section}); return section; } diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.hpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.hpp index 4a0e1487..eb8ab898 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.hpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.hpp @@ -6,18 +6,16 @@ #pragma once -#include "sc-memory/kpm/sc_agent.hpp" - -#include "sc-agents-common/keynodes/coreKeynodes.hpp" - -#include "generated/add_section_agent.generated.hpp" +#include namespace sectionsModule { -class AddSectionAgent : public ScAgent +class AddSectionAgent : public ScActionInitiatedAgent { - SC_CLASS(Agent, Event(scAgentsCommon::CoreKeynodes::question_initiated, ScEvent::Type::AddOutputEdge)) - SC_GENERATED_BODY() +public: + ScAddr GetActionClass() const override; + + ScResult DoProgram(ScActionInitiatedEvent const & event, ScAction & action) override; private: bool CheckActionClass(ScAddr const & actionNode); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp index 4814a854..f43ad50b 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp @@ -4,7 +4,6 @@ * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) */ -#include "sc-agents-common/utils/AgentUtils.hpp" #include "sc-agents-common/utils/CommonUtils.hpp" #include "sc-agents-common/utils/IteratorUtils.hpp" @@ -17,75 +16,80 @@ using namespace utils; namespace sectionsModule { -SC_AGENT_IMPLEMENTATION(GetDecompositionAgent) +ScResult GetDecompositionAgent::DoProgram(ScActionInitiatedEvent const & event, ScAction & action) { - ScAddr const questionNode = m_memoryCtx.GetEdgeTarget(edgeAddr); + ScAddr const questionNode = m_context.GetEdgeTarget(event.GetArc()); if (!CheckActionClass(questionNode)) - return SC_RESULT_OK; + return action.FinishSuccessfully(); SC_LOG_INFO("GetDecompositionAgent started"); size_t level = 1; - ScAddr const subjDomainAddr = - IteratorUtils::getAnyByOutRelation(&m_memoryCtx, questionNode, scAgentsCommon::CoreKeynodes::rrel_1); - ScAddr const levelAddr = - IteratorUtils::getAnyByOutRelation(&m_memoryCtx, questionNode, scAgentsCommon::CoreKeynodes::rrel_2); - ScAddr const langAddr = - IteratorUtils::getAnyByOutRelation(&m_memoryCtx, questionNode, scAgentsCommon::CoreKeynodes::rrel_3); - ScAddr decompositionAddr = - IteratorUtils::getAnyByOutRelation(&m_memoryCtx, questionNode, scAgentsCommon::CoreKeynodes::rrel_4); - - if (!m_memoryCtx.IsElement(subjDomainAddr)) + + std::tuple const Tresult = action.GetArguments<4>(); + ScAddr const subjDomainAddr = std::get<0>(Tresult); + ScAddr const levelAddr = std::get<1>(Tresult); + ScAddr const langAddr = std::get<2>(Tresult); + ScAddr decompositionAddr = std::get<3>(Tresult); + + if (!m_context.IsElement(subjDomainAddr)) { SC_LOG_ERROR("GetDecompositionAgent: subject domain node not found."); - utils::AgentUtils::finishAgentWork(&m_memoryCtx, questionNode, false); - return SC_RESULT_ERROR_INVALID_PARAMS; + return action.FinishUnsuccessfully(); } - if (m_memoryCtx.IsElement(levelAddr)) - m_memoryCtx.GetLinkContent(levelAddr, level); - if (!m_memoryCtx.IsElement(langAddr)) + if (m_context.IsElement(levelAddr)) + m_context.GetLinkContent(levelAddr, level); + if (!m_context.IsElement(langAddr)) { SC_LOG_ERROR("GetDecompositionAgent: language node not found."); - utils::AgentUtils::finishAgentWork(&m_memoryCtx, questionNode, false); - return SC_RESULT_ERROR_INVALID_PARAMS; + return action.FinishUnsuccessfully(); } - if (!m_memoryCtx.IsElement(decompositionAddr)) + if (!m_context.IsElement(decompositionAddr)) { decompositionAddr = SectionsKeynodes::nrel_section_decomposition; SC_LOG_DEBUG( "GetDecompositionAgent: decomposition relation node not found. By default, " - << m_memoryCtx.HelperGetSystemIdtf(decompositionAddr) << " is used."); + << m_context.HelperGetSystemIdtf(decompositionAddr) << " is used."); } - ScAddr answerLink = m_memoryCtx.CreateLink(); + ScAddr answerLink = m_context.CreateLink(); ScAddrVector decomposition = GetDecomposition(subjDomainAddr, decompositionAddr); json answerJSON{ {CommonUtils::getAddrHashString(subjDomainAddr), - {{"idtf", CommonUtils::getMainIdtf(&m_memoryCtx, subjDomainAddr, {langAddr})}, + {{"idtf", CommonUtils::getMainIdtf(&m_context, subjDomainAddr, {langAddr})}, {"decomposition", GetJSONDecomposition(decomposition, level, langAddr, decompositionAddr)}, {"position", 0}}}}; std::string answerJSONContent = answerJSON.dump(); SC_LOG_INFO("Result decomposition: " << answerJSONContent); - m_memoryCtx.SetLinkContent(answerLink, answerJSONContent); + m_context.SetLinkContent(answerLink, answerJSONContent); ScAddrVector answerElements = {answerLink}; - utils::AgentUtils::finishAgentWork(&m_memoryCtx, questionNode, answerElements, true); + ScStructure result = m_context.GenerateStructure(); + for (auto const & answerElement : answerElements) + result << answerElement; + action.SetResult(result); + SC_LOG_INFO("GetDecompositionAgent finished"); - return SC_RESULT_OK; + return action.FinishSuccessfully(); +} + +ScAddr GetDecompositionAgent::GetActionClass() const +{ + return SectionsKeynodes::action_get_decomposition; } bool GetDecompositionAgent::CheckActionClass(ScAddr const & actionNode) { - return m_memoryCtx.HelperCheckEdge( + return m_context.HelperCheckEdge( SectionsKeynodes::action_get_decomposition, actionNode, ScType::EdgeAccessConstPosPerm); } ScAddrVector GetDecompositionAgent::GetDecomposition(ScAddr const & subjDomainAddr, ScAddr const & decompositionAddr) { - SC_LOG_DEBUG("GetDecompositionAgent: main section is " << m_memoryCtx.HelperGetSystemIdtf(subjDomainAddr) << "."); + SC_LOG_DEBUG("GetDecompositionAgent: main section is " << m_context.HelperGetSystemIdtf(subjDomainAddr) << "."); ScAddrVector decomposition; ScTemplate decompositionTemplate; @@ -100,23 +104,23 @@ ScAddrVector GetDecompositionAgent::GetDecomposition(ScAddr const & subjDomainAd ScType::EdgeAccessVarPosPerm, ScType::NodeVar >> sections_aliases::SECTION_NODE, ScType::EdgeAccessVarPosPerm, - scAgentsCommon::CoreKeynodes::rrel_1); + ScKeynodes::rrel_1); ScTemplateSearchResult result; - m_memoryCtx.HelperSearchTemplate(decompositionTemplate, result); + m_context.HelperSearchTemplate(decompositionTemplate, result); if (!result.IsEmpty()) { ScAddr tupleNode = result[0][sections_aliases::DECOMPOSITION_TUPLE]; ScAddr subSection = result[0][sections_aliases::SECTION_NODE]; - SC_LOG_DEBUG("GetDecompositionAgent: subsection is " << m_memoryCtx.HelperGetSystemIdtf(subSection) << "."); + SC_LOG_DEBUG("GetDecompositionAgent: subsection is " << m_context.HelperGetSystemIdtf(subSection) << "."); decomposition.push_back(subSection); - ScAddr nextSubSection = utils::IteratorUtils::getNextFromSet(&m_memoryCtx, tupleNode, subSection); - while (m_memoryCtx.IsElement(nextSubSection)) + ScAddr nextSubSection = utils::IteratorUtils::getNextFromSet(&m_context, tupleNode, subSection); + while (m_context.IsElement(nextSubSection)) { decomposition.push_back(nextSubSection); subSection = nextSubSection; - SC_LOG_DEBUG("GetDecompositionAgent: subsection is " << m_memoryCtx.HelperGetSystemIdtf(subSection) << "."); - nextSubSection = utils::IteratorUtils::getNextFromSet(&m_memoryCtx, tupleNode, subSection); + SC_LOG_DEBUG("GetDecompositionAgent: subsection is " << m_context.HelperGetSystemIdtf(subSection) << "."); + nextSubSection = utils::IteratorUtils::getNextFromSet(&m_context, tupleNode, subSection); } } return decomposition; @@ -133,7 +137,7 @@ json GetDecompositionAgent::GetJSONDecomposition( { json item; item["position"] = index; - item["idtf"] = CommonUtils::getMainIdtf(&m_memoryCtx, decomposition[index], {langAddr}); + item["idtf"] = CommonUtils::getMainIdtf(&m_context, decomposition[index], {langAddr}); if (level != 1) item["decomposition"] = GetJSONDecomposition( GetDecomposition(decomposition[index], decompositionAddr), level - 1, langAddr, decompositionAddr); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.hpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.hpp index 3b672568..3809aacc 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.hpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.hpp @@ -6,22 +6,19 @@ #pragma once -#include "sc-memory/kpm/sc_agent.hpp" - +#include #include -#include "sc-agents-common/keynodes/coreKeynodes.hpp" - -#include "generated/get_decomposition_agent.generated.hpp" - using json = nlohmann::json; namespace sectionsModule { -class GetDecompositionAgent : public ScAgent +class GetDecompositionAgent : public ScActionInitiatedAgent { - SC_CLASS(Agent, Event(scAgentsCommon::CoreKeynodes::question_initiated, ScEvent::Type::AddOutputEdge)) - SC_GENERATED_BODY() +public: + ScAddr GetActionClass() const override; + + ScResult DoProgram(ScActionInitiatedEvent const & event, ScAction & action) override; private: bool CheckActionClass(ScAddr const & actionNode); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp index d1c55952..87beafe3 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp @@ -4,8 +4,6 @@ * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) */ -#include "sc-agents-common/keynodes/coreKeynodes.hpp" -#include "sc-agents-common/utils/AgentUtils.hpp" #include "sc-agents-common/utils/CommonUtils.hpp" #include "sc-agents-common/utils/IteratorUtils.hpp" #include "sc-agents-common/utils/GenerationUtils.hpp" @@ -18,65 +16,67 @@ #include "remove_section_agent.hpp" -using namespace scAgentsCommon; using namespace utils; namespace sectionsModule { -SC_AGENT_IMPLEMENTATION(RemoveSectionAgent) +ScResult RemoveSectionAgent::DoProgram(ScActionInitiatedEvent const & event, ScAction & action) { - ScAddr const & questionNode = m_memoryCtx.GetEdgeTarget(edgeAddr); + ScAddr const & questionNode = m_context.GetEdgeTarget(event.GetArc()); if (!CheckActionClass(questionNode)) - return SC_RESULT_OK; + return action.FinishSuccessfully(); SC_LOG_DEBUG("RemoveSectionAgent started"); - ScAddr sectionAddr = - IteratorUtils::getAnyByOutRelation(&m_memoryCtx, questionNode, scAgentsCommon::CoreKeynodes::rrel_1); - ScAddr parentSectionAddr = - IteratorUtils::getAnyByOutRelation(&m_memoryCtx, questionNode, scAgentsCommon::CoreKeynodes::rrel_2); + ScAddr sectionAddr = IteratorUtils::getAnyByOutRelation(&m_context, questionNode, ScKeynodes::rrel_1); + ScAddr parentSectionAddr = IteratorUtils::getAnyByOutRelation(&m_context, questionNode, ScKeynodes::rrel_2); - if (!m_memoryCtx.IsElement(sectionAddr)) + if (!m_context.IsElement(sectionAddr)) { SC_LOG_ERROR("RemoveSectionAgent: section node not found."); - utils::AgentUtils::finishAgentWork(&m_memoryCtx, questionNode, false); - return SC_RESULT_ERROR_INVALID_PARAMS; + return action.FinishUnsuccessfully(); } - bool result = m_memoryCtx.IsElement(parentSectionAddr) ? RemoveSection(sectionAddr, parentSectionAddr) - : RemoveSection(sectionAddr); - if (!result) + bool isSuccess = m_context.IsElement(parentSectionAddr) ? RemoveSection(sectionAddr, parentSectionAddr) + : RemoveSection(sectionAddr); + if (!isSuccess) { SC_LOG_ERROR("RemoveSectionAgent: error in the section deletion."); - utils::AgentUtils::finishAgentWork(&m_memoryCtx, questionNode, false); - return SC_RESULT_ERROR_INVALID_PARAMS; + return action.FinishUnsuccessfully(); } - utils::AgentUtils::finishAgentWork(&m_memoryCtx, questionNode, (ScAddrVector){sectionAddr}, true); + ScStructure result = m_context.GenerateStructure(); + for (auto const & answerElement : (ScAddrVector){sectionAddr}) + result << answerElement; + action.SetResult(result); SC_LOG_DEBUG("RemoveSectionAgent finished"); - return SC_RESULT_OK; + return action.FinishSuccessfully(); +} + +ScAddr RemoveSectionAgent::GetActionClass() const +{ + return SectionsKeynodes::action_remove_section; } bool RemoveSectionAgent::CheckActionClass(ScAddr const & actionNode) { - return m_memoryCtx.HelperCheckEdge( - SectionsKeynodes::action_remove_section, actionNode, ScType::EdgeAccessConstPosPerm); + return m_context.HelperCheckEdge(SectionsKeynodes::action_remove_section, actionNode, ScType::EdgeAccessConstPosPerm); } bool RemoveSectionAgent::RemoveSection(ScAddr const & section, ScAddr const & parentSection) { - SC_LOG_DEBUG("RemoveSectionAgent: section system idtf is " + m_memoryCtx.HelperGetSystemIdtf(section) + "."); + SC_LOG_DEBUG("RemoveSectionAgent: section system idtf is " + m_context.HelperGetSystemIdtf(section) + "."); SC_LOG_DEBUG( - "RemoveSectionAgent: parent section system idtf is " + m_memoryCtx.HelperGetSystemIdtf(parentSection) + "."); + "RemoveSectionAgent: parent section system idtf is " + m_context.HelperGetSystemIdtf(parentSection) + "."); ScTemplate scTemplate; sections_builder::buildDecompositionTupleTemplate(scTemplate, parentSection, section); ScTemplateSearchResult searchResult; - m_memoryCtx.HelperSearchTemplate(scTemplate, searchResult); + m_context.HelperSearchTemplate(scTemplate, searchResult); if (!searchResult.IsEmpty()) { HandleSection(searchResult[0], section); HandleParentSection(searchResult[0], parentSection); - sectionsModule::SetUtils::AddToSets(&m_memoryCtx, section, {SectionsKeynodes::removed_section}); + sectionsModule::SetUtils::AddToSets(&m_context, section, {SectionsKeynodes::removed_section}); return true; } @@ -85,11 +85,11 @@ bool RemoveSectionAgent::RemoveSection(ScAddr const & section, ScAddr const & pa bool RemoveSectionAgent::RemoveSection(ScAddr const & section) { - SC_LOG_DEBUG("RemoveSectionAgent: section system idtf is " << m_memoryCtx.HelperGetSystemIdtf(section) << "."); + SC_LOG_DEBUG("RemoveSectionAgent: section system idtf is " << m_context.HelperGetSystemIdtf(section) << "."); ScTemplate scTemplate; sections_builder::buildDecompositionTupleTemplate(scTemplate, section); ScTemplateSearchResult searchResult; - m_memoryCtx.HelperSearchTemplate(scTemplate, searchResult); + m_context.HelperSearchTemplate(scTemplate, searchResult); if (!searchResult.IsEmpty()) { @@ -97,17 +97,16 @@ bool RemoveSectionAgent::RemoveSection(ScAddr const & section) { ScAddr parentSection = searchResult[i][sections_aliases::PARENT_SECTION]; SC_LOG_DEBUG( - "RemoveSectionAgent: parent section system idtf is " << m_memoryCtx.HelperGetSystemIdtf(parentSection) - << "."); + "RemoveSectionAgent: parent section system idtf is " << m_context.HelperGetSystemIdtf(parentSection) << "."); HandleSection(searchResult[i], section); HandleParentSection(searchResult[i], parentSection); } - sectionsModule::SetUtils::AddToSets(&m_memoryCtx, section, {SectionsKeynodes::removed_section}); + sectionsModule::SetUtils::AddToSets(&m_context, section, {SectionsKeynodes::removed_section}); return true; } - ScAddr edge = m_memoryCtx.CreateEdge(ScType::EdgeAccessConstPosPerm, SectionsKeynodes::removed_section, section); - return m_memoryCtx.IsElement(edge); + ScAddr edge = m_context.CreateEdge(ScType::EdgeAccessConstPosPerm, SectionsKeynodes::removed_section, section); + return m_context.IsElement(edge); } void RemoveSectionAgent::HandleSection(ScTemplateSearchResultItem const & searchResult, ScAddr const & section) @@ -123,11 +122,11 @@ void RemoveSectionAgent::HandleParentSection( { ScAddr tuple = searchResult[sections_aliases::DECOMPOSITION_TUPLE]; - if (CommonUtils::getSetPower(&m_memoryCtx, tuple) == 0) + if (CommonUtils::getSetPower(&m_context, tuple) == 0) { - m_memoryCtx.EraseElement(tuple); - sectionsModule::SetUtils::AddToSets(&m_memoryCtx, parentSection, {SectionsKeynodes::atomic_section}); - sectionsModule::SetUtils::RemoveFromSets(&m_memoryCtx, parentSection, {SectionsKeynodes::non_atomic_section}); + m_context.EraseElement(tuple); + sectionsModule::SetUtils::AddToSets(&m_context, parentSection, {SectionsKeynodes::atomic_section}); + sectionsModule::SetUtils::RemoveFromSets(&m_context, parentSection, {SectionsKeynodes::non_atomic_section}); } } @@ -136,7 +135,7 @@ void RemoveSectionAgent::HandleNeighboringSections(ScAddr const & tuple, ScAddr ScTemplate previousSectionTemplate; sections_builder::buildPreviousSectionTemplate(previousSectionTemplate, tuple, section); ScTemplateSearchResult previousSectionSearchResult; - m_memoryCtx.HelperSearchTemplate(previousSectionTemplate, previousSectionSearchResult); + m_context.HelperSearchTemplate(previousSectionTemplate, previousSectionSearchResult); ScAddr currentSectionEdge; ScAddr previousSection; @@ -148,13 +147,13 @@ void RemoveSectionAgent::HandleNeighboringSections(ScAddr const & tuple, ScAddr currentSectionEdge = previousSectionSearchResult[0][sections_aliases::SECTION_EDGE]; SC_LOG_DEBUG( "RemoveSectionAgent: previous neighboring section system idtf is " - + m_memoryCtx.HelperGetSystemIdtf(previousSection) + "."); + + m_context.HelperGetSystemIdtf(previousSection) + "."); } ScTemplate nextSectionTemplate; sections_builder::buildNextSectionTemplate(nextSectionTemplate, tuple, section); ScTemplateSearchResult nextSectionSearchResult; - m_memoryCtx.HelperSearchTemplate(nextSectionTemplate, nextSectionSearchResult); + m_context.HelperSearchTemplate(nextSectionTemplate, nextSectionSearchResult); ScAddr nextSection; ScAddr nextSectionEdge; @@ -164,38 +163,38 @@ void RemoveSectionAgent::HandleNeighboringSections(ScAddr const & tuple, ScAddr nextSectionEdge = nextSectionSearchResult[0][sections_aliases::NEXT_SECTION_ARC]; currentSectionEdge = nextSectionSearchResult[0][sections_aliases::SECTION_EDGE]; SC_LOG_DEBUG( - "RemoveSectionAgent: next neighboring section system idtf is " << m_memoryCtx.HelperGetSystemIdtf(nextSection) + "RemoveSectionAgent: next neighboring section system idtf is " << m_context.HelperGetSystemIdtf(nextSection) << "."); } // If current element is the first and the last - if (!m_memoryCtx.IsElement(currentSectionEdge)) + if (!m_context.IsElement(currentSectionEdge)) { - ScIterator3Ptr currentSectionEdgeIterator = m_memoryCtx.Iterator3(tuple, ScType::EdgeAccessConstPosPerm, section); + ScIterator3Ptr currentSectionEdgeIterator = m_context.Iterator3(tuple, ScType::EdgeAccessConstPosPerm, section); if (currentSectionEdgeIterator->Next()) { currentSectionEdge = currentSectionEdgeIterator->Get(1); } } - m_memoryCtx.EraseElement(currentSectionEdge); + m_context.EraseElement(currentSectionEdge); // If current element has previous and has next - if (m_memoryCtx.IsElement(previousSection) && m_memoryCtx.IsElement(nextSection)) + if (m_context.IsElement(previousSection) && m_context.IsElement(nextSection)) { GenerationUtils::generateRelationBetween( - &m_memoryCtx, previousSectionEdge, nextSectionEdge, CoreKeynodes::nrel_basic_sequence); + &m_context, previousSectionEdge, nextSectionEdge, ScKeynodes::nrel_basic_sequence); } // If current element is the last - if (m_memoryCtx.IsElement(previousSection) && !m_memoryCtx.IsElement(nextSection)) + if (m_context.IsElement(previousSection) && !m_context.IsElement(nextSection)) { - m_memoryCtx.CreateEdge(ScType::EdgeAccessConstPosTemp, SectionsKeynodes::rrel_last, previousSectionEdge); + m_context.CreateEdge(ScType::EdgeAccessConstPosTemp, SectionsKeynodes::rrel_last, previousSectionEdge); } // If current element is the first - if (!m_memoryCtx.IsElement(previousSection) && m_memoryCtx.IsElement(nextSection)) + if (!m_context.IsElement(previousSection) && m_context.IsElement(nextSection)) { - m_memoryCtx.CreateEdge(ScType::EdgeAccessConstPosPerm, CoreKeynodes::rrel_1, nextSectionEdge); + m_context.CreateEdge(ScType::EdgeAccessConstPosPerm, ScKeynodes::rrel_1, nextSectionEdge); } } diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.hpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.hpp index 029a0204..065db5fe 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.hpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.hpp @@ -6,18 +6,16 @@ #pragma once -#include "sc-memory/kpm/sc_agent.hpp" - -#include "sc-agents-common/keynodes/coreKeynodes.hpp" - -#include "generated/remove_section_agent.generated.hpp" +#include namespace sectionsModule { -class RemoveSectionAgent : public ScAgent +class RemoveSectionAgent : public ScActionInitiatedAgent { - SC_CLASS(Agent, Event(scAgentsCommon::CoreKeynodes::question_initiated, ScEvent::Type::AddOutputEdge)) - SC_GENERATED_BODY() +public: + ScAddr GetActionClass() const override; + + ScResult DoProgram(ScActionInitiatedEvent const & event, ScAction & action) override; private: bool CheckActionClass(ScAddr const & actionNode); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/builder/sections_builder.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/builder/sections_builder.cpp index 58d4fbfd..a39673c2 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/builder/sections_builder.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/builder/sections_builder.cpp @@ -4,8 +4,6 @@ * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) */ -#include "sc-agents-common/keynodes/coreKeynodes.hpp" - #include "constants/sections_aliases.hpp" #include "keynodes/sections_keynodes.hpp" @@ -57,7 +55,7 @@ void sections_builder::buildNextSectionTemplate( ScType::EdgeDCommonVar >> sections_aliases::BASE_SEQUENCE_EDGE, sections_aliases::NEXT_SECTION_ARC, ScType::EdgeAccessVarPosPerm, - scAgentsCommon::CoreKeynodes::nrel_basic_sequence); + ScKeynodes::nrel_basic_sequence); } void sections_builder::buildPreviousSectionTemplate( @@ -75,7 +73,7 @@ void sections_builder::buildPreviousSectionTemplate( ScType::EdgeDCommonVar >> sections_aliases::BASE_SEQUENCE_EDGE, sections_aliases::SECTION_EDGE, ScType::EdgeAccessVarPosPerm, - scAgentsCommon::CoreKeynodes::nrel_basic_sequence); + ScKeynodes::nrel_basic_sequence); } } // namespace sectionsModule diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/keynodes/sections_keynodes.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/keynodes/sections_keynodes.cpp deleted file mode 100644 index 0439953d..00000000 --- a/platform-dependent-components/problem-solver/cxx/sections-module/keynodes/sections_keynodes.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - * This source file is part of an OSTIS project. For the latest info, see http://ostis.net - * Distributed under the MIT License - * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) - */ - -#include "sections_keynodes.hpp" - -#include "sc-memory/sc_memory.hpp" - -namespace sectionsModule -{ -ScAddr SectionsKeynodes::action_get_decomposition; -ScAddr SectionsKeynodes::action_add_section; -ScAddr SectionsKeynodes::action_remove_section; -ScAddr SectionsKeynodes::nrel_section_decomposition; -ScAddr SectionsKeynodes::nrel_entity_decomposition; -ScAddr SectionsKeynodes::removed_section; -ScAddr SectionsKeynodes::section; -ScAddr SectionsKeynodes::not_enough_formed_structure; -ScAddr SectionsKeynodes::atomic_section; -ScAddr SectionsKeynodes::non_atomic_section; -ScAddr SectionsKeynodes::rrel_last; -} // namespace sectionsModule diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/keynodes/sections_keynodes.hpp b/platform-dependent-components/problem-solver/cxx/sections-module/keynodes/sections_keynodes.hpp index 05034eff..9dde77f4 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/keynodes/sections_keynodes.hpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/keynodes/sections_keynodes.hpp @@ -5,52 +5,39 @@ */ #pragma once +#include #include "sc-memory/sc_addr.hpp" #include "sc-memory/sc_object.hpp" -#include "generated/sections_keynodes.generated.hpp" - namespace sectionsModule { -class SectionsKeynodes : public ScObject +class SectionsKeynodes : public ScKeynodes { - SC_CLASS() - SC_GENERATED_BODY() - public: - SC_PROPERTY(Keynode("action_get_decomposition"), ForceCreate) - static ScAddr action_get_decomposition; + static inline ScKeynode const action_get_decomposition{"action_get_decomposition"}; + + static inline ScKeynode const action_add_section{"action_add_section"}; - SC_PROPERTY(Keynode("action_add_section"), ForceCreate) - static ScAddr action_add_section; + static inline ScKeynode const action_remove_section{"action_remove_section"}; - SC_PROPERTY(Keynode("action_remove_section"), ForceCreate) - static ScAddr action_remove_section; + static inline ScKeynode const nrel_section_decomposition{"nrel_section_decomposition"}; - SC_PROPERTY(Keynode("nrel_section_decomposition"), ForceCreate) - static ScAddr nrel_section_decomposition; + static inline ScKeynode const nrel_entity_decomposition{"nrel_entity_decomposition"}; - SC_PROPERTY(Keynode("nrel_entity_decomposition"), ForceCreate) - static ScAddr nrel_entity_decomposition; + static inline ScKeynode const removed_section{"removed_section"}; - SC_PROPERTY(Keynode("removed_section"), ForceCreate) - static ScAddr removed_section; + static inline ScKeynode const section{"section"}; - SC_PROPERTY(Keynode("section"), ForceCreate) - static ScAddr section; + static inline ScKeynode const not_enough_formed_structure{"not_enough_formed_structure"}; - SC_PROPERTY(Keynode("not_enough_formed_structure"), ForceCreate) - static ScAddr not_enough_formed_structure; + static inline ScKeynode const atomic_section{"atomic_section"}; - SC_PROPERTY(Keynode("atomic_section"), ForceCreate) - static ScAddr atomic_section; + static inline ScKeynode const non_atomic_section{"non_atomic_section"}; - SC_PROPERTY(Keynode("non_atomic_section"), ForceCreate) - static ScAddr non_atomic_section; + static inline ScKeynode const rrel_last{"rrel_last"}; - SC_PROPERTY(Keynode("rrel_last"), ForceCreate) - static ScAddr rrel_last; + static inline ScKeynode const nrel_answer{"nrel_answer"}; }; } // namespace sectionsModule diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/subject_domain_module.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/subject_domain_module.cpp index 02fbe889..d83f0163 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/subject_domain_module.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/subject_domain_module.cpp @@ -14,25 +14,7 @@ using namespace sectionsModule; -SC_IMPLEMENT_MODULE(SectionsModule) - -sc_result SectionsModule::InitializeImpl() -{ - if (!sectionsModule::SectionsKeynodes::InitGlobal()) - return SC_RESULT_ERROR; - - SC_AGENT_REGISTER(GetDecompositionAgent) - SC_AGENT_REGISTER(AddSectionAgent) - SC_AGENT_REGISTER(RemoveSectionAgent) - - return SC_RESULT_OK; -} - -sc_result SectionsModule::ShutdownImpl() -{ - SC_AGENT_UNREGISTER(GetDecompositionAgent) - SC_AGENT_UNREGISTER(AddSectionAgent) - SC_AGENT_UNREGISTER(RemoveSectionAgent) - - return SC_RESULT_OK; -} +SC_MODULE_REGISTER(SectionsModule) + ->Agent() + ->Agent() + ->Agent(); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/subject_domain_module.hpp b/platform-dependent-components/problem-solver/cxx/sections-module/subject_domain_module.hpp index fd7111e9..3bd51e4a 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/subject_domain_module.hpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/subject_domain_module.hpp @@ -8,14 +8,6 @@ #include "sc-memory/sc_module.hpp" -#include "generated/subject_domain_module.generated.hpp" - class SectionsModule : public ScModule { - SC_CLASS(LoadOrder(100)) - SC_GENERATED_BODY() - - virtual sc_result InitializeImpl() override; - - virtual sc_result ShutdownImpl() override; }; diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.cpp index c46fa0d5..17cdc74f 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.cpp @@ -45,8 +45,7 @@ ScAddr sections_utils::FindSectionByName(ScMemoryContext * context, std::string { for (ScAddr const & link : links) { - ScAddr section = - utils::IteratorUtils::getAnyByInRelation(context, link, scAgentsCommon::CoreKeynodes::nrel_main_idtf); + ScAddr section = utils::IteratorUtils::getAnyByInRelation(context, link, ScKeynodes::nrel_main_idtf); if (context->IsElement(section)) { sectionAddr = section; diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.hpp b/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.hpp index 39a516f5..8592cc08 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.hpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.hpp @@ -9,8 +9,6 @@ #include "sc-memory/sc_memory.hpp" #include "sc-agents-common/utils/IteratorUtils.hpp" -#include "sc-agents-common/keynodes/coreKeynodes.hpp" - #include "keynodes/sections_keynodes.hpp" #include From 92c54a252e1a2c177b14c1e409e05dbc3e784ebb Mon Sep 17 00:00:00 2001 From: Anna Makarenko Date: Tue, 17 Sep 2024 07:23:11 +0300 Subject: [PATCH 2/9] [tests] Update agents --- .../test/test-structures/correct_test.scs | 2 +- .../test/test-structures/incorrect_test.scs | 2 +- .../many_system_idtfs_test.scs | 2 +- .../test/test-structures/void_test.scs | 2 +- .../identifiers-module/test/units/test.cpp | 77 ++++------- .../test/testStructures/test_add_section.scs | 10 +- .../testStructures/test_remove_section.scs | 8 +- .../test_successful_decomposition.scs | 4 +- .../test/units/add_section_agent_test.cpp | 123 ++++++++---------- .../units/get_decomposition_agent_test.cpp | 60 +++------ .../test/units/remove_section_agent_test.cpp | 107 +++++++-------- 11 files changed, 163 insertions(+), 234 deletions(-) diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/correct_test.scs b/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/correct_test.scs index 20253415..1c94f528 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/correct_test.scs +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/correct_test.scs @@ -1,6 +1,6 @@ test_action_node <- action_find_identifiers; - <- question;; + <- action;; knowledge <- sc_node_class; diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/incorrect_test.scs b/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/incorrect_test.scs index 6e0f1f5c..c664c4a7 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/incorrect_test.scs +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/incorrect_test.scs @@ -1,6 +1,6 @@ test_action_node <- action_find_identifiers; - <- question;; + <- action;; Knowledge <- sc_node_class; diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/many_system_idtfs_test.scs b/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/many_system_idtfs_test.scs index ab2220d3..72812741 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/many_system_idtfs_test.scs +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/many_system_idtfs_test.scs @@ -1,6 +1,6 @@ test_action_node <- action_find_identifiers; - <- question;; + <- action;; Knowledge <- sc_node_class; diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/void_test.scs b/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/void_test.scs index ad0081a1..62a011d7 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/void_test.scs +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/test/test-structures/void_test.scs @@ -1,3 +1,3 @@ test_action_node <- action_find_identifiers; - <- question;; + <- action;; diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/test/units/test.cpp b/platform-dependent-components/problem-solver/cxx/identifiers-module/test/units/test.cpp index 0db48a19..a98243fc 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/test/units/test.cpp +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/test/units/test.cpp @@ -1,11 +1,8 @@ #include "sc-builder/src/scs_loader.hpp" -#include "sc-memory/sc_wait.hpp" #include "sc_test.hpp" #include "sc-agents-common/utils/CommonUtils.hpp" -#include "sc-agents-common/utils/AgentUtils.hpp" #include "keynodes/identifiers_keynodes.hpp" #include "agent/translate_main_system_idtfs_from_sc_to_file_agent.hpp" -#include "sc-agents-common/keynodes/coreKeynodes.hpp" using namespace identifiersModule; using AgentTest = ScMemoryTest; @@ -13,16 +10,11 @@ using AgentTest = ScMemoryTest; namespace moduleTest { ScsLoader loader; + std::string const TEST_FILES_DIR_PATH = MODULE_TEST_SRC_PATH "/test-structures/"; int const WAIT_TIME = 1000; -void InitializeKeynodes() -{ - scAgentsCommon::CoreKeynodes::InitGlobal(); - IdentifiersKeynodes::InitGlobal(); -} - std::string GetFileContent() { char fileName[] = IDENTIFIERS_MODULE_PATH "identifiers.txt"; @@ -63,42 +55,33 @@ bool IsSubstringOfFile(std::vector const & input, std::string const TEST_F(AgentTest, VoidTest) { - ScMemoryContext & context = *m_ctx; - + ScAgentContext & context = *m_ctx; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "void_test.scs"); ScAddr const & testActionNode = context.HelperFindBySystemIdtf("test_action_node"); + ScAction testAction = context.ConvertToAction(testActionNode); - ScAgentInit(true); - InitializeKeynodes(); - - SC_AGENT_REGISTER(TranslateMainSystemIdtfsFromScToFileAgent) - - EXPECT_TRUE(utils::AgentUtils::applyAction(&context, testActionNode, WAIT_TIME)); + context.SubscribeAgent(); - EXPECT_TRUE(context.HelperCheckEdge( - scAgentsCommon::CoreKeynodes::question_finished_successfully, testActionNode, ScType::EdgeAccessConstPosPerm)); + testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.IsFinishedSuccessfully()); std::string const fileContent = GetFileContent(); EXPECT_TRUE(fileContent.empty()); - - SC_AGENT_UNREGISTER(TranslateMainSystemIdtfsFromScToFileAgent) + context.UnsubscribeAgent(); } TEST_F(AgentTest, CorrectTest) { - ScMemoryContext & context = *m_ctx; + ScAgentContext & context = *m_ctx; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "correct_test.scs"); ScAddr const & testActionNode = context.HelperFindBySystemIdtf("test_action_node"); + ScAction testAction = context.ConvertToAction(testActionNode); - ScAgentInit(true); - InitializeKeynodes(); - SC_AGENT_REGISTER(TranslateMainSystemIdtfsFromScToFileAgent) - - EXPECT_TRUE(utils::AgentUtils::applyAction(&context, testActionNode, WAIT_TIME)); + context.SubscribeAgent(); - EXPECT_TRUE(context.HelperCheckEdge( - scAgentsCommon::CoreKeynodes::question_finished_successfully, testActionNode, ScType::EdgeAccessConstPosPerm)); + testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.IsFinishedSuccessfully()); std::string const & space = R"({"space", "sc_node_class"})"; std::string const & knowledge = R"({"знание", {"knowledge", "sc_node_class"}})"; @@ -114,23 +97,20 @@ TEST_F(AgentTest, CorrectTest) bool const falseResult = IsSubstringOfFile(falseInput, fileContent); EXPECT_TRUE(!falseResult && trueResult); - SC_AGENT_UNREGISTER(TranslateMainSystemIdtfsFromScToFileAgent) + context.UnsubscribeAgent(); } TEST_F(AgentTest, IncorrectTest) { - ScMemoryContext & context = *m_ctx; + ScAgentContext & context = *m_ctx; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "incorrect_test.scs"); ScAddr const & testActionNode = context.HelperFindBySystemIdtf("test_action_node"); + ScAction testAction = context.ConvertToAction(testActionNode); - ScAgentInit(true); - InitializeKeynodes(); - SC_AGENT_REGISTER(TranslateMainSystemIdtfsFromScToFileAgent) + context.SubscribeAgent(); - EXPECT_TRUE(utils::AgentUtils::applyAction(&context, testActionNode, WAIT_TIME)); - - EXPECT_TRUE(context.HelperCheckEdge( - scAgentsCommon::CoreKeynodes::question_finished_successfully, testActionNode, ScType::EdgeAccessConstPosPerm)); + testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.IsFinishedSuccessfully()); std::string const fileContent = GetFileContent(); @@ -145,28 +125,23 @@ TEST_F(AgentTest, IncorrectTest) bool const trueResult = IsSubstringOfFile(trueInput, fileContent); bool const falseResult = IsSubstringOfFile(falseInput, fileContent); - + SC_LOG_WARNING(fileContent); EXPECT_TRUE(!falseResult && trueResult); - - SC_AGENT_UNREGISTER(TranslateMainSystemIdtfsFromScToFileAgent) + context.UnsubscribeAgent(); } TEST_F(AgentTest, ManySystemIdtfsTest) { - ScMemoryContext & context = *m_ctx; + ScAgentContext & context = *m_ctx; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "many_system_idtfs_test.scs"); ScAddr const & testActionNode = context.HelperFindBySystemIdtf("test_action_node"); + ScAction testAction = context.ConvertToAction(testActionNode); - ScAgentInit(true); - InitializeKeynodes(); - SC_AGENT_REGISTER(TranslateMainSystemIdtfsFromScToFileAgent) - - EXPECT_TRUE(utils::AgentUtils::applyAction(&context, testActionNode, WAIT_TIME)); - - EXPECT_TRUE(context.HelperCheckEdge( - scAgentsCommon::CoreKeynodes::question_finished_unsuccessfully, testActionNode, ScType::EdgeAccessConstPosPerm)); + context.SubscribeAgent(); + testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.IsFinishedUnsuccessfully()); - SC_AGENT_UNREGISTER(TranslateMainSystemIdtfsFromScToFileAgent) + context.UnsubscribeAgent(); } } // namespace moduleTest diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/test/testStructures/test_add_section.scs b/platform-dependent-components/problem-solver/cxx/sections-module/test/testStructures/test_add_section.scs index f38a6976..4a6269ad 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/test/testStructures/test_add_section.scs +++ b/platform-dependent-components/problem-solver/cxx/sections-module/test/testStructures/test_add_section.scs @@ -1,22 +1,22 @@ -test_action_node <- question; action_add_section; +test_action_node <- action; action_add_section; -> rrel_1: [new section]; -> rrel_2: knowledge_base_IMS; -> rrel_3: lang_en;; -test_action_node2 <- question; action_add_section; +test_action_node2 <- action; action_add_section; -> rrel_1: [new section]; -> rrel_2: section_project_IMS_history_and_development_programme; -> rrel_3: lang_en;; -test_action_node3 <- question; action_add_section; +test_action_node3 <- action; action_add_section; -> rrel_2: section_project_IMS_history_and_development_programme; -> rrel_3: lang_en;; -test_action_node4 <- question; action_add_section; +test_action_node4 <- action; action_add_section; -> rrel_1: [new section]; -> rrel_2: section_project_IMS_history_and_development_programme;; -test_action_node5 <- question; action_add_section; +test_action_node5 <- action; action_add_section; -> rrel_1: [new section]; -> rrel_3: lang_en;; diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/test/testStructures/test_remove_section.scs b/platform-dependent-components/problem-solver/cxx/sections-module/test/testStructures/test_remove_section.scs index 7aa09fef..6ee8b0bb 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/test/testStructures/test_remove_section.scs +++ b/platform-dependent-components/problem-solver/cxx/sections-module/test/testStructures/test_remove_section.scs @@ -1,15 +1,15 @@ -test_action_node <- question; action_remove_section; +test_action_node <- action; action_remove_section; -> rrel_1: section_OSTIS_technology; -> rrel_2: knowledge_base_IMS;; -test_action_node2 <- question; action_remove_section; +test_action_node2 <- action; action_remove_section; -> rrel_1: doc_IMS; -> rrel_2: section_project_OSTIS_perspectives_current_state_history_of_evolution_and_use;; -test_action_node3 <- question; action_remove_section; +test_action_node3 <- action; action_remove_section; -> rrel_2: section_inner_project_IMS_history_and_development_programme;; -test_action_node4 <- question; action_remove_section; +test_action_node4 <- action; action_remove_section; -> rrel_1: section_inner_project_IMS_history_and_development_programme;; diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/test/testStructures/test_successful_decomposition.scs b/platform-dependent-components/problem-solver/cxx/sections-module/test/testStructures/test_successful_decomposition.scs index ce6b6d8c..0344e8a3 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/test/testStructures/test_successful_decomposition.scs +++ b/platform-dependent-components/problem-solver/cxx/sections-module/test/testStructures/test_successful_decomposition.scs @@ -1,12 +1,12 @@ nrel_section_base_order <- sc_node_norole_relation;; -test_action_node <- question; action_get_decomposition; +test_action_node <- action; action_get_decomposition; -> rrel_1: root_section; -> rrel_3: lang_ru; -> rrel_4: nrel_entity_decomposition;; -test_action_node2 <- question; action_get_decomposition; +test_action_node2 <- action; action_get_decomposition; -> rrel_1: root_section; -> rrel_2: [2]; -> rrel_3: lang_ru; diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/add_section_agent_test.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/add_section_agent_test.cpp index e684ab98..db8279c8 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/add_section_agent_test.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/add_section_agent_test.cpp @@ -12,12 +12,10 @@ #include "sc_test.hpp" -#include "sc-agents-common/keynodes/coreKeynodes.hpp" #include "sc-agents-common/utils/CommonUtils.hpp" -#include "sc-agents-common/utils/AgentUtils.hpp" #include "sc-agents-common/utils/IteratorUtils.hpp" -#include "sc-memory/kpm/sc_agent.hpp" +#include #include "sc-memory/utils/sc_base64.hpp" #include @@ -34,127 +32,110 @@ using AddSectionTest = ScMemoryTest; TEST_F(AddSectionTest, successful_add_section_to_decomposition) { - ScMemoryContext & context = *m_ctx; - scAgentsCommon::CoreKeynodes::InitGlobal(); - SectionsKeynodes::InitGlobal(); - SC_AGENT_REGISTER(AddSectionAgent) + ScAgentContext & context = *m_ctx; + ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_add_section.scs"); + ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node"); - ScAddr parentSectionAddr = - utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, scAgentsCommon::CoreKeynodes::rrel_2); + ScAction testAction = context.ConvertToAction(testActionNode); + + ScAddr parentSectionAddr = utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, ScKeynodes::rrel_2); ScAddr decompositionTupleAddr = sections_utils::GetSectionDecompositionTuple(&context, parentSectionAddr); size_t decompositionSize = utils::CommonUtils::getSetPower(&context, decompositionTupleAddr); - utils::AgentUtils::applyAction(&context, testActionNode, 1000); - ScIterator5Ptr it5 = context.Iterator5( - testActionNode, - ScType::EdgeDCommon, - ScType::Unknown, - ScType::EdgeAccessConstPosPerm, - scAgentsCommon::CoreKeynodes::nrel_answer); - EXPECT_TRUE(it5->Next()); + context.SubscribeAgent(); + + testAction.InitiateAndWait(WAIT_TIME); + ScStructure result = testAction.GetResult(); - ScIterator3Ptr it3 = context.Iterator3(it5->Get(2), ScType::EdgeAccessConstPosPerm, ScType::Unknown); + ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Unknown); EXPECT_TRUE(it3->Next()); EXPECT_TRUE(context.IsElement(it3->Get(2))); EXPECT_EQ(utils::CommonUtils::getSetPower(&context, decompositionTupleAddr) - decompositionSize, 1u); - SC_AGENT_UNREGISTER(AddSectionAgent) + context.UnsubscribeAgent(); } TEST_F(AddSectionTest, successful_add_section_empty_decomposition) { - ScMemoryContext & context = *m_ctx; - scAgentsCommon::CoreKeynodes::InitGlobal(); - SectionsKeynodes::InitGlobal(); + ScAgentContext & context = *m_ctx; - SC_AGENT_REGISTER(AddSectionAgent) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_add_section.scs"); + ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node2"); - ScAddr parentSectionAddr = - utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, scAgentsCommon::CoreKeynodes::rrel_2); - - utils::AgentUtils::applyAction(&context, testActionNode, WAIT_TIME); - ScIterator5Ptr it5 = context.Iterator5( - testActionNode, - ScType::EdgeDCommon, - ScType::Unknown, - ScType::EdgeAccessConstPosPerm, - scAgentsCommon::CoreKeynodes::nrel_answer); - EXPECT_TRUE(it5->Next()); - - ScIterator3Ptr it3 = context.Iterator3(it5->Get(2), ScType::EdgeAccessConstPosPerm, ScType::NodeConst); + ScAddr parentSectionAddr = utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, ScKeynodes::rrel_2); + + ScAction testAction = context.ConvertToAction(testActionNode); + + context.SubscribeAgent(); + + testAction.InitiateAndWait(WAIT_TIME); + + ScStructure result = testAction.GetResult(); + + ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::NodeConst); EXPECT_TRUE(it3->Next()); EXPECT_TRUE(context.IsElement(it3->Get(2))); ScAddr decompositionTupleAddr = sections_utils::GetSectionDecompositionTuple(&context, parentSectionAddr); EXPECT_EQ(utils::CommonUtils::getSetPower(&context, decompositionTupleAddr), 1u); - SC_AGENT_UNREGISTER(AddSectionAgent) + context.UnsubscribeAgent(); } TEST_F(AddSectionTest, add_section_invalid_parameters_1) { - ScMemoryContext & context = *m_ctx; - scAgentsCommon::CoreKeynodes::InitGlobal(); - SectionsKeynodes::InitGlobal(); + ScAgentContext & context = *m_ctx; - SC_AGENT_REGISTER(AddSectionAgent) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_add_section.scs"); ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node3"); - EXPECT_TRUE(utils::AgentUtils::applyAction(&context, testActionNode, WAIT_TIME)); - EXPECT_TRUE(context.HelperCheckEdge( - scAgentsCommon::CoreKeynodes::question_finished_unsuccessfully, testActionNode, ScType::EdgeAccessConstPosPerm)); + ScAction testAction = context.ConvertToAction(testActionNode); - SC_AGENT_UNREGISTER(AddSectionAgent) + context.SubscribeAgent(); + + testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.IsFinishedUnsuccessfully()); + context.UnsubscribeAgent(); } TEST_F(AddSectionTest, add_section_invalid_parameters_3) { - ScMemoryContext & context = *m_ctx; - scAgentsCommon::CoreKeynodes::InitGlobal(); - SectionsKeynodes::InitGlobal(); + ScAgentContext & context = *m_ctx; - SC_AGENT_REGISTER(AddSectionAgent) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_add_section.scs"); ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node4"); - EXPECT_TRUE(utils::AgentUtils::applyAction(&context, testActionNode, WAIT_TIME)); - EXPECT_TRUE(context.HelperCheckEdge( - scAgentsCommon::CoreKeynodes::question_finished_unsuccessfully, testActionNode, ScType::EdgeAccessConstPosPerm)); + ScAction testAction = context.ConvertToAction(testActionNode); + + context.SubscribeAgent(); - SC_AGENT_UNREGISTER(AddSectionAgent) + testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.IsFinishedUnsuccessfully()); + context.UnsubscribeAgent(); } TEST_F(AddSectionTest, add_section_without_parent) { - ScMemoryContext & context = *m_ctx; - scAgentsCommon::CoreKeynodes::InitGlobal(); - SectionsKeynodes::InitGlobal(); + ScAgentContext & context = *m_ctx; - SC_AGENT_REGISTER(AddSectionAgent) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_add_section.scs"); ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node5"); - ScAddr sectionNameAddr = - utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, scAgentsCommon::CoreKeynodes::rrel_1); - - EXPECT_TRUE(utils::AgentUtils::applyAction(&context, testActionNode, WAIT_TIME)); - ScIterator5Ptr it5 = context.Iterator5( - testActionNode, - ScType::EdgeDCommon, - ScType::Unknown, - ScType::EdgeAccessConstPosPerm, - scAgentsCommon::CoreKeynodes::nrel_answer); - EXPECT_TRUE(it5->Next()); - - ScIterator3Ptr it3 = context.Iterator3(it5->Get(2), ScType::EdgeAccessConstPosPerm, ScType::NodeConst); + ScAddr sectionNameAddr = utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, ScKeynodes::rrel_1); + ScAction testAction = context.ConvertToAction(testActionNode); + + context.SubscribeAgent(); + + testAction.InitiateAndWait(WAIT_TIME); + ScStructure result = testAction.GetResult(); + + ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::NodeConst); EXPECT_TRUE(it3->Next()); EXPECT_TRUE(context.IsElement(it3->Get(2))); @@ -164,6 +145,6 @@ TEST_F(AddSectionTest, add_section_without_parent) EXPECT_TRUE(context.IsElement(sectionAddr)); EXPECT_EQ(it3->Get(2), sectionAddr); - SC_AGENT_UNREGISTER(AddSectionAgent) + context.UnsubscribeAgent(); } } // namespace subjDomainTest diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp index 1f74940c..0a046872 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp @@ -11,11 +11,8 @@ #include "sc_test.hpp" -#include "sc-agents-common/keynodes/coreKeynodes.hpp" #include "sc-agents-common/utils/CommonUtils.hpp" -#include "sc-agents-common/utils/AgentUtils.hpp" - -#include "sc-memory/kpm/sc_agent.hpp" +#include #include "sc-memory/utils/sc_base64.hpp" #include @@ -39,33 +36,21 @@ int const WAIT_TIME = 1000; using GetSectionDecompositionTest = ScMemoryTest; -void initialize() -{ - scAgentsCommon::CoreKeynodes::InitGlobal(); - SectionsKeynodes::InitGlobal(); - - SC_AGENT_REGISTER(GetDecompositionAgent) -} - -void shutdown(){SC_AGENT_UNREGISTER(GetDecompositionAgent)} - TEST_F(GetSectionDecompositionTest, successful_decomposition) { - ScMemoryContext & context = *m_ctx; - initialize(); + ScAgentContext & context = *m_ctx; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_successful_decomposition.scs"); ScAddr const testActionNode = context.HelperFindBySystemIdtf("test_action_node"); - utils::AgentUtils::applyAction(&context, testActionNode, WAIT_TIME); - ScIterator5Ptr it5 = context.Iterator5( - testActionNode, - ScType::EdgeDCommon, - ScType::Unknown, - ScType::EdgeAccessConstPosPerm, - scAgentsCommon::CoreKeynodes::nrel_answer); - EXPECT_TRUE(it5->Next()); + ScAction testAction = context.ConvertToAction(testActionNode); - ScIterator3Ptr const it3 = context.Iterator3(it5->Get(2), ScType::EdgeAccessConstPosPerm, ScType::Link); + context.SubscribeAgent(); + + testAction.InitiateAndWait(WAIT_TIME); + ScStructure result = testAction.GetResult(); + + + ScIterator3Ptr const it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Link); EXPECT_TRUE(it3->Next()); std::string decompositionContent; context.GetLinkContent(it3->Get(2), decompositionContent); @@ -76,26 +61,23 @@ TEST_F(GetSectionDecompositionTest, successful_decomposition) json testJson = GetTestJSON(); EXPECT_EQ(temp, GetTestJSON()); - shutdown(); + context.UnsubscribeAgent(); } TEST_F(GetSectionDecompositionTest, successful_decomposition_with_level) { - ScMemoryContext & context = *m_ctx; - initialize(); + ScAgentContext & context = *m_ctx; + loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_successful_decomposition.scs"); ScAddr const testActionNode = context.HelperFindBySystemIdtf("test_action_node2"); + ScAction testAction = context.ConvertToAction(testActionNode); + + context.SubscribeAgent(); + + testAction.InitiateAndWait(WAIT_TIME); + ScStructure result = testAction.GetResult(); - context.CreateEdge(ScType::EdgeAccessConstPosPerm, scAgentsCommon::CoreKeynodes::question_initiated, testActionNode); - EXPECT_TRUE(utils::AgentUtils::applyAction(&context, testActionNode, WAIT_TIME)); - ScIterator5Ptr const it5 = context.Iterator5( - testActionNode, - ScType::EdgeDCommon, - ScType::Unknown, - ScType::EdgeAccessConstPosPerm, - scAgentsCommon::CoreKeynodes::nrel_answer); - EXPECT_TRUE(it5->Next()); - ScIterator3Ptr it3 = context.Iterator3(it5->Get(2), ScType::EdgeAccessConstPosPerm, ScType::Link); + ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Link); EXPECT_TRUE(it3->Next()); std::string decompositionText; @@ -107,7 +89,7 @@ TEST_F(GetSectionDecompositionTest, successful_decomposition_with_level) json testJson = GetTestJSON(2); EXPECT_EQ(temp, GetTestJSON(2)); - shutdown(); + context.UnsubscribeAgent(); } json GetDecompositionIdList(json const & answerDecomposition, int level) diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/remove_section_agent_test.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/remove_section_agent_test.cpp index 599ed59a..33f499ed 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/remove_section_agent_test.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/remove_section_agent_test.cpp @@ -13,11 +13,9 @@ #include "sc_test.hpp" #include "sc-agents-common/utils/CommonUtils.hpp" -#include "sc-agents-common/utils/AgentUtils.hpp" #include "sc-agents-common/utils/IteratorUtils.hpp" -#include "sc-memory/kpm/sc_agent.hpp" - +#include #include using namespace sectionsModule; @@ -33,63 +31,53 @@ using RemoveSectionTest = ScMemoryTest; TEST_F(RemoveSectionTest, successful_remove_section_from_decomposition) { - ScMemoryContext & context = *m_ctx; - scAgentsCommon::CoreKeynodes::InitGlobal(); - SectionsKeynodes::InitGlobal(); - SC_AGENT_REGISTER(RemoveSectionAgent) + ScAgentContext & context = *m_ctx; + ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_remove_section.scs"); + ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node"); - ScAddr sectionAddr = - utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, scAgentsCommon::CoreKeynodes::rrel_1); - ScAddr parentSectionAddr = - utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, scAgentsCommon::CoreKeynodes::rrel_2); + ScAction testAction = context.ConvertToAction(testActionNode); + + ScAddr sectionAddr = utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, ScKeynodes::rrel_1); + ScAddr parentSectionAddr = utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, ScKeynodes::rrel_2); ScAddr decompositionTupleAddr = sections_utils::GetSectionDecompositionTuple(&context, parentSectionAddr); size_t decompositionSize = utils::CommonUtils::getSetPower(&context, decompositionTupleAddr); - context.CreateEdge(ScType::EdgeAccessConstPosPerm, scAgentsCommon::CoreKeynodes::question_initiated, testActionNode); - utils::AgentUtils::applyAction(&context, testActionNode, 1000); - ScIterator5Ptr it5 = context.Iterator5( - testActionNode, - ScType::EdgeDCommon, - ScType::Unknown, - ScType::EdgeAccessConstPosPerm, - scAgentsCommon::CoreKeynodes::nrel_answer); - EXPECT_TRUE(it5->Next()); - ScIterator3Ptr it3 = context.Iterator3(it5->Get(2), ScType::EdgeAccessConstPosPerm, ScType::Unknown); + context.SubscribeAgent(); + + testAction.InitiateAndWait(WAIT_TIME); + ScStructure result = testAction.GetResult(); + + ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Unknown); EXPECT_TRUE(it3->Next()); EXPECT_TRUE(context.HelperCheckEdge(SectionsKeynodes::removed_section, sectionAddr, ScType::EdgeAccessConstPosPerm)); EXPECT_EQ(decompositionSize - utils::CommonUtils::getSetPower(&context, decompositionTupleAddr), 1u); - SC_AGENT_UNREGISTER(RemoveSectionAgent) + context.UnsubscribeAgent(); } TEST_F(RemoveSectionTest, successful_remove_section_from_decomposition_2) { - ScMemoryContext & context = *m_ctx; - scAgentsCommon::CoreKeynodes::InitGlobal(); - SectionsKeynodes::InitGlobal(); + ScAgentContext & context = *m_ctx; - SC_AGENT_REGISTER(RemoveSectionAgent) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_remove_section.scs"); + ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node2"); - ScAddr sectionAddr = - utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, scAgentsCommon::CoreKeynodes::rrel_1); - ScAddr parentSectionAddr = - utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, scAgentsCommon::CoreKeynodes::rrel_2); - - context.CreateEdge(ScType::EdgeAccessConstPosPerm, scAgentsCommon::CoreKeynodes::question_initiated, testActionNode); - utils::AgentUtils::applyAction(&context, testActionNode, WAIT_TIME); - ScIterator5Ptr it5 = context.Iterator5( - testActionNode, - ScType::EdgeDCommon, - ScType::Unknown, - ScType::EdgeAccessConstPosPerm, - scAgentsCommon::CoreKeynodes::nrel_answer); - EXPECT_TRUE(it5->Next()); - ScIterator3Ptr it3 = context.Iterator3(it5->Get(2), ScType::EdgeAccessConstPosPerm, ScType::NodeConst); + ScAction testAction = context.ConvertToAction(testActionNode); + + context.SubscribeAgent(); + + ScAddr sectionAddr = utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, ScKeynodes::rrel_1); + ScAddr parentSectionAddr = utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, ScKeynodes::rrel_2); + + testAction.InitiateAndWait(WAIT_TIME); + + ScStructure result = testAction.GetResult(); + + ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::NodeConst); EXPECT_TRUE(it3->Next()); ScTemplate scTemplate; scTemplate.Quintuple( @@ -102,41 +90,44 @@ TEST_F(RemoveSectionTest, successful_remove_section_from_decomposition_2) context.HelperSearchTemplate(scTemplate, searchResult); EXPECT_TRUE(searchResult.IsEmpty()); EXPECT_TRUE(context.HelperCheckEdge(SectionsKeynodes::removed_section, sectionAddr, ScType::EdgeAccessConstPosPerm)); - SC_AGENT_UNREGISTER(RemoveSectionAgent) + + context.UnsubscribeAgent(); } TEST_F(RemoveSectionTest, remove_section_invalid_parameters_1) { - ScMemoryContext & context = *m_ctx; - scAgentsCommon::CoreKeynodes::InitGlobal(); - SectionsKeynodes::InitGlobal(); + ScAgentContext & context = *m_ctx; - SC_AGENT_REGISTER(RemoveSectionAgent) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_remove_section.scs"); + ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node3"); + ScAction testAction = context.ConvertToAction(testActionNode); + + context.SubscribeAgent(); - EXPECT_TRUE(utils::AgentUtils::applyAction(&context, testActionNode, WAIT_TIME)); - EXPECT_TRUE(context.HelperCheckEdge( - scAgentsCommon::CoreKeynodes::question_finished_unsuccessfully, testActionNode, ScType::EdgeAccessConstPosPerm)); + testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.IsFinishedUnsuccessfully()); - SC_AGENT_UNREGISTER(RemoveSectionAgent) + context.UnsubscribeAgent(); } TEST_F(RemoveSectionTest, remove_section_without_parent) { - ScMemoryContext & context = *m_ctx; - scAgentsCommon::CoreKeynodes::InitGlobal(); - SectionsKeynodes::InitGlobal(); + ScAgentContext & context = *m_ctx; - SC_AGENT_REGISTER(RemoveSectionAgent) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_remove_section.scs"); + ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node4"); - ScAddr sectionAddr = - utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, scAgentsCommon::CoreKeynodes::rrel_1); + ScAction testAction = context.ConvertToAction(testActionNode); + + context.SubscribeAgent(); + + ScAddr sectionAddr = utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, ScKeynodes::rrel_1); + + testAction.InitiateAndWait(WAIT_TIME); - EXPECT_TRUE(utils::AgentUtils::applyAction(&context, testActionNode, WAIT_TIME)); EXPECT_TRUE(context.HelperCheckEdge(SectionsKeynodes::removed_section, sectionAddr, ScType::EdgeAccessConstPosPerm)); ScTemplate scTemplate; scTemplate.Quintuple( @@ -150,6 +141,6 @@ TEST_F(RemoveSectionTest, remove_section_without_parent) context.HelperSearchTemplate(scTemplate, searchResult); EXPECT_TRUE(searchResult.IsEmpty()); - SC_AGENT_UNREGISTER(RemoveSectionAgent) + context.UnsubscribeAgent(); } } // namespace subjDomainTest From 5f564e240717f1d8803e6ee479ece2c369fd9b51 Mon Sep 17 00:00:00 2001 From: Anna Makarenko Date: Tue, 17 Sep 2024 19:07:09 +0300 Subject: [PATCH 3/9] [refactor][tests] Clang refactoring --- ...anslate_main_system_idtfs_from_sc_to_file_agent.cpp | 10 ++-------- .../cxx/sections-module/agent/add_section_agent.cpp | 5 +---- .../test/units/get_decomposition_agent_test.cpp | 1 - 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp index d3e40dfe..e8d8b6b0 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp @@ -46,14 +46,8 @@ ScResult TranslateMainSystemIdtfsFromScToFileAgent::DoProgram(ScActionInitiatedE if (!systemIdentifier.empty() && !mainIdentifier.empty() && !stringType.empty()) { - streamIdtfs << R"({")" - << mainIdentifier << - R"(", )" - << R"({")" - << systemIdentifier << - R"(", ")" - << stringType << - R"("}},\n)"; + streamIdtfs << R"({")" << mainIdentifier << R"(", )" + << R"({")" << systemIdentifier << R"(", ")" << stringType << R"("}},\n)"; } } catch (utils::ScException const & exception) diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp index 2acbba4c..f6839a81 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp @@ -45,10 +45,7 @@ ScResult AddSectionAgent::DoProgram(ScActionInitiatedEvent const & event, ScActi std::string sectionName; m_context.GetLinkContent(sectionNameAddr, sectionName); - SC_LOG_DEBUG( - R"(AddSectionAgent: new section name is ")" - << sectionName << - R"(".)"); + SC_LOG_DEBUG(R"(AddSectionAgent: new section name is ")" << sectionName << R"(".)"); ScAddr sectionAddr; if (m_context.IsElement(parentSectionAddr)) sectionAddr = GenerateSection(sectionName, parentSectionAddr, langAddr); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp index 0a046872..ce40de0f 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp @@ -49,7 +49,6 @@ TEST_F(GetSectionDecompositionTest, successful_decomposition) testAction.InitiateAndWait(WAIT_TIME); ScStructure result = testAction.GetResult(); - ScIterator3Ptr const it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Link); EXPECT_TRUE(it3->Next()); std::string decompositionContent; From 64ff45f037a958f64b7f6009fa14a6266371d42a Mon Sep 17 00:00:00 2001 From: Anna Makarenko Date: Tue, 17 Sep 2024 19:08:13 +0300 Subject: [PATCH 4/9] [docs] Update changelog --- docs/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.md b/docs/changelog.md index 35f15405..df8dcc75 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -24,3 +24,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deprecated ### Removed +- Remove codegen for agents From f8fd5ca985b2465a2b1aa3b9b34d5da07b80b066 Mon Sep 17 00:00:00 2001 From: Anna Makarenko Date: Wed, 18 Sep 2024 22:37:29 +0300 Subject: [PATCH 5/9] Review fixes --- ...ain_system_idtfs_from_sc_to_file_agent.cpp | 16 ++------- .../identifiers-module/test/units/test.cpp | 10 +++--- .../agent/add_section_agent.cpp | 15 ++------ .../agent/get_decomposition_agent.cpp | 32 +++++------------ .../agent/remove_section_agent.cpp | 36 ++++++------------- .../test/units/add_section_agent_test.cpp | 10 +++--- .../units/get_decomposition_agent_test.cpp | 4 +-- .../test/units/remove_section_agent_test.cpp | 8 ++--- 8 files changed, 41 insertions(+), 90 deletions(-) diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp index e8d8b6b0..34fc9525 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp @@ -12,13 +12,6 @@ using namespace identifiersModule; ScResult TranslateMainSystemIdtfsFromScToFileAgent::DoProgram(ScActionInitiatedEvent const & event, ScAction & action) { - ScAddr const & actionAddr = event.GetOtherElement(); - - if (!CheckAction(actionAddr)) - return action.FinishSuccessfully(); - - SC_LOG_DEBUG("TranslateMainSystemIdtfsFromScToFileAgent started"); - // TODO: replace by ScKeynodes::nrel_system_identifier after release ScAddr const & nrelSystemIdtf = m_context.HelperFindBySystemIdtf("nrel_system_identifier"); @@ -55,14 +48,14 @@ ScResult TranslateMainSystemIdtfsFromScToFileAgent::DoProgram(ScActionInitiatedE SC_LOG_ERROR(exception.Description()); ScStructure result = m_context.GenerateStructure(); - result << actionAddr; - action.SetResult(false); + result << action; + action.SetResult(result); return action.FinishUnsuccessfully(); } } std::string strIdtfs(streamIdtfs.str()); - // Remove last symbols "," and "n" + // Remove last symbols "," and "\n" if (!strIdtfs.empty()) { strIdtfs.pop_back(); @@ -77,13 +70,11 @@ ScResult TranslateMainSystemIdtfsFromScToFileAgent::DoProgram(ScActionInitiatedE if (resultOfWrite) { SC_LOG_DEBUG("File has been created"); - SC_LOG_DEBUG("TranslateMainSystemIdtfsFromScToFileAgent finished"); return action.FinishSuccessfully(); } else { SC_LOG_ERROR("File hasn't been created"); - SC_LOG_DEBUG("TranslateMainSystemIdtfsFromScToFileAgent finished"); return action.FinishUnsuccessfully(); } } @@ -171,7 +162,6 @@ bool TranslateMainSystemIdtfsFromScToFileAgent::WriteInFile(std::string const & { try { - SC_LOG_INFO(IDENTIFIERS_MODULE_PATH); std::ofstream file(IDENTIFIERS_MODULE_PATH "identifiers.txt"); if (file.is_open()) { diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/test/units/test.cpp b/platform-dependent-components/problem-solver/cxx/identifiers-module/test/units/test.cpp index a98243fc..1f2017d3 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/test/units/test.cpp +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/test/units/test.cpp @@ -62,7 +62,7 @@ TEST_F(AgentTest, VoidTest) context.SubscribeAgent(); - testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); EXPECT_TRUE(testAction.IsFinishedSuccessfully()); std::string const fileContent = GetFileContent(); @@ -80,7 +80,7 @@ TEST_F(AgentTest, CorrectTest) context.SubscribeAgent(); - testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); EXPECT_TRUE(testAction.IsFinishedSuccessfully()); std::string const & space = R"({"space", "sc_node_class"})"; @@ -109,7 +109,7 @@ TEST_F(AgentTest, IncorrectTest) context.SubscribeAgent(); - testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); EXPECT_TRUE(testAction.IsFinishedSuccessfully()); std::string const fileContent = GetFileContent(); @@ -125,7 +125,7 @@ TEST_F(AgentTest, IncorrectTest) bool const trueResult = IsSubstringOfFile(trueInput, fileContent); bool const falseResult = IsSubstringOfFile(falseInput, fileContent); - SC_LOG_WARNING(fileContent); + EXPECT_TRUE(!falseResult && trueResult); context.UnsubscribeAgent(); } @@ -138,7 +138,7 @@ TEST_F(AgentTest, ManySystemIdtfsTest) ScAction testAction = context.ConvertToAction(testActionNode); context.SubscribeAgent(); - testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); EXPECT_TRUE(testAction.IsFinishedUnsuccessfully()); context.UnsubscribeAgent(); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp index f6839a81..164cab80 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp @@ -22,16 +22,7 @@ namespace sectionsModule { ScResult AddSectionAgent::DoProgram(ScActionInitiatedEvent const & event, ScAction & action) { - ScAddr const & questionNode = m_context.GetEdgeTarget(event.GetArc()); - if (!CheckActionClass(questionNode)) - return action.FinishSuccessfully(); - - SC_LOG_DEBUG("AddSectionAgent started"); - - ScAddr sectionNameAddr = IteratorUtils::getAnyByOutRelation(&m_context, questionNode, ScKeynodes::rrel_1); - ScAddr parentSectionAddr = IteratorUtils::getAnyByOutRelation(&m_context, questionNode, ScKeynodes::rrel_2); - ScAddr langAddr = IteratorUtils::getAnyByOutRelation(&m_context, questionNode, ScKeynodes::rrel_3); - + auto const [sectionNameAddr, parentSectionAddr, langAddr] = action.GetArguments<3>(); if (!m_context.IsElement(sectionNameAddr)) { SC_LOG_ERROR("AddSectionAgent: section identifier link not found."); @@ -58,10 +49,8 @@ ScResult AddSectionAgent::DoProgram(ScActionInitiatedEvent const & event, ScActi return action.FinishUnsuccessfully(); } ScStructure result = m_context.GenerateStructure(); - for (auto const & identifierNode : (ScAddrVector){sectionAddr}) - result << identifierNode; + result << sectionAddr; action.SetResult(result); - SC_LOG_DEBUG("AddSectionAgent finished"); return action.FinishSuccessfully(); } diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp index f43ad50b..4aacfa9d 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp @@ -18,38 +18,28 @@ namespace sectionsModule { ScResult GetDecompositionAgent::DoProgram(ScActionInitiatedEvent const & event, ScAction & action) { - ScAddr const questionNode = m_context.GetEdgeTarget(event.GetArc()); - if (!CheckActionClass(questionNode)) - return action.FinishSuccessfully(); - - SC_LOG_INFO("GetDecompositionAgent started"); - size_t level = 1; - std::tuple const Tresult = action.GetArguments<4>(); - ScAddr const subjDomainAddr = std::get<0>(Tresult); - ScAddr const levelAddr = std::get<1>(Tresult); - ScAddr const langAddr = std::get<2>(Tresult); - ScAddr decompositionAddr = std::get<3>(Tresult); + auto [subjDomainAddr, levelAddr, langAddr, decompositionAddr] = action.GetArguments<4>(); if (!m_context.IsElement(subjDomainAddr)) { - SC_LOG_ERROR("GetDecompositionAgent: subject domain node not found."); + SC_LOG_ERROR("Subject domain node not found."); return action.FinishUnsuccessfully(); } if (m_context.IsElement(levelAddr)) m_context.GetLinkContent(levelAddr, level); if (!m_context.IsElement(langAddr)) { - SC_LOG_ERROR("GetDecompositionAgent: language node not found."); + SC_LOG_ERROR("Language node not found."); return action.FinishUnsuccessfully(); } if (!m_context.IsElement(decompositionAddr)) { decompositionAddr = SectionsKeynodes::nrel_section_decomposition; SC_LOG_DEBUG( - "GetDecompositionAgent: decomposition relation node not found. By default, " - << m_context.HelperGetSystemIdtf(decompositionAddr) << " is used."); + "Decomposition relation node not found. By default, " << m_context.HelperGetSystemIdtf(decompositionAddr) + << " is used."); } ScAddr answerLink = m_context.CreateLink(); @@ -65,14 +55,10 @@ ScResult GetDecompositionAgent::DoProgram(ScActionInitiatedEvent const & event, SC_LOG_INFO("Result decomposition: " << answerJSONContent); m_context.SetLinkContent(answerLink, answerJSONContent); - ScAddrVector answerElements = {answerLink}; - ScStructure result = m_context.GenerateStructure(); - for (auto const & answerElement : answerElements) - result << answerElement; + result << answerLink; action.SetResult(result); - SC_LOG_INFO("GetDecompositionAgent finished"); return action.FinishSuccessfully(); } @@ -89,7 +75,7 @@ bool GetDecompositionAgent::CheckActionClass(ScAddr const & actionNode) ScAddrVector GetDecompositionAgent::GetDecomposition(ScAddr const & subjDomainAddr, ScAddr const & decompositionAddr) { - SC_LOG_DEBUG("GetDecompositionAgent: main section is " << m_context.HelperGetSystemIdtf(subjDomainAddr) << "."); + SC_LOG_DEBUG("Main section is " << m_context.HelperGetSystemIdtf(subjDomainAddr) << "."); ScAddrVector decomposition; ScTemplate decompositionTemplate; @@ -111,7 +97,7 @@ ScAddrVector GetDecompositionAgent::GetDecomposition(ScAddr const & subjDomainAd { ScAddr tupleNode = result[0][sections_aliases::DECOMPOSITION_TUPLE]; ScAddr subSection = result[0][sections_aliases::SECTION_NODE]; - SC_LOG_DEBUG("GetDecompositionAgent: subsection is " << m_context.HelperGetSystemIdtf(subSection) << "."); + SC_LOG_DEBUG("Subsection is " << m_context.HelperGetSystemIdtf(subSection) << "."); decomposition.push_back(subSection); ScAddr nextSubSection = utils::IteratorUtils::getNextFromSet(&m_context, tupleNode, subSection); @@ -119,7 +105,7 @@ ScAddrVector GetDecompositionAgent::GetDecomposition(ScAddr const & subjDomainAd { decomposition.push_back(nextSubSection); subSection = nextSubSection; - SC_LOG_DEBUG("GetDecompositionAgent: subsection is " << m_context.HelperGetSystemIdtf(subSection) << "."); + SC_LOG_DEBUG("Subsection is " << m_context.HelperGetSystemIdtf(subSection) << "."); nextSubSection = utils::IteratorUtils::getNextFromSet(&m_context, tupleNode, subSection); } } diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp index 87beafe3..7c1e7fb7 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp @@ -22,33 +22,25 @@ namespace sectionsModule { ScResult RemoveSectionAgent::DoProgram(ScActionInitiatedEvent const & event, ScAction & action) { - ScAddr const & questionNode = m_context.GetEdgeTarget(event.GetArc()); - if (!CheckActionClass(questionNode)) - return action.FinishSuccessfully(); - - SC_LOG_DEBUG("RemoveSectionAgent started"); - - ScAddr sectionAddr = IteratorUtils::getAnyByOutRelation(&m_context, questionNode, ScKeynodes::rrel_1); - ScAddr parentSectionAddr = IteratorUtils::getAnyByOutRelation(&m_context, questionNode, ScKeynodes::rrel_2); + ScAddr sectionAddr = IteratorUtils::getAnyByOutRelation(&m_context, action, ScKeynodes::rrel_1); + ScAddr parentSectionAddr = IteratorUtils::getAnyByOutRelation(&m_context, action, ScKeynodes::rrel_2); if (!m_context.IsElement(sectionAddr)) { - SC_LOG_ERROR("RemoveSectionAgent: section node not found."); + SC_LOG_ERROR("Section node not found."); return action.FinishUnsuccessfully(); } bool isSuccess = m_context.IsElement(parentSectionAddr) ? RemoveSection(sectionAddr, parentSectionAddr) : RemoveSection(sectionAddr); if (!isSuccess) { - SC_LOG_ERROR("RemoveSectionAgent: error in the section deletion."); + SC_LOG_ERROR("Error in the section deletion."); return action.FinishUnsuccessfully(); } ScStructure result = m_context.GenerateStructure(); - for (auto const & answerElement : (ScAddrVector){sectionAddr}) - result << answerElement; + result << sectionAddr; action.SetResult(result); - SC_LOG_DEBUG("RemoveSectionAgent finished"); return action.FinishSuccessfully(); } @@ -64,9 +56,8 @@ bool RemoveSectionAgent::CheckActionClass(ScAddr const & actionNode) bool RemoveSectionAgent::RemoveSection(ScAddr const & section, ScAddr const & parentSection) { - SC_LOG_DEBUG("RemoveSectionAgent: section system idtf is " + m_context.HelperGetSystemIdtf(section) + "."); - SC_LOG_DEBUG( - "RemoveSectionAgent: parent section system idtf is " + m_context.HelperGetSystemIdtf(parentSection) + "."); + SC_LOG_DEBUG("Section system idtf is " + m_context.HelperGetSystemIdtf(section) + "."); + SC_LOG_DEBUG("Parent section system idtf is " + m_context.HelperGetSystemIdtf(parentSection) + "."); ScTemplate scTemplate; sections_builder::buildDecompositionTupleTemplate(scTemplate, parentSection, section); ScTemplateSearchResult searchResult; @@ -85,7 +76,7 @@ bool RemoveSectionAgent::RemoveSection(ScAddr const & section, ScAddr const & pa bool RemoveSectionAgent::RemoveSection(ScAddr const & section) { - SC_LOG_DEBUG("RemoveSectionAgent: section system idtf is " << m_context.HelperGetSystemIdtf(section) << "."); + SC_LOG_DEBUG("Section system idtf is " << m_context.HelperGetSystemIdtf(section) << "."); ScTemplate scTemplate; sections_builder::buildDecompositionTupleTemplate(scTemplate, section); ScTemplateSearchResult searchResult; @@ -96,8 +87,7 @@ bool RemoveSectionAgent::RemoveSection(ScAddr const & section) for (size_t i = 0; i < searchResult.Size(); i++) { ScAddr parentSection = searchResult[i][sections_aliases::PARENT_SECTION]; - SC_LOG_DEBUG( - "RemoveSectionAgent: parent section system idtf is " << m_context.HelperGetSystemIdtf(parentSection) << "."); + SC_LOG_DEBUG("Parent section system idtf is " << m_context.HelperGetSystemIdtf(parentSection) << "."); HandleSection(searchResult[i], section); HandleParentSection(searchResult[i], parentSection); } @@ -145,9 +135,7 @@ void RemoveSectionAgent::HandleNeighboringSections(ScAddr const & tuple, ScAddr previousSection = previousSectionSearchResult[0][sections_aliases::SECTION_NODE]; previousSectionEdge = previousSectionSearchResult[0][sections_aliases::PREVIOUS_SECTION_ARC]; currentSectionEdge = previousSectionSearchResult[0][sections_aliases::SECTION_EDGE]; - SC_LOG_DEBUG( - "RemoveSectionAgent: previous neighboring section system idtf is " - + m_context.HelperGetSystemIdtf(previousSection) + "."); + SC_LOG_DEBUG("Previous neighboring section system idtf is " + m_context.HelperGetSystemIdtf(previousSection) + "."); } ScTemplate nextSectionTemplate; @@ -162,9 +150,7 @@ void RemoveSectionAgent::HandleNeighboringSections(ScAddr const & tuple, ScAddr nextSection = nextSectionSearchResult[0][sections_aliases::SECTION_NODE]; nextSectionEdge = nextSectionSearchResult[0][sections_aliases::NEXT_SECTION_ARC]; currentSectionEdge = nextSectionSearchResult[0][sections_aliases::SECTION_EDGE]; - SC_LOG_DEBUG( - "RemoveSectionAgent: next neighboring section system idtf is " << m_context.HelperGetSystemIdtf(nextSection) - << "."); + SC_LOG_DEBUG("Next neighboring section system idtf is " << m_context.HelperGetSystemIdtf(nextSection) << "."); } // If current element is the first and the last diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/add_section_agent_test.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/add_section_agent_test.cpp index db8279c8..ad4c5c2d 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/add_section_agent_test.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/add_section_agent_test.cpp @@ -46,7 +46,7 @@ TEST_F(AddSectionTest, successful_add_section_to_decomposition) context.SubscribeAgent(); - testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); ScStructure result = testAction.GetResult(); ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Unknown); @@ -72,7 +72,7 @@ TEST_F(AddSectionTest, successful_add_section_empty_decomposition) context.SubscribeAgent(); - testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); ScStructure result = testAction.GetResult(); @@ -98,7 +98,7 @@ TEST_F(AddSectionTest, add_section_invalid_parameters_1) context.SubscribeAgent(); - testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); EXPECT_TRUE(testAction.IsFinishedUnsuccessfully()); context.UnsubscribeAgent(); } @@ -115,7 +115,7 @@ TEST_F(AddSectionTest, add_section_invalid_parameters_3) context.SubscribeAgent(); - testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); EXPECT_TRUE(testAction.IsFinishedUnsuccessfully()); context.UnsubscribeAgent(); } @@ -132,7 +132,7 @@ TEST_F(AddSectionTest, add_section_without_parent) context.SubscribeAgent(); - testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); ScStructure result = testAction.GetResult(); ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::NodeConst); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp index ce40de0f..06e6888c 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp @@ -46,7 +46,7 @@ TEST_F(GetSectionDecompositionTest, successful_decomposition) context.SubscribeAgent(); - testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); ScStructure result = testAction.GetResult(); ScIterator3Ptr const it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Link); @@ -73,7 +73,7 @@ TEST_F(GetSectionDecompositionTest, successful_decomposition_with_level) context.SubscribeAgent(); - testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); ScStructure result = testAction.GetResult(); ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Link); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/remove_section_agent_test.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/remove_section_agent_test.cpp index 33f499ed..6f1fa6c7 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/remove_section_agent_test.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/remove_section_agent_test.cpp @@ -46,7 +46,7 @@ TEST_F(RemoveSectionTest, successful_remove_section_from_decomposition) context.SubscribeAgent(); - testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); ScStructure result = testAction.GetResult(); ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Unknown); @@ -73,7 +73,7 @@ TEST_F(RemoveSectionTest, successful_remove_section_from_decomposition_2) ScAddr sectionAddr = utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, ScKeynodes::rrel_1); ScAddr parentSectionAddr = utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, ScKeynodes::rrel_2); - testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); ScStructure result = testAction.GetResult(); @@ -106,7 +106,7 @@ TEST_F(RemoveSectionTest, remove_section_invalid_parameters_1) context.SubscribeAgent(); - testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); EXPECT_TRUE(testAction.IsFinishedUnsuccessfully()); context.UnsubscribeAgent(); @@ -126,7 +126,7 @@ TEST_F(RemoveSectionTest, remove_section_without_parent) ScAddr sectionAddr = utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, ScKeynodes::rrel_1); - testAction.InitiateAndWait(WAIT_TIME); + EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); EXPECT_TRUE(context.HelperCheckEdge(SectionsKeynodes::removed_section, sectionAddr, ScType::EdgeAccessConstPosPerm)); ScTemplate scTemplate; From 106ee0732d6772811ec003d0f80874b41735bac9 Mon Sep 17 00:00:00 2001 From: Anna Makarenko Date: Wed, 18 Sep 2024 22:41:46 +0300 Subject: [PATCH 6/9] Review fixes --- .../cxx/sections-module/agent/add_section_agent.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp index 164cab80..68a8d80c 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp @@ -25,18 +25,18 @@ ScResult AddSectionAgent::DoProgram(ScActionInitiatedEvent const & event, ScActi auto const [sectionNameAddr, parentSectionAddr, langAddr] = action.GetArguments<3>(); if (!m_context.IsElement(sectionNameAddr)) { - SC_LOG_ERROR("AddSectionAgent: section identifier link not found."); + SC_LOG_ERROR("Section identifier link not found."); return action.FinishUnsuccessfully(); } if (!m_context.IsElement(langAddr)) { - SC_LOG_ERROR("AddSectionAgent: lang node not found."); + SC_LOG_ERROR("Lang node not found."); return action.FinishUnsuccessfully(); } std::string sectionName; m_context.GetLinkContent(sectionNameAddr, sectionName); - SC_LOG_DEBUG(R"(AddSectionAgent: new section name is ")" << sectionName << R"(".)"); + SC_LOG_DEBUG(R"(New section name is ")" << sectionName << R"(".)"); ScAddr sectionAddr; if (m_context.IsElement(parentSectionAddr)) sectionAddr = GenerateSection(sectionName, parentSectionAddr, langAddr); @@ -45,7 +45,7 @@ ScResult AddSectionAgent::DoProgram(ScActionInitiatedEvent const & event, ScActi if (!m_context.IsElement(sectionAddr)) { - SC_LOG_ERROR("AddSectionAgent: section is not generated."); + SC_LOG_ERROR("Section is not generated."); return action.FinishUnsuccessfully(); } ScStructure result = m_context.GenerateStructure(); @@ -87,8 +87,7 @@ ScAddr AddSectionAgent::GenerateSection( ScAddr newSectionArc = m_context.CreateEdge(ScType::EdgeAccessConstPosPerm, decompositionTuple, newSection); if (m_context.IsElement(lastSection)) { - SC_LOG_DEBUG( - "AddSectionAgent: last section system idtf is \"" + m_context.HelperGetSystemIdtf(lastSection) + "\"."); + SC_LOG_DEBUG("Last section system idtf is \"" + m_context.HelperGetSystemIdtf(lastSection) + "\"."); ScIterator5Ptr lastSectionIterator = m_context.Iterator5( decompositionTuple, ScType::EdgeAccessConstPosPerm, @@ -108,7 +107,7 @@ ScAddr AddSectionAgent::GenerateSection( } else { - SC_LOG_DEBUG("AddSectionAgent: added section is new."); + SC_LOG_DEBUG("Added section is new."); m_context.CreateEdge(ScType::EdgeAccessConstPosPerm, ScKeynodes::rrel_1, newSectionArc); m_context.CreateEdge(ScType::EdgeAccessConstPosTemp, SectionsKeynodes::rrel_last, newSectionArc); } From 49e420bedad18768bcb4bf6109020430903503f0 Mon Sep 17 00:00:00 2001 From: Anna Makarenko Date: Thu, 19 Sep 2024 10:07:43 +0300 Subject: [PATCH 7/9] Review fixes --- ...ain_system_idtfs_from_sc_to_file_agent.cpp | 18 +++++----- .../identifiers-module/test/units/test.cpp | 8 ++--- .../agent/add_section_agent.cpp | 16 ++++----- .../agent/get_decomposition_agent.cpp | 14 ++++---- .../agent/remove_section_agent.cpp | 33 ++++++++++--------- .../generator/sections_generator.cpp | 4 +-- .../test/units/add_section_agent_test.cpp | 16 ++++----- .../units/get_decomposition_agent_test.cpp | 8 ++--- .../test/units/remove_section_agent_test.cpp | 22 ++++++------- .../sections-module/utils/sections_utils.cpp | 11 ++++--- .../cxx/sections-module/utils/set_utils.cpp | 6 ++-- 11 files changed, 80 insertions(+), 76 deletions(-) diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp index 34fc9525..581d8c34 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp @@ -13,12 +13,12 @@ using namespace identifiersModule; ScResult TranslateMainSystemIdtfsFromScToFileAgent::DoProgram(ScActionInitiatedEvent const & event, ScAction & action) { // TODO: replace by ScKeynodes::nrel_system_identifier after release - ScAddr const & nrelSystemIdtf = m_context.HelperFindBySystemIdtf("nrel_system_identifier"); + ScAddr const & nrelSystemIdtf = m_context.SearchElementBySystemIdentifier("nrel_system_identifier"); std::stringstream streamIdtfs; ScIterator3Ptr const & iterator3PtrEdgeBelongsToNrelSystemIdtf = - m_context.Iterator3(nrelSystemIdtf, ScType::EdgeAccessConstPosPerm, ScType::EdgeDCommonConst); + m_context.CreateIterator3(nrelSystemIdtf, ScType::EdgeAccessConstPosPerm, ScType::EdgeDCommonConst); ScAddr edgeBelongsToNrelSystemIdtf; ScAddr sourceOfEdgeBelongsToNrelSystemIdtf; @@ -30,7 +30,7 @@ ScResult TranslateMainSystemIdtfsFromScToFileAgent::DoProgram(ScActionInitiatedE while (iterator3PtrEdgeBelongsToNrelSystemIdtf->Next()) { edgeBelongsToNrelSystemIdtf = iterator3PtrEdgeBelongsToNrelSystemIdtf->Get(2); - sourceOfEdgeBelongsToNrelSystemIdtf = m_context.GetEdgeSource(edgeBelongsToNrelSystemIdtf); + sourceOfEdgeBelongsToNrelSystemIdtf = m_context.GetArcSourceElement(edgeBelongsToNrelSystemIdtf); try { systemIdentifier = GetSystemIdtfAndVerifyNode(m_context, sourceOfEdgeBelongsToNrelSystemIdtf); @@ -86,7 +86,7 @@ ScAddr TranslateMainSystemIdtfsFromScToFileAgent::GetActionClass() const bool TranslateMainSystemIdtfsFromScToFileAgent::CheckAction(ScAddr const & actionAddr) { - return m_context.HelperCheckEdge( + return m_context.CheckConnector( IdentifiersKeynodes::action_find_identifiers, actionAddr, ScType::EdgeAccessConstPosPerm); } @@ -96,12 +96,12 @@ std::string TranslateMainSystemIdtfsFromScToFileAgent::GetSystemIdtfAndVerifyNod { std::string identifier; ScAddr identifierLink; - ScIterator5Ptr const & iterator5PtrCheckOnlyOneIdtf = m_context.Iterator5( + ScIterator5Ptr const & iterator5PtrCheckOnlyOneIdtf = m_context.CreateIterator5( node, ScType::EdgeDCommonConst, ScType::LinkConst, ScType::EdgeAccessConstPosPerm, - m_context.HelperFindBySystemIdtf("nrel_system_identifier")); + m_context.SearchElementBySystemIdentifier("nrel_system_identifier")); if (iterator5PtrCheckOnlyOneIdtf->Next()) { @@ -120,14 +120,14 @@ std::string TranslateMainSystemIdtfsFromScToFileAgent::GetMainIdtfAndVerifyNode( std::string identifier; ScAddr mainIdentifierLink; ScAddr mainAnotherIdentifierLink; - ScIterator5Ptr const & iterator5PtrCheckOnlyOneIdtf = m_context.Iterator5( + ScIterator5Ptr const & iterator5PtrCheckOnlyOneIdtf = m_context.CreateIterator5( node, ScType::EdgeDCommonConst, ScType::LinkConst, ScType::EdgeAccessConstPosPerm, ScKeynodes::nrel_main_idtf); bool isLangRu; while (iterator5PtrCheckOnlyOneIdtf->Next()) { mainIdentifierLink = iterator5PtrCheckOnlyOneIdtf->Get(2); - isLangRu = m_context.HelperCheckEdge(ScKeynodes::lang_ru, mainIdentifierLink, ScType::EdgeAccessConstPosPerm); + isLangRu = m_context.CheckConnector(ScKeynodes::lang_ru, mainIdentifierLink, ScType::EdgeAccessConstPosPerm); if (isLangRu) { @@ -135,7 +135,7 @@ std::string TranslateMainSystemIdtfsFromScToFileAgent::GetMainIdtfAndVerifyNode( { mainAnotherIdentifierLink = iterator5PtrCheckOnlyOneIdtf->Get(2); isLangRu = - m_context.HelperCheckEdge(ScKeynodes::lang_ru, mainAnotherIdentifierLink, ScType::EdgeAccessConstPosPerm); + m_context.CheckConnector(ScKeynodes::lang_ru, mainAnotherIdentifierLink, ScType::EdgeAccessConstPosPerm); if (isLangRu) return identifier; diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/test/units/test.cpp b/platform-dependent-components/problem-solver/cxx/identifiers-module/test/units/test.cpp index 1f2017d3..b392c5c8 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/test/units/test.cpp +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/test/units/test.cpp @@ -57,7 +57,7 @@ TEST_F(AgentTest, VoidTest) { ScAgentContext & context = *m_ctx; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "void_test.scs"); - ScAddr const & testActionNode = context.HelperFindBySystemIdtf("test_action_node"); + ScAddr const & testActionNode = context.SearchElementBySystemIdentifier("test_action_node"); ScAction testAction = context.ConvertToAction(testActionNode); context.SubscribeAgent(); @@ -75,7 +75,7 @@ TEST_F(AgentTest, CorrectTest) { ScAgentContext & context = *m_ctx; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "correct_test.scs"); - ScAddr const & testActionNode = context.HelperFindBySystemIdtf("test_action_node"); + ScAddr const & testActionNode = context.SearchElementBySystemIdentifier("test_action_node"); ScAction testAction = context.ConvertToAction(testActionNode); context.SubscribeAgent(); @@ -104,7 +104,7 @@ TEST_F(AgentTest, IncorrectTest) { ScAgentContext & context = *m_ctx; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "incorrect_test.scs"); - ScAddr const & testActionNode = context.HelperFindBySystemIdtf("test_action_node"); + ScAddr const & testActionNode = context.SearchElementBySystemIdentifier("test_action_node"); ScAction testAction = context.ConvertToAction(testActionNode); context.SubscribeAgent(); @@ -134,7 +134,7 @@ TEST_F(AgentTest, ManySystemIdtfsTest) { ScAgentContext & context = *m_ctx; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "many_system_idtfs_test.scs"); - ScAddr const & testActionNode = context.HelperFindBySystemIdtf("test_action_node"); + ScAddr const & testActionNode = context.SearchElementBySystemIdentifier("test_action_node"); ScAction testAction = context.ConvertToAction(testActionNode); context.SubscribeAgent(); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp index 68a8d80c..405f23cc 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp @@ -61,7 +61,7 @@ ScAddr AddSectionAgent::GetActionClass() const bool AddSectionAgent::CheckActionClass(ScAddr const & actionNode) { - return m_context.HelperCheckEdge(SectionsKeynodes::action_add_section, actionNode, ScType::EdgeAccessConstPosPerm); + return m_context.CheckConnector(SectionsKeynodes::action_add_section, actionNode, ScType::EdgeAccessConstPosPerm); } ScAddr AddSectionAgent::GenerateSection( @@ -78,17 +78,17 @@ ScAddr AddSectionAgent::GenerateSection( newSection = sections_generator::GenerateSection(&m_context, sectionName, lang, true); else { - if (m_context.HelperCheckEdge(decompositionTuple, newSection, ScType::EdgeAccessConstPosPerm) + if (m_context.CheckConnector(decompositionTuple, newSection, ScType::EdgeAccessConstPosPerm) || parentSection == newSection) return {}; } ScAddr lastSection = sections_utils::GetLastSubSection(&m_context, decompositionTuple); - ScAddr newSectionArc = m_context.CreateEdge(ScType::EdgeAccessConstPosPerm, decompositionTuple, newSection); + ScAddr newSectionArc = m_context.GenerateConnector(ScType::EdgeAccessConstPosPerm, decompositionTuple, newSection); if (m_context.IsElement(lastSection)) { - SC_LOG_DEBUG("Last section system idtf is \"" + m_context.HelperGetSystemIdtf(lastSection) + "\"."); - ScIterator5Ptr lastSectionIterator = m_context.Iterator5( + SC_LOG_DEBUG("Last section system idtf is \"" + m_context.GetElementSystemIdentifier(lastSection) + "\"."); + ScIterator5Ptr lastSectionIterator = m_context.CreateIterator5( decompositionTuple, ScType::EdgeAccessConstPosPerm, lastSection, @@ -102,14 +102,14 @@ ScAddr AddSectionAgent::GenerateSection( utils::GenerationUtils::generateRelationBetween( &m_context, previousSectionArc, newSectionArc, ScKeynodes::nrel_basic_sequence); - m_context.CreateEdge(ScType::EdgeAccessConstPosTemp, SectionsKeynodes::rrel_last, newSectionArc); + m_context.GenerateConnector(ScType::EdgeAccessConstPosTemp, SectionsKeynodes::rrel_last, newSectionArc); } } else { SC_LOG_DEBUG("Added section is new."); - m_context.CreateEdge(ScType::EdgeAccessConstPosPerm, ScKeynodes::rrel_1, newSectionArc); - m_context.CreateEdge(ScType::EdgeAccessConstPosTemp, SectionsKeynodes::rrel_last, newSectionArc); + m_context.GenerateConnector(ScType::EdgeAccessConstPosPerm, ScKeynodes::rrel_1, newSectionArc); + m_context.GenerateConnector(ScType::EdgeAccessConstPosTemp, SectionsKeynodes::rrel_last, newSectionArc); } sectionsModule::SetUtils::AddToSets(&m_context, parentSection, {SectionsKeynodes::non_atomic_section}); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp index 4aacfa9d..de8c8347 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp @@ -38,11 +38,11 @@ ScResult GetDecompositionAgent::DoProgram(ScActionInitiatedEvent const & event, { decompositionAddr = SectionsKeynodes::nrel_section_decomposition; SC_LOG_DEBUG( - "Decomposition relation node not found. By default, " << m_context.HelperGetSystemIdtf(decompositionAddr) + "Decomposition relation node not found. By default, " << m_context.GetElementSystemIdentifier(decompositionAddr) << " is used."); } - ScAddr answerLink = m_context.CreateLink(); + ScAddr answerLink = m_context.GenerateLink(); ScAddrVector decomposition = GetDecomposition(subjDomainAddr, decompositionAddr); json answerJSON{ @@ -69,13 +69,13 @@ ScAddr GetDecompositionAgent::GetActionClass() const bool GetDecompositionAgent::CheckActionClass(ScAddr const & actionNode) { - return m_context.HelperCheckEdge( + return m_context.CheckConnector( SectionsKeynodes::action_get_decomposition, actionNode, ScType::EdgeAccessConstPosPerm); } ScAddrVector GetDecompositionAgent::GetDecomposition(ScAddr const & subjDomainAddr, ScAddr const & decompositionAddr) { - SC_LOG_DEBUG("Main section is " << m_context.HelperGetSystemIdtf(subjDomainAddr) << "."); + SC_LOG_DEBUG("Main section is " << m_context.GetElementSystemIdentifier(subjDomainAddr) << "."); ScAddrVector decomposition; ScTemplate decompositionTemplate; @@ -92,12 +92,12 @@ ScAddrVector GetDecompositionAgent::GetDecomposition(ScAddr const & subjDomainAd ScType::EdgeAccessVarPosPerm, ScKeynodes::rrel_1); ScTemplateSearchResult result; - m_context.HelperSearchTemplate(decompositionTemplate, result); + m_context.SearchByTemplate(decompositionTemplate, result); if (!result.IsEmpty()) { ScAddr tupleNode = result[0][sections_aliases::DECOMPOSITION_TUPLE]; ScAddr subSection = result[0][sections_aliases::SECTION_NODE]; - SC_LOG_DEBUG("Subsection is " << m_context.HelperGetSystemIdtf(subSection) << "."); + SC_LOG_DEBUG("Subsection is " << m_context.GetElementSystemIdentifier(subSection) << "."); decomposition.push_back(subSection); ScAddr nextSubSection = utils::IteratorUtils::getNextFromSet(&m_context, tupleNode, subSection); @@ -105,7 +105,7 @@ ScAddrVector GetDecompositionAgent::GetDecomposition(ScAddr const & subjDomainAd { decomposition.push_back(nextSubSection); subSection = nextSubSection; - SC_LOG_DEBUG("Subsection is " << m_context.HelperGetSystemIdtf(subSection) << "."); + SC_LOG_DEBUG("Subsection is " << m_context.GetElementSystemIdentifier(subSection) << "."); nextSubSection = utils::IteratorUtils::getNextFromSet(&m_context, tupleNode, subSection); } } diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp index 7c1e7fb7..b28020e2 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp @@ -51,17 +51,17 @@ ScAddr RemoveSectionAgent::GetActionClass() const bool RemoveSectionAgent::CheckActionClass(ScAddr const & actionNode) { - return m_context.HelperCheckEdge(SectionsKeynodes::action_remove_section, actionNode, ScType::EdgeAccessConstPosPerm); + return m_context.CheckConnector(SectionsKeynodes::action_remove_section, actionNode, ScType::EdgeAccessConstPosPerm); } bool RemoveSectionAgent::RemoveSection(ScAddr const & section, ScAddr const & parentSection) { - SC_LOG_DEBUG("Section system idtf is " + m_context.HelperGetSystemIdtf(section) + "."); - SC_LOG_DEBUG("Parent section system idtf is " + m_context.HelperGetSystemIdtf(parentSection) + "."); + SC_LOG_DEBUG("Section system idtf is " + m_context.GetElementSystemIdentifier(section) + "."); + SC_LOG_DEBUG("Parent section system idtf is " + m_context.GetElementSystemIdentifier(parentSection) + "."); ScTemplate scTemplate; sections_builder::buildDecompositionTupleTemplate(scTemplate, parentSection, section); ScTemplateSearchResult searchResult; - m_context.HelperSearchTemplate(scTemplate, searchResult); + m_context.SearchByTemplate(scTemplate, searchResult); if (!searchResult.IsEmpty()) { @@ -76,18 +76,18 @@ bool RemoveSectionAgent::RemoveSection(ScAddr const & section, ScAddr const & pa bool RemoveSectionAgent::RemoveSection(ScAddr const & section) { - SC_LOG_DEBUG("Section system idtf is " << m_context.HelperGetSystemIdtf(section) << "."); + SC_LOG_DEBUG("Section system idtf is " << m_context.GetElementSystemIdentifier(section) << "."); ScTemplate scTemplate; sections_builder::buildDecompositionTupleTemplate(scTemplate, section); ScTemplateSearchResult searchResult; - m_context.HelperSearchTemplate(scTemplate, searchResult); + m_context.SearchByTemplate(scTemplate, searchResult); if (!searchResult.IsEmpty()) { for (size_t i = 0; i < searchResult.Size(); i++) { ScAddr parentSection = searchResult[i][sections_aliases::PARENT_SECTION]; - SC_LOG_DEBUG("Parent section system idtf is " << m_context.HelperGetSystemIdtf(parentSection) << "."); + SC_LOG_DEBUG("Parent section system idtf is " << m_context.GetElementSystemIdentifier(parentSection) << "."); HandleSection(searchResult[i], section); HandleParentSection(searchResult[i], parentSection); } @@ -95,7 +95,7 @@ bool RemoveSectionAgent::RemoveSection(ScAddr const & section) return true; } - ScAddr edge = m_context.CreateEdge(ScType::EdgeAccessConstPosPerm, SectionsKeynodes::removed_section, section); + ScAddr edge = m_context.GenerateConnector(ScType::EdgeAccessConstPosPerm, SectionsKeynodes::removed_section, section); return m_context.IsElement(edge); } @@ -125,7 +125,7 @@ void RemoveSectionAgent::HandleNeighboringSections(ScAddr const & tuple, ScAddr ScTemplate previousSectionTemplate; sections_builder::buildPreviousSectionTemplate(previousSectionTemplate, tuple, section); ScTemplateSearchResult previousSectionSearchResult; - m_context.HelperSearchTemplate(previousSectionTemplate, previousSectionSearchResult); + m_context.SearchByTemplate(previousSectionTemplate, previousSectionSearchResult); ScAddr currentSectionEdge; ScAddr previousSection; @@ -135,13 +135,14 @@ void RemoveSectionAgent::HandleNeighboringSections(ScAddr const & tuple, ScAddr previousSection = previousSectionSearchResult[0][sections_aliases::SECTION_NODE]; previousSectionEdge = previousSectionSearchResult[0][sections_aliases::PREVIOUS_SECTION_ARC]; currentSectionEdge = previousSectionSearchResult[0][sections_aliases::SECTION_EDGE]; - SC_LOG_DEBUG("Previous neighboring section system idtf is " + m_context.HelperGetSystemIdtf(previousSection) + "."); + SC_LOG_DEBUG( + "Previous neighboring section system idtf is " + m_context.GetElementSystemIdentifier(previousSection) + "."); } ScTemplate nextSectionTemplate; sections_builder::buildNextSectionTemplate(nextSectionTemplate, tuple, section); ScTemplateSearchResult nextSectionSearchResult; - m_context.HelperSearchTemplate(nextSectionTemplate, nextSectionSearchResult); + m_context.SearchByTemplate(nextSectionTemplate, nextSectionSearchResult); ScAddr nextSection; ScAddr nextSectionEdge; @@ -150,13 +151,15 @@ void RemoveSectionAgent::HandleNeighboringSections(ScAddr const & tuple, ScAddr nextSection = nextSectionSearchResult[0][sections_aliases::SECTION_NODE]; nextSectionEdge = nextSectionSearchResult[0][sections_aliases::NEXT_SECTION_ARC]; currentSectionEdge = nextSectionSearchResult[0][sections_aliases::SECTION_EDGE]; - SC_LOG_DEBUG("Next neighboring section system idtf is " << m_context.HelperGetSystemIdtf(nextSection) << "."); + SC_LOG_DEBUG( + "Next neighboring section system idtf is " << m_context.GetElementSystemIdentifier(nextSection) << "."); } // If current element is the first and the last if (!m_context.IsElement(currentSectionEdge)) { - ScIterator3Ptr currentSectionEdgeIterator = m_context.Iterator3(tuple, ScType::EdgeAccessConstPosPerm, section); + ScIterator3Ptr currentSectionEdgeIterator = + m_context.CreateIterator3(tuple, ScType::EdgeAccessConstPosPerm, section); if (currentSectionEdgeIterator->Next()) { currentSectionEdge = currentSectionEdgeIterator->Get(1); @@ -174,13 +177,13 @@ void RemoveSectionAgent::HandleNeighboringSections(ScAddr const & tuple, ScAddr // If current element is the last if (m_context.IsElement(previousSection) && !m_context.IsElement(nextSection)) { - m_context.CreateEdge(ScType::EdgeAccessConstPosTemp, SectionsKeynodes::rrel_last, previousSectionEdge); + m_context.GenerateConnector(ScType::EdgeAccessConstPosTemp, SectionsKeynodes::rrel_last, previousSectionEdge); } // If current element is the first if (!m_context.IsElement(previousSection) && m_context.IsElement(nextSection)) { - m_context.CreateEdge(ScType::EdgeAccessConstPosPerm, ScKeynodes::rrel_1, nextSectionEdge); + m_context.GenerateConnector(ScType::EdgeAccessConstPosPerm, ScKeynodes::rrel_1, nextSectionEdge); } } diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/generator/sections_generator.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/generator/sections_generator.cpp index d533f4d0..92cd4d8e 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/generator/sections_generator.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/generator/sections_generator.cpp @@ -19,7 +19,7 @@ ScAddr sections_generator::GenerateSection( ScAddr const & lang, bool isAtomic) { - ScAddr section = context->CreateNode(ScType::NodeConstClass); + ScAddr section = context->GenerateNode(ScType::NodeConstClass); utils::CommonUtils::setMainIdtf(context, section, sectionName, {lang}); ScTemplate sectionTemplate; @@ -30,7 +30,7 @@ ScAddr sections_generator::GenerateSection( sectionTemplate.Triple(SectionsKeynodes::non_atomic_section, ScType::EdgeAccessVarPosPerm, section); sectionTemplate.Triple(SectionsKeynodes::not_enough_formed_structure, ScType::EdgeAccessVarPosPerm, section); ScTemplateGenResult genResult; - context->HelperGenTemplate(sectionTemplate, genResult); + context->GenerateByTemplate(sectionTemplate, genResult); return section; } diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/add_section_agent_test.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/add_section_agent_test.cpp index ad4c5c2d..25bfefb9 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/add_section_agent_test.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/add_section_agent_test.cpp @@ -37,7 +37,7 @@ TEST_F(AddSectionTest, successful_add_section_to_decomposition) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_add_section.scs"); - ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node"); + ScAddr testActionNode = context.SearchElementBySystemIdentifier("test_action_node"); ScAction testAction = context.ConvertToAction(testActionNode); ScAddr parentSectionAddr = utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, ScKeynodes::rrel_2); @@ -49,7 +49,7 @@ TEST_F(AddSectionTest, successful_add_section_to_decomposition) EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); ScStructure result = testAction.GetResult(); - ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Unknown); + ScIterator3Ptr it3 = context.CreateIterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Unknown); EXPECT_TRUE(it3->Next()); EXPECT_TRUE(context.IsElement(it3->Get(2))); @@ -65,7 +65,7 @@ TEST_F(AddSectionTest, successful_add_section_empty_decomposition) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_add_section.scs"); - ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node2"); + ScAddr testActionNode = context.SearchElementBySystemIdentifier("test_action_node2"); ScAddr parentSectionAddr = utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, ScKeynodes::rrel_2); ScAction testAction = context.ConvertToAction(testActionNode); @@ -76,7 +76,7 @@ TEST_F(AddSectionTest, successful_add_section_empty_decomposition) ScStructure result = testAction.GetResult(); - ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::NodeConst); + ScIterator3Ptr it3 = context.CreateIterator3(result, ScType::EdgeAccessConstPosPerm, ScType::NodeConst); EXPECT_TRUE(it3->Next()); EXPECT_TRUE(context.IsElement(it3->Get(2))); @@ -92,7 +92,7 @@ TEST_F(AddSectionTest, add_section_invalid_parameters_1) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_add_section.scs"); - ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node3"); + ScAddr testActionNode = context.SearchElementBySystemIdentifier("test_action_node3"); ScAction testAction = context.ConvertToAction(testActionNode); @@ -109,7 +109,7 @@ TEST_F(AddSectionTest, add_section_invalid_parameters_3) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_add_section.scs"); - ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node4"); + ScAddr testActionNode = context.SearchElementBySystemIdentifier("test_action_node4"); ScAction testAction = context.ConvertToAction(testActionNode); @@ -126,7 +126,7 @@ TEST_F(AddSectionTest, add_section_without_parent) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_add_section.scs"); - ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node5"); + ScAddr testActionNode = context.SearchElementBySystemIdentifier("test_action_node5"); ScAddr sectionNameAddr = utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, ScKeynodes::rrel_1); ScAction testAction = context.ConvertToAction(testActionNode); @@ -135,7 +135,7 @@ TEST_F(AddSectionTest, add_section_without_parent) EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); ScStructure result = testAction.GetResult(); - ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::NodeConst); + ScIterator3Ptr it3 = context.CreateIterator3(result, ScType::EdgeAccessConstPosPerm, ScType::NodeConst); EXPECT_TRUE(it3->Next()); EXPECT_TRUE(context.IsElement(it3->Get(2))); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp index 06e6888c..cf4f3a40 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/get_decomposition_agent_test.cpp @@ -40,7 +40,7 @@ TEST_F(GetSectionDecompositionTest, successful_decomposition) { ScAgentContext & context = *m_ctx; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_successful_decomposition.scs"); - ScAddr const testActionNode = context.HelperFindBySystemIdtf("test_action_node"); + ScAddr const testActionNode = context.SearchElementBySystemIdentifier("test_action_node"); ScAction testAction = context.ConvertToAction(testActionNode); @@ -49,7 +49,7 @@ TEST_F(GetSectionDecompositionTest, successful_decomposition) EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); ScStructure result = testAction.GetResult(); - ScIterator3Ptr const it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Link); + ScIterator3Ptr const it3 = context.CreateIterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Link); EXPECT_TRUE(it3->Next()); std::string decompositionContent; context.GetLinkContent(it3->Get(2), decompositionContent); @@ -68,7 +68,7 @@ TEST_F(GetSectionDecompositionTest, successful_decomposition_with_level) ScAgentContext & context = *m_ctx; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_successful_decomposition.scs"); - ScAddr const testActionNode = context.HelperFindBySystemIdtf("test_action_node2"); + ScAddr const testActionNode = context.SearchElementBySystemIdentifier("test_action_node2"); ScAction testAction = context.ConvertToAction(testActionNode); context.SubscribeAgent(); @@ -76,7 +76,7 @@ TEST_F(GetSectionDecompositionTest, successful_decomposition_with_level) EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); ScStructure result = testAction.GetResult(); - ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Link); + ScIterator3Ptr it3 = context.CreateIterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Link); EXPECT_TRUE(it3->Next()); std::string decompositionText; diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/remove_section_agent_test.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/remove_section_agent_test.cpp index 6f1fa6c7..d764a8e3 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/test/units/remove_section_agent_test.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/test/units/remove_section_agent_test.cpp @@ -36,7 +36,7 @@ TEST_F(RemoveSectionTest, successful_remove_section_from_decomposition) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_remove_section.scs"); - ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node"); + ScAddr testActionNode = context.SearchElementBySystemIdentifier("test_action_node"); ScAction testAction = context.ConvertToAction(testActionNode); ScAddr sectionAddr = utils::IteratorUtils::getAnyByOutRelation(&context, testActionNode, ScKeynodes::rrel_1); @@ -49,10 +49,10 @@ TEST_F(RemoveSectionTest, successful_remove_section_from_decomposition) EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); ScStructure result = testAction.GetResult(); - ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Unknown); + ScIterator3Ptr it3 = context.CreateIterator3(result, ScType::EdgeAccessConstPosPerm, ScType::Unknown); EXPECT_TRUE(it3->Next()); - EXPECT_TRUE(context.HelperCheckEdge(SectionsKeynodes::removed_section, sectionAddr, ScType::EdgeAccessConstPosPerm)); + EXPECT_TRUE(context.CheckConnector(SectionsKeynodes::removed_section, sectionAddr, ScType::EdgeAccessConstPosPerm)); EXPECT_EQ(decompositionSize - utils::CommonUtils::getSetPower(&context, decompositionTupleAddr), 1u); context.UnsubscribeAgent(); @@ -65,7 +65,7 @@ TEST_F(RemoveSectionTest, successful_remove_section_from_decomposition_2) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_remove_section.scs"); - ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node2"); + ScAddr testActionNode = context.SearchElementBySystemIdentifier("test_action_node2"); ScAction testAction = context.ConvertToAction(testActionNode); context.SubscribeAgent(); @@ -77,7 +77,7 @@ TEST_F(RemoveSectionTest, successful_remove_section_from_decomposition_2) ScStructure result = testAction.GetResult(); - ScIterator3Ptr it3 = context.Iterator3(result, ScType::EdgeAccessConstPosPerm, ScType::NodeConst); + ScIterator3Ptr it3 = context.CreateIterator3(result, ScType::EdgeAccessConstPosPerm, ScType::NodeConst); EXPECT_TRUE(it3->Next()); ScTemplate scTemplate; scTemplate.Quintuple( @@ -87,9 +87,9 @@ TEST_F(RemoveSectionTest, successful_remove_section_from_decomposition_2) ScType::EdgeAccessVarPosPerm, SectionsKeynodes::nrel_entity_decomposition); ScTemplateSearchResult searchResult; - context.HelperSearchTemplate(scTemplate, searchResult); + context.SearchByTemplate(scTemplate, searchResult); EXPECT_TRUE(searchResult.IsEmpty()); - EXPECT_TRUE(context.HelperCheckEdge(SectionsKeynodes::removed_section, sectionAddr, ScType::EdgeAccessConstPosPerm)); + EXPECT_TRUE(context.CheckConnector(SectionsKeynodes::removed_section, sectionAddr, ScType::EdgeAccessConstPosPerm)); context.UnsubscribeAgent(); } @@ -101,7 +101,7 @@ TEST_F(RemoveSectionTest, remove_section_invalid_parameters_1) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_remove_section.scs"); - ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node3"); + ScAddr testActionNode = context.SearchElementBySystemIdentifier("test_action_node3"); ScAction testAction = context.ConvertToAction(testActionNode); context.SubscribeAgent(); @@ -119,7 +119,7 @@ TEST_F(RemoveSectionTest, remove_section_without_parent) ScsLoader loader; loader.loadScsFile(context, TEST_FILES_DIR_PATH + "test_remove_section.scs"); - ScAddr testActionNode = context.HelperFindBySystemIdtf("test_action_node4"); + ScAddr testActionNode = context.SearchElementBySystemIdentifier("test_action_node4"); ScAction testAction = context.ConvertToAction(testActionNode); context.SubscribeAgent(); @@ -128,7 +128,7 @@ TEST_F(RemoveSectionTest, remove_section_without_parent) EXPECT_TRUE(testAction.InitiateAndWait(WAIT_TIME)); - EXPECT_TRUE(context.HelperCheckEdge(SectionsKeynodes::removed_section, sectionAddr, ScType::EdgeAccessConstPosPerm)); + EXPECT_TRUE(context.CheckConnector(SectionsKeynodes::removed_section, sectionAddr, ScType::EdgeAccessConstPosPerm)); ScTemplate scTemplate; scTemplate.Quintuple( ScType::NodeVarTuple >> sections_aliases::DECOMPOSITION_TUPLE, @@ -138,7 +138,7 @@ TEST_F(RemoveSectionTest, remove_section_without_parent) SectionsKeynodes::nrel_entity_decomposition); scTemplate.Triple(sections_aliases::DECOMPOSITION_TUPLE, ScType::EdgeAccessVarPosPerm, sectionAddr); ScTemplateSearchResult searchResult; - context.HelperSearchTemplate(scTemplate, searchResult); + context.SearchByTemplate(scTemplate, searchResult); EXPECT_TRUE(searchResult.IsEmpty()); context.UnsubscribeAgent(); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.cpp index 17cdc74f..9e863665 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.cpp @@ -27,12 +27,13 @@ ScAddr sections_utils::GetSectionDecompositionTuple(ScMemoryContext * context, S ScType::EdgeAccessVarPosPerm, SectionsKeynodes::nrel_entity_decomposition); ScTemplateSearchResult searchResult; - context->HelperSearchTemplate(scTemplate, searchResult); + context->SearchByTemplate(scTemplate, searchResult); if (!searchResult.IsEmpty()) return searchResult[0][sections_aliases::DECOMPOSITION_TUPLE]; - ScTemplateGenResult genResult; - ScTemplate::Result result = context->HelperGenTemplate(scTemplate, genResult); - if (result) + ScTemplateResultItem genResult; + context->GenerateByTemplate(scTemplate, genResult); + + if (genResult.Size() != 0) return genResult[sections_aliases::DECOMPOSITION_TUPLE]; return {}; } @@ -40,7 +41,7 @@ ScAddr sections_utils::GetSectionDecompositionTuple(ScMemoryContext * context, S ScAddr sections_utils::FindSectionByName(ScMemoryContext * context, std::string const & sectionName) { ScAddr sectionAddr; - ScAddrVector links = context->FindLinksByContent(sectionName); + ScAddrSet links = context->SearchLinksByContentSubstring(sectionName); if (!links.empty()) { for (ScAddr const & link : links) diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/utils/set_utils.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/utils/set_utils.cpp index ad07b698..23d99763 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/utils/set_utils.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/utils/set_utils.cpp @@ -19,7 +19,7 @@ ScAddrVector SetUtils::GetAllElementsByEdgeType(ScMemoryContext * context, ScAdd ScTemplate rightsTemplate; rightsTemplate.Triple(set, edgeType, ScType::NodeVar >> "_node"); ScTemplateSearchResult result; - context->HelperSearchTemplate(rightsTemplate, result); + context->SearchByTemplate(rightsTemplate, result); if (!result.IsEmpty()) { for (int i = 0; i < result.Size(); i++) @@ -33,7 +33,7 @@ ScAddr SetUtils::GetEdge(ScMemoryContext * context, ScAddr const & source, ScAdd ScTemplate scTemplate; scTemplate.Triple(source, ScType::EdgeAccessVarPosPerm >> "_edge", target); ScTemplateSearchResult result; - context->HelperSearchTemplate(scTemplate, result); + context->SearchByTemplate(scTemplate, result); if (!result.IsEmpty()) return result[0]["_edge"]; else @@ -58,7 +58,7 @@ void SetUtils::RemoveFromSets(ScMemoryContext * context, ScAddr const & element, void SetUtils::RemoveBaseEdgesFromSet(ScMemoryContext * context, ScAddr const & set) { - ScIterator3Ptr setElementsIterator = context->Iterator3(set, ScType::EdgeAccessConstPosPerm, ScType::Unknown); + ScIterator3Ptr setElementsIterator = context->CreateIterator3(set, ScType::EdgeAccessConstPosPerm, ScType::Unknown); while (setElementsIterator->Next()) { From a85147c42d5147cc6c427552113a7870e2d30d42 Mon Sep 17 00:00:00 2001 From: Anna Makarenko Date: Thu, 19 Sep 2024 10:32:34 +0300 Subject: [PATCH 8/9] Review fixes --- ...e_main_system_idtfs_from_sc_to_file_agent.cpp | 6 +++--- .../sections-module/agent/add_section_agent.cpp | 12 ++++++------ .../agent/get_decomposition_agent.cpp | 14 +++++++------- .../agent/remove_section_agent.cpp | 16 ++++++++-------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp index 581d8c34..4ec1b2eb 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp @@ -40,7 +40,7 @@ ScResult TranslateMainSystemIdtfsFromScToFileAgent::DoProgram(ScActionInitiatedE if (!systemIdentifier.empty() && !mainIdentifier.empty() && !stringType.empty()) { streamIdtfs << R"({")" << mainIdentifier << R"(", )" - << R"({")" << systemIdentifier << R"(", ")" << stringType << R"("}},\n)"; + << R"({")" << systemIdentifier << R"(", ")" << stringType << R"("}},)" << "\n"; } } catch (utils::ScException const & exception) @@ -69,12 +69,12 @@ ScResult TranslateMainSystemIdtfsFromScToFileAgent::DoProgram(ScActionInitiatedE if (resultOfWrite) { - SC_LOG_DEBUG("File has been created"); + SC_AGENT_LOG_DEBUG("File has been created"); return action.FinishSuccessfully(); } else { - SC_LOG_ERROR("File hasn't been created"); + SC_AGENT_LOG_ERROR("File hasn't been created"); return action.FinishUnsuccessfully(); } } diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp index 405f23cc..2c2b4a9a 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp @@ -25,18 +25,18 @@ ScResult AddSectionAgent::DoProgram(ScActionInitiatedEvent const & event, ScActi auto const [sectionNameAddr, parentSectionAddr, langAddr] = action.GetArguments<3>(); if (!m_context.IsElement(sectionNameAddr)) { - SC_LOG_ERROR("Section identifier link not found."); + SC_AGENT_LOG_ERROR("Section identifier link not found."); return action.FinishUnsuccessfully(); } if (!m_context.IsElement(langAddr)) { - SC_LOG_ERROR("Lang node not found."); + SC_AGENT_LOG_ERROR("Lang node not found."); return action.FinishUnsuccessfully(); } std::string sectionName; m_context.GetLinkContent(sectionNameAddr, sectionName); - SC_LOG_DEBUG(R"(New section name is ")" << sectionName << R"(".)"); + SC_AGENT_LOG_DEBUG(R"(New section name is ")" << sectionName << R"(".)"); ScAddr sectionAddr; if (m_context.IsElement(parentSectionAddr)) sectionAddr = GenerateSection(sectionName, parentSectionAddr, langAddr); @@ -45,7 +45,7 @@ ScResult AddSectionAgent::DoProgram(ScActionInitiatedEvent const & event, ScActi if (!m_context.IsElement(sectionAddr)) { - SC_LOG_ERROR("Section is not generated."); + SC_AGENT_LOG_ERROR("Section is not generated."); return action.FinishUnsuccessfully(); } ScStructure result = m_context.GenerateStructure(); @@ -87,7 +87,7 @@ ScAddr AddSectionAgent::GenerateSection( ScAddr newSectionArc = m_context.GenerateConnector(ScType::EdgeAccessConstPosPerm, decompositionTuple, newSection); if (m_context.IsElement(lastSection)) { - SC_LOG_DEBUG("Last section system idtf is \"" + m_context.GetElementSystemIdentifier(lastSection) + "\"."); + SC_AGENT_LOG_DEBUG("Last section system idtf is \"" + m_context.GetElementSystemIdentifier(lastSection) + "\"."); ScIterator5Ptr lastSectionIterator = m_context.CreateIterator5( decompositionTuple, ScType::EdgeAccessConstPosPerm, @@ -107,7 +107,7 @@ ScAddr AddSectionAgent::GenerateSection( } else { - SC_LOG_DEBUG("Added section is new."); + SC_AGENT_LOG_DEBUG("Added section is new."); m_context.GenerateConnector(ScType::EdgeAccessConstPosPerm, ScKeynodes::rrel_1, newSectionArc); m_context.GenerateConnector(ScType::EdgeAccessConstPosTemp, SectionsKeynodes::rrel_last, newSectionArc); } diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp index de8c8347..eb9580a0 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp @@ -24,20 +24,20 @@ ScResult GetDecompositionAgent::DoProgram(ScActionInitiatedEvent const & event, if (!m_context.IsElement(subjDomainAddr)) { - SC_LOG_ERROR("Subject domain node not found."); + SC_AGENT_LOG_ERROR("Subject domain node not found."); return action.FinishUnsuccessfully(); } if (m_context.IsElement(levelAddr)) m_context.GetLinkContent(levelAddr, level); if (!m_context.IsElement(langAddr)) { - SC_LOG_ERROR("Language node not found."); + SC_AGENT_LOG_ERROR("Language node not found."); return action.FinishUnsuccessfully(); } if (!m_context.IsElement(decompositionAddr)) { decompositionAddr = SectionsKeynodes::nrel_section_decomposition; - SC_LOG_DEBUG( + SC_AGENT_LOG_DEBUG( "Decomposition relation node not found. By default, " << m_context.GetElementSystemIdentifier(decompositionAddr) << " is used."); } @@ -52,7 +52,7 @@ ScResult GetDecompositionAgent::DoProgram(ScActionInitiatedEvent const & event, {"position", 0}}}}; std::string answerJSONContent = answerJSON.dump(); - SC_LOG_INFO("Result decomposition: " << answerJSONContent); + SC_AGENT_LOG_INFO("Result decomposition: " << answerJSONContent); m_context.SetLinkContent(answerLink, answerJSONContent); ScStructure result = m_context.GenerateStructure(); @@ -75,7 +75,7 @@ bool GetDecompositionAgent::CheckActionClass(ScAddr const & actionNode) ScAddrVector GetDecompositionAgent::GetDecomposition(ScAddr const & subjDomainAddr, ScAddr const & decompositionAddr) { - SC_LOG_DEBUG("Main section is " << m_context.GetElementSystemIdentifier(subjDomainAddr) << "."); + SC_AGENT_LOG_DEBUG("Main section is " << m_context.GetElementSystemIdentifier(subjDomainAddr) << "."); ScAddrVector decomposition; ScTemplate decompositionTemplate; @@ -97,7 +97,7 @@ ScAddrVector GetDecompositionAgent::GetDecomposition(ScAddr const & subjDomainAd { ScAddr tupleNode = result[0][sections_aliases::DECOMPOSITION_TUPLE]; ScAddr subSection = result[0][sections_aliases::SECTION_NODE]; - SC_LOG_DEBUG("Subsection is " << m_context.GetElementSystemIdentifier(subSection) << "."); + SC_AGENT_LOG_DEBUG("Subsection is " << m_context.GetElementSystemIdentifier(subSection) << "."); decomposition.push_back(subSection); ScAddr nextSubSection = utils::IteratorUtils::getNextFromSet(&m_context, tupleNode, subSection); @@ -105,7 +105,7 @@ ScAddrVector GetDecompositionAgent::GetDecomposition(ScAddr const & subjDomainAd { decomposition.push_back(nextSubSection); subSection = nextSubSection; - SC_LOG_DEBUG("Subsection is " << m_context.GetElementSystemIdentifier(subSection) << "."); + SC_AGENT_LOG_DEBUG("Subsection is " << m_context.GetElementSystemIdentifier(subSection) << "."); nextSubSection = utils::IteratorUtils::getNextFromSet(&m_context, tupleNode, subSection); } } diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp index b28020e2..287ef1c3 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp @@ -27,14 +27,14 @@ ScResult RemoveSectionAgent::DoProgram(ScActionInitiatedEvent const & event, ScA if (!m_context.IsElement(sectionAddr)) { - SC_LOG_ERROR("Section node not found."); + SC_AGENT_LOG_ERROR("Section node not found."); return action.FinishUnsuccessfully(); } bool isSuccess = m_context.IsElement(parentSectionAddr) ? RemoveSection(sectionAddr, parentSectionAddr) : RemoveSection(sectionAddr); if (!isSuccess) { - SC_LOG_ERROR("Error in the section deletion."); + SC_AGENT_LOG_ERROR("Error in the section deletion."); return action.FinishUnsuccessfully(); } @@ -56,8 +56,8 @@ bool RemoveSectionAgent::CheckActionClass(ScAddr const & actionNode) bool RemoveSectionAgent::RemoveSection(ScAddr const & section, ScAddr const & parentSection) { - SC_LOG_DEBUG("Section system idtf is " + m_context.GetElementSystemIdentifier(section) + "."); - SC_LOG_DEBUG("Parent section system idtf is " + m_context.GetElementSystemIdentifier(parentSection) + "."); + SC_AGENT_LOG_DEBUG("Section system idtf is " + m_context.GetElementSystemIdentifier(section) + "."); + SC_AGENT_LOG_DEBUG("Parent section system idtf is " + m_context.GetElementSystemIdentifier(parentSection) + "."); ScTemplate scTemplate; sections_builder::buildDecompositionTupleTemplate(scTemplate, parentSection, section); ScTemplateSearchResult searchResult; @@ -76,7 +76,7 @@ bool RemoveSectionAgent::RemoveSection(ScAddr const & section, ScAddr const & pa bool RemoveSectionAgent::RemoveSection(ScAddr const & section) { - SC_LOG_DEBUG("Section system idtf is " << m_context.GetElementSystemIdentifier(section) << "."); + SC_AGENT_LOG_DEBUG("Section system idtf is " << m_context.GetElementSystemIdentifier(section) << "."); ScTemplate scTemplate; sections_builder::buildDecompositionTupleTemplate(scTemplate, section); ScTemplateSearchResult searchResult; @@ -87,7 +87,7 @@ bool RemoveSectionAgent::RemoveSection(ScAddr const & section) for (size_t i = 0; i < searchResult.Size(); i++) { ScAddr parentSection = searchResult[i][sections_aliases::PARENT_SECTION]; - SC_LOG_DEBUG("Parent section system idtf is " << m_context.GetElementSystemIdentifier(parentSection) << "."); + SC_AGENT_LOG_DEBUG("Parent section system idtf is " << m_context.GetElementSystemIdentifier(parentSection) << "."); HandleSection(searchResult[i], section); HandleParentSection(searchResult[i], parentSection); } @@ -135,7 +135,7 @@ void RemoveSectionAgent::HandleNeighboringSections(ScAddr const & tuple, ScAddr previousSection = previousSectionSearchResult[0][sections_aliases::SECTION_NODE]; previousSectionEdge = previousSectionSearchResult[0][sections_aliases::PREVIOUS_SECTION_ARC]; currentSectionEdge = previousSectionSearchResult[0][sections_aliases::SECTION_EDGE]; - SC_LOG_DEBUG( + SC_AGENT_LOG_DEBUG( "Previous neighboring section system idtf is " + m_context.GetElementSystemIdentifier(previousSection) + "."); } @@ -151,7 +151,7 @@ void RemoveSectionAgent::HandleNeighboringSections(ScAddr const & tuple, ScAddr nextSection = nextSectionSearchResult[0][sections_aliases::SECTION_NODE]; nextSectionEdge = nextSectionSearchResult[0][sections_aliases::NEXT_SECTION_ARC]; currentSectionEdge = nextSectionSearchResult[0][sections_aliases::SECTION_EDGE]; - SC_LOG_DEBUG( + SC_AGENT_LOG_DEBUG( "Next neighboring section system idtf is " << m_context.GetElementSystemIdentifier(nextSection) << "."); } From 8dd32b52cd7252efd2dd0353c076da9d256849b0 Mon Sep 17 00:00:00 2001 From: Anna Makarenko Date: Thu, 19 Sep 2024 10:44:27 +0300 Subject: [PATCH 9/9] Review fixes --- .../translate_main_system_idtfs_from_sc_to_file_agent.cpp | 6 ------ .../translate_main_system_idtfs_from_sc_to_file_agent.hpp | 2 +- .../cxx/sections-module/agent/add_section_agent.cpp | 5 ----- .../cxx/sections-module/agent/add_section_agent.hpp | 2 -- .../cxx/sections-module/agent/get_decomposition_agent.cpp | 6 ------ .../cxx/sections-module/agent/get_decomposition_agent.hpp | 2 -- .../cxx/sections-module/agent/remove_section_agent.cpp | 5 ----- .../cxx/sections-module/agent/remove_section_agent.hpp | 2 -- .../cxx/sections-module/utils/sections_utils.cpp | 4 +--- 9 files changed, 2 insertions(+), 32 deletions(-) diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp index 4ec1b2eb..a73356fa 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.cpp @@ -84,12 +84,6 @@ ScAddr TranslateMainSystemIdtfsFromScToFileAgent::GetActionClass() const return IdentifiersKeynodes::action_find_identifiers; } -bool TranslateMainSystemIdtfsFromScToFileAgent::CheckAction(ScAddr const & actionAddr) -{ - return m_context.CheckConnector( - IdentifiersKeynodes::action_find_identifiers, actionAddr, ScType::EdgeAccessConstPosPerm); -} - std::string TranslateMainSystemIdtfsFromScToFileAgent::GetSystemIdtfAndVerifyNode( ScMemoryContext & m_context, ScAddr const & node) diff --git a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.hpp b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.hpp index 6536cec5..a91fd10c 100644 --- a/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.hpp +++ b/platform-dependent-components/problem-solver/cxx/identifiers-module/agent/translate_main_system_idtfs_from_sc_to_file_agent.hpp @@ -82,7 +82,7 @@ class TranslateMainSystemIdtfsFromScToFileAgent : public ScActionInitiatedAgent {ScType::EdgeAccessVarFuzTemp, "sc_edge_main"}}; private: - bool CheckAction(ScAddr const & actionAddr); + std::string GetStrScType(ScAddr const & node); static std::string GetSystemIdtfAndVerifyNode(ScMemoryContext & m_memoryCtx, ScAddr const & node); static std::string GetMainIdtfAndVerifyNode(ScMemoryContext & m_memoryCtx, ScAddr const & node); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp index 2c2b4a9a..bae19d87 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.cpp @@ -59,11 +59,6 @@ ScAddr AddSectionAgent::GetActionClass() const return SectionsKeynodes::action_add_section; } -bool AddSectionAgent::CheckActionClass(ScAddr const & actionNode) -{ - return m_context.CheckConnector(SectionsKeynodes::action_add_section, actionNode, ScType::EdgeAccessConstPosPerm); -} - ScAddr AddSectionAgent::GenerateSection( std::string const & sectionName, ScAddr const & parentSection, diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.hpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.hpp index eb8ab898..82cb3a8a 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.hpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/add_section_agent.hpp @@ -18,8 +18,6 @@ class AddSectionAgent : public ScActionInitiatedAgent ScResult DoProgram(ScActionInitiatedEvent const & event, ScAction & action) override; private: - bool CheckActionClass(ScAddr const & actionNode); - ScAddr GenerateSection(std::string const & sectionName, ScAddr const & parentSection, ScAddr const & lang); ScAddr GenerateSection(std::string const & sectionName, ScAddr const & lang); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp index eb9580a0..18d83652 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.cpp @@ -67,12 +67,6 @@ ScAddr GetDecompositionAgent::GetActionClass() const return SectionsKeynodes::action_get_decomposition; } -bool GetDecompositionAgent::CheckActionClass(ScAddr const & actionNode) -{ - return m_context.CheckConnector( - SectionsKeynodes::action_get_decomposition, actionNode, ScType::EdgeAccessConstPosPerm); -} - ScAddrVector GetDecompositionAgent::GetDecomposition(ScAddr const & subjDomainAddr, ScAddr const & decompositionAddr) { SC_AGENT_LOG_DEBUG("Main section is " << m_context.GetElementSystemIdentifier(subjDomainAddr) << "."); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.hpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.hpp index 3809aacc..ae9a44d9 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.hpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/get_decomposition_agent.hpp @@ -21,8 +21,6 @@ class GetDecompositionAgent : public ScActionInitiatedAgent ScResult DoProgram(ScActionInitiatedEvent const & event, ScAction & action) override; private: - bool CheckActionClass(ScAddr const & actionNode); - json GetJSONDecomposition(ScAddrVector const &, size_t, ScAddr const &, ScAddr const &); ScAddrVector GetDecomposition(ScAddr const &, ScAddr const &); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp index 287ef1c3..1a808638 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.cpp @@ -49,11 +49,6 @@ ScAddr RemoveSectionAgent::GetActionClass() const return SectionsKeynodes::action_remove_section; } -bool RemoveSectionAgent::CheckActionClass(ScAddr const & actionNode) -{ - return m_context.CheckConnector(SectionsKeynodes::action_remove_section, actionNode, ScType::EdgeAccessConstPosPerm); -} - bool RemoveSectionAgent::RemoveSection(ScAddr const & section, ScAddr const & parentSection) { SC_AGENT_LOG_DEBUG("Section system idtf is " + m_context.GetElementSystemIdentifier(section) + "."); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.hpp b/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.hpp index 065db5fe..9fa1a079 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.hpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/agent/remove_section_agent.hpp @@ -18,8 +18,6 @@ class RemoveSectionAgent : public ScActionInitiatedAgent ScResult DoProgram(ScActionInitiatedEvent const & event, ScAction & action) override; private: - bool CheckActionClass(ScAddr const & actionNode); - bool RemoveSection(ScAddr const & section, ScAddr const & parentSection); bool RemoveSection(ScAddr const & section); diff --git a/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.cpp b/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.cpp index 9e863665..20729942 100644 --- a/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.cpp +++ b/platform-dependent-components/problem-solver/cxx/sections-module/utils/sections_utils.cpp @@ -33,9 +33,7 @@ ScAddr sections_utils::GetSectionDecompositionTuple(ScMemoryContext * context, S ScTemplateResultItem genResult; context->GenerateByTemplate(scTemplate, genResult); - if (genResult.Size() != 0) - return genResult[sections_aliases::DECOMPOSITION_TUPLE]; - return {}; + return genResult[sections_aliases::DECOMPOSITION_TUPLE]; } ScAddr sections_utils::FindSectionByName(ScMemoryContext * context, std::string const & sectionName)