Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Refactor/remove codegen #65

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated

### Removed
- Remove codegen for agents
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 @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,20 @@
*/

#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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this agent has question_initiated in docs translate_agent_input.png

{
ScAddr const & actionAddr = otherAddr;

if (!CheckAction(actionAddr))
return SC_RESULT_OK;

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.SearchElementBySystemIdentifier("nrel_system_identifier");

std::stringstream streamIdtfs;

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

ScAddr edgeBelongsToNrelSystemIdtf;
ScAddr sourceOfEdgeBelongsToNrelSystemIdtf;
Expand All @@ -38,24 +30,27 @@ 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)";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everything is printed in one line with \n between entries, I guess previously they were separated with newline
image

}
}
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 << action;
action.SetResult(result);
return action.FinishUnsuccessfully();
}
}

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

if (resultOfWrite)
{
SC_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;
return action.FinishUnsuccessfully();
}
}

ScAddr TranslateMainSystemIdtfsFromScToFileAgent::GetActionClass() const
{
return IdentifiersKeynodes::action_find_identifiers;
}

bool TranslateMainSystemIdtfsFromScToFileAgent::CheckAction(ScAddr const & actionAddr)
kilativ-dotcom marked this conversation as resolved.
Show resolved Hide resolved
{
return m_memoryCtx.HelperCheckEdge(
return m_context.CheckConnector(
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.CreateIterator5(
node,
ScType::EdgeDCommonConst,
ScType::LinkConst,
ScType::EdgeAccessConstPosPerm,
m_memoryCtx.HelperFindBySystemIdtf("nrel_system_identifier"));
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::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.CheckConnector(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.CheckConnector(ScKeynodes::lang_ru, mainAnotherIdentifierLink, ScType::EdgeAccessConstPosPerm);

if (isLangRu)
return identifier;
}
m_memoryCtx.GetLinkContent(mainIdentifierLink, identifier);
m_context.GetLinkContent(mainIdentifierLink, identifier);
break;
}
}
Expand All @@ -152,7 +150,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
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sc-memory/sc_agent.hpp>

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<ScType, std::string> ScTypesOfNodesWithSCsClasses = {
{ScType::Const, "sc_node"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TranslateMainSystemIdtfsFromScToFileAgent>();
Original file line number Diff line number Diff line change
Expand Up @@ -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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@
*/

#pragma once
#include <sc-memory/sc_keynodes.hpp>

#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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_action_node
<- action_find_identifiers;
<- question;;
<- action;;

knowledge
<- sc_node_class;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_action_node
<- action_find_identifiers;
<- question;;
<- action;;

Knowledge
<- sc_node_class;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_action_node
<- action_find_identifiers;
<- question;;
<- action;;

Knowledge
<- sc_node_class;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test_action_node
<- action_find_identifiers;
<- question;;
<- action;;
Loading
Loading