Skip to content

Commit

Permalink
Merge pull request #65 from ostis-ai/fix/new_api
Browse files Browse the repository at this point in the history
Refactor/remove codegen
  • Loading branch information
MakarenkoAI authored Dec 11, 2024
2 parents 5a17c28 + 367c730 commit 46a7ce9
Show file tree
Hide file tree
Showing 240 changed files with 853 additions and 1,198 deletions.
15 changes: 8 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.11)
cmake_minimum_required(VERSION 3.14)
project(ostis-metasystem)
set(CMAKE_CXX_STANDARD 17)

Expand All @@ -15,18 +15,19 @@ 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")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")

if(${SC_CLANG_FORMAT_CODE})
include(${CMAKE_MODULE_PATH}/ClangFormat.cmake)
endif()

set(SC_MEMORY_SRC "${SC_MACHINE_PATH}/sc-memory/")
set(SC_KPM_SRC "${SC_MACHINE_PATH}/sc-kpm/")
set(SC_TOOLS_SRC "${SC_MACHINE_PATH}/sc-tools/")
set(SC_MEMORY_INCLUDE "${SC_MACHINE_PATH}/sc-memory/sc-memory/include")
set(SC_AGENTS_COMMON_INCLUDE "${SC_MACHINE_PATH}/sc-kpm/sc-agents-common/include")
set(SC_CORE_INCLUDE "${SC_MACHINE_PATH}/sc-memory/sc-core/include")
set(SC_BUILDER_INCLUDE "${SC_MACHINE_PATH}/sc-tools/sc-builder/include")
set(SC_CONFIG_INCLUDE "${SC_MACHINE_PATH}/sc-tools/sc-config/include")

include("${CMAKE_CURRENT_SOURCE_DIR}/dependencies.cmake")
sc_target_dependencies()
include(CTest)

# for multi-config builds (e.g. msvc)
foreach(OUTPUT_CONFIG ${CMAKE_CONFIGURATION_TYPES})
Expand Down
18 changes: 0 additions & 18 deletions dependencies.cmake

This file was deleted.

3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added build of sc-machine and manager in `install_metasystem.sh`

### Changed
- This version of the Metasystem is not supported on macOS.
- Rename questions to actions
- Use `build_platform.sh` instead of `build_sc_machine.sh`
- Update ostis-web-platform to develop-branch

Expand All @@ -24,3 +26,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated

### Removed
- Remove codegen for agents
Binary file modified docs/images/translate_agent_input.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions ostis-metasystem.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ max_events_and_agents_threads = 32
dump_memory_period = 3600
dump_memory_statistics_period = 1800

repo_path = kb.bin
extensions_path = bin/extensions
storage = kb.bin
extensions = bin/extensions

log_type = Console
log_file = sc-memory.log
Expand Down
2 changes: 0 additions & 2 deletions platform-dependent-components/problem-solver/cxx/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -16,12 +15,12 @@ target_link_libraries(identifiers-module
)
target_include_directories(identifiers-module
PUBLIC ${IDENTIFIERS_MODULE_SRC}
PUBLIC ${SC_MEMORY_SRC}
PUBLIC ${SC_KPM_SRC}
PUBLIC ${SC_MEMORY_INCLUDE}
PUBLIC ${SC_CORE_INCLUDE}
PUBLIC ${SC_AGENTS_COMMON_INCLUDE}
PUBLIC ${SC_BUILDER_INCLUDE}
)

sc_codegen_ex(identifiers-module ${IDENTIFIERS_MODULE_SRC} ${IDENTIFIERS_MODULE_SRC}/generated)

if(${SC_CLANG_FORMAT_CODE})
target_clangformat_setup(identifiers-module)
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,20 @@
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/

