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

SearchNotEnoughSpecifiedObjectsAgent #72

Draft
wants to merge 22 commits into
base: feature/dublication_agent
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ 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)
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_SRC "${SC_MACHINE_PATH}/sc-memory/sc-memory/include")
set(SC_AGENTS_COMMON_PATH "${SC_MACHINE_PATH}/sc-kpm/sc-agents-common/include")
set(SC_CORE_PATH "${SC_MACHINE_PATH}/sc-memory/sc-core/include")
set(SC_BUILDER_PATH "${SC_MACHINE_PATH}/sc-tools/sc-builder/include")
set(SC_CONFIG_PATH "${SC_MACHINE_PATH}/sc-tools/sc-config/include")

include("${CMAKE_CURRENT_SOURCE_DIR}/dependencies.cmake")
sc_target_dependencies()
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
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
@@ -1,2 +1,3 @@
add_subdirectory(identifiers-module)
add_subdirectory(sections-module)
add_subdirectory(verification-module)
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 @@ -17,11 +16,12 @@ target_link_libraries(identifiers-module
target_include_directories(identifiers-module
PUBLIC ${IDENTIFIERS_MODULE_SRC}
PUBLIC ${SC_MEMORY_SRC}
PUBLIC ${SC_CORE_PATH}
PUBLIC ${SC_AGENTS_COMMON_PATH}
PUBLIC ${SC_KPM_SRC}
PUBLIC ${SC_BUILDER_PATH}
)

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)
ScResult TranslateMainSystemIdtfsFromScToFileAgent::DoProgram(ScActionInitiatedEvent const & event, ScAction & action)
{
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::ConstPermPosArc, ScType::ConstCommonArc);

ScAddr edgeBelongsToNrelSystemIdtf;
ScAddr sourceOfEdgeBelongsToNrelSystemIdtf;
Expand All @@ -38,24 +29,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";
}
}
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 +67,73 @@ 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 +143,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,84 +6,77 @@

#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"},
{ScType::Var, "sc_node"},

{ScType::Node, "sc_node"},
{ScType::Link, "sc_link"},
{ScType::LinkClass, "sc_link"},
{ScType::NodeLink, "sc_link"},
{ScType::NodeLinkClass, "sc_link"},
{ScType::Unknown, "sc_node"},

{ScType::NodeConst, "sc_node"},
{ScType::NodeVar, "sc_node"},
{ScType::ConstNode, "sc_node"},
{ScType::VarNode, "sc_node"},

{ScType::LinkConst, "sc_link"},
{ScType::LinkVar, "sc_link"},
{ScType::ConstNodeLink, "sc_link"},
{ScType::VarNodeLink, "sc_link"},

{ScType::NodeStruct, "sc_node_struct"},
{ScType::NodeStructure, "sc_node_structure"},
{ScType::NodeTuple, "sc_node_tuple"},
{ScType::NodeRole, "sc_node_role_relation"},
{ScType::NodeNoRole, "sc_node_norole_relation"},
{ScType::NodeNonRole, "sc_node_non_role_relation"},
{ScType::NodeClass, "sc_node_class"},
{ScType::NodeAbstract, "sc_node"},
{ScType::NodeSuperclass, "sc_node_superclass"},
{ScType::NodeMaterial, "sc_node_material"},

{ScType::NodeConstStruct, "sc_node_struct"},
{ScType::NodeConstTuple, "sc_node_tuple"},
{ScType::NodeConstRole, "sc_node_role_relation"},
{ScType::NodeConstNoRole, "sc_node_norole_relation"},
{ScType::NodeConstClass, "sc_node_class"},
{ScType::NodeConstAbstract, "sc_node"},
{ScType::NodeConstMaterial, "sc_node_material"},

{ScType::NodeVarStruct, "sc_node_struct"},
{ScType::NodeVarTuple, "sc_node_tuple"},
{ScType::NodeVarRole, "sc_node_role_relation"},
{ScType::NodeVarNoRole, "sc_node_norole_relation"},
{ScType::NodeVarClass, "sc_node_class"},
{ScType::NodeVarAbstract, "sc_node"},
{ScType::NodeVarMaterial, "sc_node_material"}};
{ScType::ConstNodeStructure, "sc_node_structure"},
{ScType::ConstNodeTuple, "sc_node_tuple"},
{ScType::ConstNodeRole, "sc_node_role_relation"},
{ScType::ConstNodeNonRole, "sc_node_non_role_relation"},
{ScType::ConstNodeClass, "sc_node_class"},
{ScType::ConstNodeMaterial, "sc_node_material"},

std::map<ScType, std::string> ScTypesOfEdgesWithSCsClasses = {
{ScType::EdgeUCommon, "sc_edge"},
{ScType::EdgeDCommon, "sc_edge_common"},

{ScType::EdgeUCommonConst, "<=>"},
{ScType::EdgeDCommonConst, "sc_edge_common"},

{ScType::EdgeAccess, "sc_edge_access"},

{ScType::EdgeAccessConstPosPerm, "sc_edge_main"},
{ScType::EdgeAccessConstNegPerm, "sc_edge_main"},
{ScType::EdgeAccessConstFuzPerm, "sc_edge_main"},
{ScType::EdgeAccessConstPosTemp, "sc_edge_main"},
{ScType::EdgeAccessConstNegTemp, "sc_edge_main"},
{ScType::EdgeAccessConstFuzTemp, "sc_edge_main"},

{ScType::EdgeUCommonVar, "_<=>"},
{ScType::EdgeDCommonVar, "sc_edge_common"},
{ScType::EdgeAccessVarPosPerm, "sc_edge_main"},
{ScType::EdgeAccessVarNegPerm, "sc_edge_main"},
{ScType::EdgeAccessVarFuzPerm, "sc_edge_main"},
{ScType::EdgeAccessVarPosTemp, "sc_edge_main"},
{ScType::EdgeAccessVarNegTemp, "sc_edge_main"},
{ScType::EdgeAccessVarFuzTemp, "sc_edge_main"}};
{ScType::VarNodeStructure, "sc_node_structure"},
{ScType::VarNodeTuple, "sc_node_tuple"},
{ScType::VarNodeRole, "sc_node_role_relation"},
{ScType::VarNodeNonRole, "sc_node_non_role_relation"},
{ScType::VarNodeClass, "sc_node_class"},
{ScType::VarNodeMaterial, "sc_node_material"}};

std::map<ScType, std::string> ScTypesOfEdgesWithSCsClasses = {
{ScType::CommonEdge, "sc_common_edge"},
{ScType::CommonArc, "sc_common_arc"},
{ScType::MembershipArc, "sc_membership_arc"},

{ScType::ConstCommonEdge, "sc_common_edge"},
{ScType::ConstCommonArc, "sc_common_arc"},

{ScType::ConstPermPosArc, "sc_main_arc"},
{ScType::ConstPermNegArc, "sc_main_arc"},
{ScType::ConstTempPosArc, "sc_main_arc"},
{ScType::ConstTempNegArc, "sc_main_arc"},

{ScType::VarCommonEdge, "sc_common_edge"},
{ScType::VarCommonArc, "sc_main_arc"},
{ScType::VarPosArc, "sc_main_arc"},
{ScType::VarFuzArc, "sc_main_arc"},
{ScType::VarPermNegArc, "sc_main_arc"},
{ScType::VarTempPosArc, "sc_main_arc"},
{ScType::VarTempNegArc, "sc_main_arc"}};

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);
Expand Down
Loading