#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)
{
ScAddr const & actionAddr = otherAddr;
#include <sc-memory/sc_memory.hpp>

if (!CheckAction(actionAddr))
return SC_RESULT_OK;

SC_LOG_DEBUG("TranslateMainSystemIdtfsFromScToFileAgent started");
#include "keynodes/identifiers_keynodes.hpp"

// TODO: replace by CoreKeynodes::nrel_system_identifier after release
ScAddr const & nrelSystemIdtf = m_memoryCtx.HelperFindBySystemIdtf("nrel_system_identifier");
using namespace identifiersModule;

ScResult TranslateMainSystemIdtfsFromScToFileAgent::DoProgram(ScAction & action)
{
std::stringstream streamIdtfs;

ScIterator3Ptr const & iterator3PtrEdgeBelongsToNrelSystemIdtf =
m_memoryCtx.Iterator3(nrelSystemIdtf, ScType::EdgeAccessConstPosPerm, ScType::EdgeDCommonConst);
m_context.CreateIterator3(ScKeynodes::nrel_system_identifier, ScType::ConstPermPosArc, ScType::ConstCommonArc);

ScAddr edgeBelongsToNrelSystemIdtf;
ScAddr sourceOfEdgeBelongsToNrelSystemIdtf;
Expand All @@ -38,24 +29,24 @@ SC_AGENT_IMPLEMENTATION(TranslateMainSystemIdtfsFromScToFileAgent)
while (iterator3PtrEdgeBelongsToNrelSystemIdtf->Next())
{
edgeBelongsToNrelSystemIdtf = iterator3PtrEdgeBelongsToNrelSystemIdtf->Get(2);
sourceOfEdgeBelongsToNrelSystemIdtf = m_memoryCtx.GetEdgeSource(edgeBelongsToNrelSystemIdtf);
sourceOfEdgeBelongsToNrelSystemIdtf = m_context.GetArcSourceElement(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;
return action.FinishUnsuccessfully();
}
}

Expand All @@ -73,76 +64,72 @@ SC_AGENT_IMPLEMENTATION(TranslateMainSystemIdtfsFromScToFileAgent)
bool const & resultOfWrite = WriteInFile(strIdtfs);

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");
utils::AgentUtils::finishAgentWork(&m_memoryCtx, actionAddr, resultOfWrite);
SC_LOG_DEBUG("TranslateMainSystemIdtfsFromScToFileAgent finished");
return SC_RESULT_OK;
{
SC_AGENT_LOG_ERROR("File hasn't been created");
return action.FinishUnsuccessfully();
}
}

bool TranslateMainSystemIdtfsFromScToFileAgent::CheckAction(ScAddr const & actionAddr)
ScAddr TranslateMainSystemIdtfsFromScToFileAgent::GetActionClass() const
{
return m_memoryCtx.HelperCheckEdge(
IdentifiersKeynodes::action_find_identifiers, actionAddr, ScType::EdgeAccessConstPosPerm);
return IdentifiersKeynodes::action_find_identifiers;
}

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.CreateIterator5(
node,
ScType::EdgeDCommonConst,
ScType::LinkConst,
ScType::EdgeAccessConstPosPerm,
m_memoryCtx.HelperFindBySystemIdtf("nrel_system_identifier"));
ScType::ConstCommonArc,
ScType::ConstNodeLink,
ScType::ConstPermPosArc,
m_context.SearchElementBySystemIdentifier("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.CreateIterator5(
node, ScType::ConstCommonArc, ScType::ConstNodeLink, ScType::ConstPermPosArc, 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.CheckConnector(ScKeynodes::lang_ru, mainIdentifierLink, ScType::ConstPermPosArc);

if (isLangRu)
{
while (iterator5PtrCheckOnlyOneIdtf->Next())
{
mainAnotherIdentifierLink = iterator5PtrCheckOnlyOneIdtf->Get(2);
isLangRu = m_memoryCtx.HelperCheckEdge(
scAgentsCommon::CoreKeynodes::lang_ru, mainAnotherIdentifierLink, ScType::EdgeAccessConstPosPerm);
isLangRu = m_context.CheckConnector(ScKeynodes::lang_ru, mainAnotherIdentifierLink, ScType::ConstPermPosArc);

if (isLangRu)
return identifier;
}
m_memoryCtx.GetLinkContent(mainIdentifierLink, identifier);
m_context.GetLinkContent(mainIdentifierLink, identifier);
break;
}
}
Expand All @@ -152,7 +139,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))
Expand Down
Loading

0 comments on commit 46a7ce9

Please sign in to comment.