From 33d86099c4e3921d7fd2625a5aaacbffe078faa4 Mon Sep 17 00:00:00 2001 From: Edgar Brissow Date: Thu, 30 Jan 2025 15:23:56 -0300 Subject: [PATCH 01/10] Parser prototype --- src/cpp/link_creation_agent/agent.cc | 14 +++++ .../link_create_template.cc | 50 ++++++++++++++++ .../link_create_template.h | 60 +++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 src/cpp/link_creation_agent/link_create_template.cc create mode 100644 src/cpp/link_creation_agent/link_create_template.h diff --git a/src/cpp/link_creation_agent/agent.cc b/src/cpp/link_creation_agent/agent.cc index 97b8486..b8e63c8 100644 --- a/src/cpp/link_creation_agent/agent.cc +++ b/src/cpp/link_creation_agent/agent.cc @@ -4,6 +4,7 @@ #include #include "RemoteIterator.h" +// #include "link_create_template.h" using namespace std; using namespace link_creation_agent; @@ -49,6 +50,7 @@ void LinkCreationAgent::run() { int current_buffer_position = 0; while (true) { if(is_stoping) break; + // cout << "LinkCreationAgent running" << endl; LinkCreationAgentRequest* lca_request = NULL; bool is_from_buffer = false; if (!link_creation_node_server->is_query_empty()) { @@ -187,6 +189,18 @@ LinkCreationAgentRequest* LinkCreationAgent::create_request(vector reque } lca_request->infinite = (lca_request->repeat == -1); + // auto link_template = new LinkCreateTemplate(lca_request->link_template); + + // for(auto target : link_template->get_targets()){ + // if (holds_alternative(target)) { + // Node node = get(target); + // cout << "Node: " << node.type << " " << node.value << endl; + // } else { + // shared_ptr sub_link = get>(target); + // cout << "Sub Link: " << sub_link->get_link_type() << endl; + // } + // } + return lca_request; } catch (exception& e) { cout << "Error parsing request: " << e.what() << endl; diff --git a/src/cpp/link_creation_agent/link_create_template.cc b/src/cpp/link_creation_agent/link_create_template.cc new file mode 100644 index 0000000..0df4bc9 --- /dev/null +++ b/src/cpp/link_creation_agent/link_create_template.cc @@ -0,0 +1,50 @@ +#include "link_create_template.h" + +#include + +using namespace link_creation_agent; +// using LinkCreateTemplateTypes = std::variant>; + + +CustomField::CustomField(std::string name, CustomFieldTypes value) { + this->name = name; + this->value = value; +} + +CustomField::~CustomField() {} + +std::string CustomField::get_name() { return this->name; } + +CustomFieldTypes CustomField::get_value() { return this->value; } + +LinkCreateTemplate::LinkCreateTemplate(std::vector link_template) { + if (link_template[0] != "LINK_CREATE") throw std::invalid_argument("Invalid link template"); + this->link_type = link_template[1]; + std::size_t cursor = 1; + while (cursor < link_template.size()) { + if (link_template[cursor] == "NODE") { + Node node; + node.type = link_template[cursor + 1]; + node.value = link_template[cursor + 2]; + this->targets.push_back(node); + cursor += 3; + } else { + std::vector sub_link_template; + while (cursor < link_template.size() && link_template[cursor] != "NODE") { + sub_link_template.push_back(link_template[cursor]); + cursor++; + } + LinkCreateTemplateTypes sub_link = std::make_shared(sub_link_template); + this->targets.push_back(sub_link); + } + } +} + +LinkCreateTemplate::~LinkCreateTemplate() {} + +std::string LinkCreateTemplate::get_link_type() { return this->link_type; } + +std::vector LinkCreateTemplate::get_targets() { + return this->targets; +} + diff --git a/src/cpp/link_creation_agent/link_create_template.h b/src/cpp/link_creation_agent/link_create_template.h new file mode 100644 index 0000000..03eccb7 --- /dev/null +++ b/src/cpp/link_creation_agent/link_create_template.h @@ -0,0 +1,60 @@ +/** + * @file link_create_template.h + * @brief LinkCreateTemplate class to handle link creation templates + */ + +#pragma once +#include +#include +#include +#include +#include + + +namespace link_creation_agent { + +class CustomField; +class LinkCreateTemplate; +struct Node { + std::string type; + std::string value; +}; + +using CustomFieldTypes = std::variant>; +using LinkCreateTemplateTypes = std::variant>; + + +class CustomField { + public: + CustomField(std::string name, CustomFieldTypes value); + ~CustomField(); + std::string get_name(); + CustomFieldTypes get_value(); + + private: + std::string name; + CustomFieldTypes value; +}; + +enum class TargetType { NODE, TEMPLATE }; + + + +/** + * @class LinkCreateTemplate + */ +class LinkCreateTemplate { + public: + LinkCreateTemplate(std::vector link_template); + ~LinkCreateTemplate(); + std::string get_link_type(); + std::vector get_targets(); + std::vector get_custom_fields(); + + private: + std::string link_type; + std::vector targets; + std::vector custom_fields; +}; + +} // namespace link_creation_agent \ No newline at end of file From 285b5ba0ecbc333aace99d3ea26deb0f7f4b88fb Mon Sep 17 00:00:00 2001 From: Edgar Brissow Date: Fri, 31 Jan 2025 23:48:45 -0300 Subject: [PATCH 02/10] Link Create working --- src/cpp/link_creation_agent/agent.cc | 27 ++- .../link_create_template.cc | 159 +++++++++++++++++- .../link_create_template.h | 19 ++- src/scripts/bazel_build.sh | 80 ++++----- 4 files changed, 223 insertions(+), 62 deletions(-) diff --git a/src/cpp/link_creation_agent/agent.cc b/src/cpp/link_creation_agent/agent.cc index b8e63c8..c9c7527 100644 --- a/src/cpp/link_creation_agent/agent.cc +++ b/src/cpp/link_creation_agent/agent.cc @@ -4,7 +4,7 @@ #include #include "RemoteIterator.h" -// #include "link_create_template.h" +#include "link_create_template.h" using namespace std; using namespace link_creation_agent; @@ -167,7 +167,7 @@ LinkCreationAgentRequest* LinkCreationAgent::create_request(vector reque bool is_link_create = false; for (string arg : request) { cursor++; - is_link_create = (arg == "LINK_CREATE") ^ is_link_create; + is_link_create = (arg == "LINK_CREATE") || is_link_create; if (!is_link_create) { lca_request->query.push_back(arg); } @@ -188,17 +188,30 @@ LinkCreationAgentRequest* LinkCreationAgent::create_request(vector reque } } lca_request->infinite = (lca_request->repeat == -1); - - // auto link_template = new LinkCreateTemplate(lca_request->link_template); + cout << "template starting" << endl; + // for(auto arg : lca_request->link_template){ + // cout << arg << endl; + // } + auto link_template = new LinkCreateTemplate(lca_request->link_template); + cout << "template ok" << endl; + cout << "Link Type: " << link_template->get_link_type() << endl; + cout << "CREATE_LINK" << endl; + cout << link_template->to_string() << endl; // for(auto target : link_template->get_targets()){ // if (holds_alternative(target)) { // Node node = get(target); // cout << "Node: " << node.type << " " << node.value << endl; - // } else { - // shared_ptr sub_link = get>(target); - // cout << "Sub Link: " << sub_link->get_link_type() << endl; // } + // if (holds_alternative(target)) { + // Variable var = get(target); + // cout << "Variable: " << var.name << endl; + // } + + // // else { + // // shared_ptr sub_link = get>(target); + // // cout << "Sub Link: " << sub_link->get_link_type() << endl; + // // } // } return lca_request; diff --git a/src/cpp/link_creation_agent/link_create_template.cc b/src/cpp/link_creation_agent/link_create_template.cc index 0df4bc9..708da01 100644 --- a/src/cpp/link_creation_agent/link_create_template.cc +++ b/src/cpp/link_creation_agent/link_create_template.cc @@ -1,16 +1,58 @@ #include "link_create_template.h" +#include #include using namespace link_creation_agent; // using LinkCreateTemplateTypes = std::variant>; - CustomField::CustomField(std::string name, CustomFieldTypes value) { this->name = name; this->value = value; } +CustomField::CustomField(std::vector args) { + if (args[0] != "CUSTOM_FIELD") + throw std::invalid_argument("Can not create Custom Field: Invalid arguments"); + int cursor = 0; + std::cout << "C" << std::endl; + int custom_field_size = std::stoi(args[2]); + std::cout << "Custom Field Size: " << custom_field_size << std::endl; + // while (cursor < args.size()) { + // if (args[cursor] == "CUSTOM_FIELD") { + // std::vector custom_field_args; + // std::cout << "D" << std::endl; + // int sub_custom_field_size = std::stoi(args[cursor + 2]); + // while (cursor < args.size()) { + // if (sub_custom_field_size == 0) { + // break; + // } + // custom_field_args.push_back(args[cursor]); + // if (args[cursor] == "CUSTOM_FIELD") { + // custom_field_args.push_back(args[cursor + 1]); + // custom_field_args.push_back(args[cursor + 2]); + // std::cout << "E" << std::endl; + // sub_custom_field_size += std::stoi(args[cursor + 2]); + // sub_custom_field_size--; + // cursor += 2; + // } else { + // custom_field_args.push_back(args[cursor + 1]); + // cursor++; + // sub_custom_field_size--; + // } + // cursor++; + // } + // CustomField custom_field = CustomField(custom_field_args); + // this->value = std::make_shared(custom_field); + // } else { + // this->name = args[cursor]; + // this->value = args[cursor + 1]; + // cursor++; + // } + // cursor++; + // } +} + CustomField::~CustomField() {} std::string CustomField::get_name() { return this->name; } @@ -18,24 +60,94 @@ std::string CustomField::get_name() { return this->name; } CustomFieldTypes CustomField::get_value() { return this->value; } LinkCreateTemplate::LinkCreateTemplate(std::vector link_template) { - if (link_template[0] != "LINK_CREATE") throw std::invalid_argument("Invalid link template"); - this->link_type = link_template[1]; + // if (link_template[0] != "LINK_CREATE") throw std::invalid_argument("Can not create Link Template: + // Invalid link template"); + + int stating_pos = 0; + if (link_template[0] == "LINK_CREATE") { + stating_pos = 1; + } + + this->link_type = link_template[stating_pos]; std::size_t cursor = 1; + std::size_t link_template_size = std::stoi(link_template[stating_pos + 1]); + // bool is_link_template = false; + // std::vector sub_link_template; + // int sub_link_template_size = 0; while (cursor < link_template.size()) { if (link_template[cursor] == "NODE") { Node node; node.type = link_template[cursor + 1]; node.value = link_template[cursor + 2]; this->targets.push_back(node); - cursor += 3; - } else { + cursor += 2; + } else if (link_template[cursor] == "VARIABLE") { + Variable var; + var.name = link_template[cursor + 1]; + this->targets.push_back(var); + cursor += 1; + } else if (link_template[cursor] == "LINK_CREATE") { + int sub_link_template_size = std::stoi(link_template[cursor + 2]); std::vector sub_link_template; - while (cursor < link_template.size() && link_template[cursor] != "NODE") { + while (cursor < link_template.size()) { + if (sub_link_template_size == 0) { + break; + } sub_link_template.push_back(link_template[cursor]); + if (link_template[cursor] == "NODE") { + sub_link_template.push_back(link_template[cursor + 1]); + sub_link_template.push_back(link_template[cursor + 2]); + cursor += 2; + sub_link_template_size--; + } + + if (link_template[cursor] == "VARIABLE") { + sub_link_template.push_back(link_template[cursor + 1]); + cursor += 1; + sub_link_template_size--; + } + + if (link_template[cursor] == "CREATE_LINK") { + sub_link_template.push_back(link_template[cursor + 1]); // link type + sub_link_template.push_back(link_template[cursor + 2]); // link size + sub_link_template.push_back(link_template[cursor + 3]); // custom_field size + cursor += 3; + sub_link_template_size += std::stoi(link_template[cursor + 2]); + sub_link_template_size--; + } cursor++; } LinkCreateTemplateTypes sub_link = std::make_shared(sub_link_template); this->targets.push_back(sub_link); + } else if (link_template[cursor] == "CUSTOM_FIELD") { + std::vector custom_field_args; + std::cout << "Custom Field Size: " << link_template[cursor + 2] << std::endl; + // std::string custom_field_name = link_template[cursor + 1]; + std::cout << "A" << std::endl; + int custom_field_size = std::stoi(link_template[cursor + 2]); + while (cursor < link_template.size()) { + if (custom_field_size == 0) { + break; + } + custom_field_args.push_back(link_template[cursor]); + if (link_template[cursor] == "CUSTOM_FIELD") { + custom_field_args.push_back(link_template[cursor + 1]); + custom_field_args.push_back(link_template[cursor + 2]); + std::cout << "B" << std::endl; + custom_field_size += std::stoi(link_template[cursor + 2]); + custom_field_size--; + cursor += 2; + + } else { + custom_field_args.push_back(link_template[cursor + 1]); + cursor++; + } + cursor++; + } + CustomField custom_field = CustomField(custom_field_args); + this->custom_fields.push_back(custom_field); + } else { + cursor++; } } } @@ -44,7 +156,38 @@ LinkCreateTemplate::~LinkCreateTemplate() {} std::string LinkCreateTemplate::get_link_type() { return this->link_type; } -std::vector LinkCreateTemplate::get_targets() { - return this->targets; +std::vector LinkCreateTemplate::get_targets() { return this->targets; } + +std::string LinkCreateTemplate::to_string() { + std::string link_template = + "LINK_CREATE " + this->link_type + " " + std::to_string(this->targets.size()) + " "; + for (auto target : this->targets) { + if (std::holds_alternative(target)) { + Node node = std::get(target); + link_template += "NODE " + node.type + " " + node.value + " "; + } else if (std::holds_alternative(target)) { + Variable var = std::get(target); + link_template += "VARIABLE " + var.name + " "; + } else if (std::holds_alternative>(target)) { + std::shared_ptr sub_link = + std::get>(target); + link_template += sub_link->to_string(); + } + } + for (auto custom_field : this->custom_fields) { + link_template += "CUSTOM_FIELD " + custom_field.to_string() + " "; + } + return link_template; } +std::string CustomField::to_string() { + std::string custom_field = this->name + " "; + if (std::holds_alternative(this->value)) { + custom_field += std::get(this->value); + } else if (std::holds_alternative>(this->value)) { + std::shared_ptr sub_custom_field = + std::get>(this->value); + custom_field += sub_custom_field->to_string(); + } + return custom_field; +} \ No newline at end of file diff --git a/src/cpp/link_creation_agent/link_create_template.h b/src/cpp/link_creation_agent/link_create_template.h index 03eccb7..bbf28e3 100644 --- a/src/cpp/link_creation_agent/link_create_template.h +++ b/src/cpp/link_creation_agent/link_create_template.h @@ -4,12 +4,11 @@ */ #pragma once +#include #include #include -#include #include -#include - +#include namespace link_creation_agent { @@ -20,16 +19,22 @@ struct Node { std::string value; }; -using CustomFieldTypes = std::variant>; -using LinkCreateTemplateTypes = std::variant>; +struct Variable { + std::string name; +}; +using CustomFieldTypes = std::variant>; +using LinkCreateTemplateTypes = std::variant>; class CustomField { public: CustomField(std::string name, CustomFieldTypes value); + CustomField(std::vector args); ~CustomField(); std::string get_name(); CustomFieldTypes get_value(); + std::string to_string(); + private: std::string name; @@ -38,8 +43,6 @@ class CustomField { enum class TargetType { NODE, TEMPLATE }; - - /** * @class LinkCreateTemplate */ @@ -50,6 +53,8 @@ class LinkCreateTemplate { std::string get_link_type(); std::vector get_targets(); std::vector get_custom_fields(); + std::string to_string(); + private: std::string link_type; diff --git a/src/scripts/bazel_build.sh b/src/scripts/bazel_build.sh index 16c6c16..6c7aa2b 100755 --- a/src/scripts/bazel_build.sh +++ b/src/scripts/bazel_build.sh @@ -7,43 +7,43 @@ BAZELISK_BUILD_CMD="${BAZELISK_CMD} build --jobs ${JOBS} --enable_bzlmod" # CPP build cd $CPP_WORKSPACE_DIR \ && $BAZELISK_BUILD_CMD //:link_creation_server \ -&& mv bazel-bin/link_creation_server $BIN_DIR \ -&& $BAZELISK_BUILD_CMD //:link_creation_agent_client \ -&& mv bazel-bin/link_creation_agent_client $BIN_DIR \ -&& $BAZELISK_BUILD_CMD //:word_query \ -&& mv bazel-bin/word_query $BIN_DIR \ -&& $BAZELISK_BUILD_CMD //:attention_broker_service \ -&& mv bazel-bin/attention_broker_service $BIN_DIR \ -&& $BAZELISK_BUILD_CMD //:query_broker \ -&& mv bazel-bin/query_broker $BIN_DIR \ -&& $BAZELISK_BUILD_CMD //:query \ -&& mv bazel-bin/query $BIN_DIR \ -&& $BAZELISK_BUILD_CMD \ - //hyperon_das_atomdb_cpp:hyperon_das_atomdb_cpp_wheel \ - --define=ATOMDB_VERSION=0.8.11 \ -&& mv bazel-bin/hyperon_das_atomdb_cpp/*.whl "$BIN_DIR" - -# Python build -cd "$PYTHON_WORKSPACE_DIR" - -$BAZELISK_CMD run --jobs ${JOBS} \ - --noenable_bzlmod --enable_workspace \ - //deps:requirements.update - -$BAZELISK_CMD run --jobs ${JOBS} \ - --noenable_bzlmod --enable_workspace \ - //deps:requirements_dev.update - -$BAZELISK_CMD build --jobs ${JOBS} \ - --noenable_bzlmod --enable_workspace \ - //hyperon_das_atomdb:hyperon_das_atomdb_wheel \ - --define=ATOMDB_VERSION=0.8.11 - -$BAZELISK_CMD build --jobs ${JOBS} \ - --noenable_bzlmod --enable_workspace \ - //hyperon_das:hyperon_das_wheel \ - --define=DAS_VERSION=0.9.17 - - -mv bazel-bin/hyperon_das_atomdb/*.whl "$BIN_DIR" -mv bazel-bin/hyperon_das/*.whl "$BIN_DIR" \ No newline at end of file +&& mv bazel-bin/link_creation_server $BIN_DIR +# && $BAZELISK_BUILD_CMD //:link_creation_agent_client \ +# && mv bazel-bin/link_creation_agent_client $BIN_DIR \ +# && $BAZELISK_BUILD_CMD //:word_query \ +# && mv bazel-bin/word_query $BIN_DIR \ +# && $BAZELISK_BUILD_CMD //:attention_broker_service \ +# && mv bazel-bin/attention_broker_service $BIN_DIR \ +# && $BAZELISK_BUILD_CMD //:query_broker \ +# && mv bazel-bin/query_broker $BIN_DIR \ +# && $BAZELISK_BUILD_CMD //:query \ +# && mv bazel-bin/query $BIN_DIR \ +# && $BAZELISK_BUILD_CMD \ +# //hyperon_das_atomdb_cpp:hyperon_das_atomdb_cpp_wheel \ +# --define=ATOMDB_VERSION=0.8.11 \ +# && mv bazel-bin/hyperon_das_atomdb_cpp/*.whl "$BIN_DIR" + +# # Python build +# cd "$PYTHON_WORKSPACE_DIR" + +# $BAZELISK_CMD run --jobs ${JOBS} \ +# --noenable_bzlmod --enable_workspace \ +# //deps:requirements.update + +# $BAZELISK_CMD run --jobs ${JOBS} \ +# --noenable_bzlmod --enable_workspace \ +# //deps:requirements_dev.update + +# $BAZELISK_CMD build --jobs ${JOBS} \ +# --noenable_bzlmod --enable_workspace \ +# //hyperon_das_atomdb:hyperon_das_atomdb_wheel \ +# --define=ATOMDB_VERSION=0.8.11 + +# $BAZELISK_CMD build --jobs ${JOBS} \ +# --noenable_bzlmod --enable_workspace \ +# //hyperon_das:hyperon_das_wheel \ +# --define=DAS_VERSION=0.9.17 + + +# mv bazel-bin/hyperon_das_atomdb/*.whl "$BIN_DIR" +# mv bazel-bin/hyperon_das/*.whl "$BIN_DIR" \ No newline at end of file From e1073ad8a1ab7b8dc6473107d48b57cc5d200663 Mon Sep 17 00:00:00 2001 From: Edgar Brissow Date: Sun, 2 Feb 2025 16:28:48 -0300 Subject: [PATCH 03/10] Tests working --- .../link_create_template.cc | 254 ++++++++++-------- .../link_create_template.h | 6 +- src/cpp/tests/link_creation_agent_test.cc | 92 ++++--- 3 files changed, 202 insertions(+), 150 deletions(-) diff --git a/src/cpp/link_creation_agent/link_create_template.cc b/src/cpp/link_creation_agent/link_create_template.cc index 708da01..095ef85 100644 --- a/src/cpp/link_creation_agent/link_create_template.cc +++ b/src/cpp/link_creation_agent/link_create_template.cc @@ -4,76 +4,141 @@ #include using namespace link_creation_agent; -// using LinkCreateTemplateTypes = std::variant>; - -CustomField::CustomField(std::string name, CustomFieldTypes value) { - this->name = name; - this->value = value; -} CustomField::CustomField(std::vector args) { if (args[0] != "CUSTOM_FIELD") throw std::invalid_argument("Can not create Custom Field: Invalid arguments"); + int cursor = 0; - std::cout << "C" << std::endl; int custom_field_size = std::stoi(args[2]); - std::cout << "Custom Field Size: " << custom_field_size << std::endl; - // while (cursor < args.size()) { - // if (args[cursor] == "CUSTOM_FIELD") { - // std::vector custom_field_args; - // std::cout << "D" << std::endl; - // int sub_custom_field_size = std::stoi(args[cursor + 2]); - // while (cursor < args.size()) { - // if (sub_custom_field_size == 0) { - // break; - // } - // custom_field_args.push_back(args[cursor]); - // if (args[cursor] == "CUSTOM_FIELD") { - // custom_field_args.push_back(args[cursor + 1]); - // custom_field_args.push_back(args[cursor + 2]); - // std::cout << "E" << std::endl; - // sub_custom_field_size += std::stoi(args[cursor + 2]); - // sub_custom_field_size--; - // cursor += 2; - // } else { - // custom_field_args.push_back(args[cursor + 1]); - // cursor++; - // sub_custom_field_size--; - // } - // cursor++; - // } - // CustomField custom_field = CustomField(custom_field_args); - // this->value = std::make_shared(custom_field); - // } else { - // this->name = args[cursor]; - // this->value = args[cursor + 1]; - // cursor++; - // } - // cursor++; - // } + std::string custom_field_name = args[1]; + this->name = custom_field_name; + cursor += 3; + while (cursor < args.size()) { + + if (args[cursor] == "CUSTOM_FIELD") { + std::vector custom_field_args; + int sub_custom_field_size = std::stoi(args[cursor + 2]); + std::string sub_custom_field_name = args[cursor + 1]; + custom_field_args.push_back(args[cursor]); // CUSTOM_FIELD + custom_field_args.push_back(args[cursor + 1]); // field name + custom_field_args.push_back(args[cursor + 2]); // field size + cursor += 3; + while (cursor < args.size()) { + if (sub_custom_field_size == 0) { + break; + } + + custom_field_args.push_back(args[cursor]); + if (args[cursor] == "CUSTOM_FIELD") { + sub_custom_field_size += std::stoi(args[cursor + 2]); + custom_field_args.push_back(args[cursor + 1]); // field name + custom_field_args.push_back(args[cursor + 2]); // field size + cursor += 3; + sub_custom_field_size--; + } else { + custom_field_args.push_back(args[cursor + 1]); + cursor += 2; + sub_custom_field_size--; + } + } + CustomField custom_field = CustomField(custom_field_args); + this->values.push_back( + std::make_tuple(sub_custom_field_name, std::make_shared(custom_field))); + } else { + this->values.push_back(std::make_tuple(args[cursor], args[cursor + 1])); + cursor += 2; + } + } } CustomField::~CustomField() {} std::string CustomField::get_name() { return this->name; } -CustomFieldTypes CustomField::get_value() { return this->value; } +std::vector> CustomField::get_values() { return this->values; } -LinkCreateTemplate::LinkCreateTemplate(std::vector link_template) { - // if (link_template[0] != "LINK_CREATE") throw std::invalid_argument("Can not create Link Template: - // Invalid link template"); +std::vector parse_sub_custom_field(std::vector link_template, size_t& cursor) { + std::vector custom_field_args; + int custom_field_size = std::stoi(link_template[cursor + 2]); + custom_field_args.push_back(link_template[cursor]); // CUSTOM_FIELD + custom_field_args.push_back(link_template[cursor + 1]); // field name + custom_field_args.push_back(link_template[cursor + 2]); // field size + cursor += 3; + while (cursor < link_template.size()) { + if (custom_field_size == 0) { + break; + } + custom_field_args.push_back(link_template[cursor]); + if (link_template[cursor] == "CUSTOM_FIELD") { + custom_field_args.push_back(link_template[cursor + 1]); + custom_field_args.push_back(link_template[cursor + 2]); + custom_field_size += std::stoi(link_template[cursor + 2]); + custom_field_size--; + cursor += 3; + } else { + custom_field_args.push_back(link_template[cursor + 1]); + custom_field_size--; + cursor += 2; + } + } + return custom_field_args; +} +std::vector parse_sub_link_template(std::vector link_template, + size_t& cursor) { + int sub_link_template_size = std::stoi(link_template[cursor + 2]); + int sub_link_custom_field_size = std::stoi(link_template[cursor + 3]); + int custom_field_value_size = 0; + std::vector sub_link_template; + int current_ptr = 0; // link create default size + sub_link_template.push_back(link_template[cursor]); // LINK_CREATE + sub_link_template.push_back(link_template[cursor + 1]); // link type + sub_link_template.push_back(link_template[cursor + 2]); // link size + sub_link_template.push_back(link_template[cursor + 3]); // custom field size + cursor += 4; + while (cursor < link_template.size()) { + if (sub_link_template_size == 0 && current_ptr == 0 && sub_link_custom_field_size == 0 && + custom_field_value_size == 0) { + break; + } + sub_link_template.push_back(link_template[cursor]); + + if (link_template[cursor] == "NODE") { + current_ptr = 3; + sub_link_template_size--; + } + if (link_template[cursor] == "VARIABLE") { + current_ptr = 2; + sub_link_template_size--; + } + if (link_template[cursor] == "LINK_CREATE") { + current_ptr = 4; + sub_link_template_size += std::stoi(link_template[cursor + 2]); + sub_link_custom_field_size = std::stoi(link_template[cursor + 3]); + sub_link_template_size--; + } + if (sub_link_custom_field_size > 0 && link_template[cursor] == "CUSTOM_FIELD") { + current_ptr = 3 + (std::stoi(link_template[cursor + 2]) * 2); + sub_link_custom_field_size--; + } + + current_ptr--; + cursor++; + } + return sub_link_template; +} + +LinkCreateTemplate::LinkCreateTemplate(std::vector link_template) { int stating_pos = 0; if (link_template[0] == "LINK_CREATE") { stating_pos = 1; } this->link_type = link_template[stating_pos]; - std::size_t cursor = 1; + std::size_t cursor = stating_pos; std::size_t link_template_size = std::stoi(link_template[stating_pos + 1]); - // bool is_link_template = false; - // std::vector sub_link_template; - // int sub_link_template_size = 0; + std::size_t custom_field_size = std::stoi(link_template[stating_pos + 2]); while (cursor < link_template.size()) { if (link_template[cursor] == "NODE") { Node node; @@ -87,65 +152,14 @@ LinkCreateTemplate::LinkCreateTemplate(std::vector link_template) { this->targets.push_back(var); cursor += 1; } else if (link_template[cursor] == "LINK_CREATE") { - int sub_link_template_size = std::stoi(link_template[cursor + 2]); - std::vector sub_link_template; - while (cursor < link_template.size()) { - if (sub_link_template_size == 0) { - break; - } - sub_link_template.push_back(link_template[cursor]); - if (link_template[cursor] == "NODE") { - sub_link_template.push_back(link_template[cursor + 1]); - sub_link_template.push_back(link_template[cursor + 2]); - cursor += 2; - sub_link_template_size--; - } - - if (link_template[cursor] == "VARIABLE") { - sub_link_template.push_back(link_template[cursor + 1]); - cursor += 1; - sub_link_template_size--; - } - - if (link_template[cursor] == "CREATE_LINK") { - sub_link_template.push_back(link_template[cursor + 1]); // link type - sub_link_template.push_back(link_template[cursor + 2]); // link size - sub_link_template.push_back(link_template[cursor + 3]); // custom_field size - cursor += 3; - sub_link_template_size += std::stoi(link_template[cursor + 2]); - sub_link_template_size--; - } - cursor++; - } + std::vector sub_link_template = parse_sub_link_template(link_template, cursor); LinkCreateTemplateTypes sub_link = std::make_shared(sub_link_template); this->targets.push_back(sub_link); } else if (link_template[cursor] == "CUSTOM_FIELD") { - std::vector custom_field_args; - std::cout << "Custom Field Size: " << link_template[cursor + 2] << std::endl; - // std::string custom_field_name = link_template[cursor + 1]; - std::cout << "A" << std::endl; - int custom_field_size = std::stoi(link_template[cursor + 2]); - while (cursor < link_template.size()) { - if (custom_field_size == 0) { - break; - } - custom_field_args.push_back(link_template[cursor]); - if (link_template[cursor] == "CUSTOM_FIELD") { - custom_field_args.push_back(link_template[cursor + 1]); - custom_field_args.push_back(link_template[cursor + 2]); - std::cout << "B" << std::endl; - custom_field_size += std::stoi(link_template[cursor + 2]); - custom_field_size--; - cursor += 2; - - } else { - custom_field_args.push_back(link_template[cursor + 1]); - cursor++; - } - cursor++; - } - CustomField custom_field = CustomField(custom_field_args); + std::vector sub_custom_field = parse_sub_custom_field(link_template, cursor); + CustomField custom_field = CustomField(sub_custom_field); this->custom_fields.push_back(custom_field); + cursor++; } else { cursor++; } @@ -159,35 +173,43 @@ std::string LinkCreateTemplate::get_link_type() { return this->link_type; } std::vector LinkCreateTemplate::get_targets() { return this->targets; } std::string LinkCreateTemplate::to_string() { - std::string link_template = - "LINK_CREATE " + this->link_type + " " + std::to_string(this->targets.size()) + " "; + std::string link_template = "LINK_CREATE " + this->link_type + " " + + std::to_string(this->targets.size()) + " " + + std::to_string(this->custom_fields.size()) + " "; for (auto target : this->targets) { if (std::holds_alternative(target)) { Node node = std::get(target); - link_template += "NODE " + node.type + " " + node.value + " "; + link_template += "NODE " + node.type + " " + node.value; } else if (std::holds_alternative(target)) { Variable var = std::get(target); - link_template += "VARIABLE " + var.name + " "; + link_template += "VARIABLE " + var.name; } else if (std::holds_alternative>(target)) { std::shared_ptr sub_link = std::get>(target); link_template += sub_link->to_string(); } + link_template += " "; } for (auto custom_field : this->custom_fields) { - link_template += "CUSTOM_FIELD " + custom_field.to_string() + " "; + link_template += custom_field.to_string(); } + link_template = link_template.substr(0, link_template.size() - 1); return link_template; } std::string CustomField::to_string() { - std::string custom_field = this->name + " "; - if (std::holds_alternative(this->value)) { - custom_field += std::get(this->value); - } else if (std::holds_alternative>(this->value)) { - std::shared_ptr sub_custom_field = - std::get>(this->value); - custom_field += sub_custom_field->to_string(); + std::string custom_field = + "CUSTOM_FIELD " + this->name + " " + std::to_string(this->values.size()) + " "; + for (auto value : this->values) { + CustomFieldTypes field_value = std::get<1>(value); + if (std::holds_alternative(field_value)) { + custom_field += std::get<0>(value) + " "; + custom_field += std::get(field_value) + " "; + } else { + std::shared_ptr sub_custom_field = + std::get>(field_value); + custom_field += sub_custom_field->to_string(); + } } return custom_field; } \ No newline at end of file diff --git a/src/cpp/link_creation_agent/link_create_template.h b/src/cpp/link_creation_agent/link_create_template.h index bbf28e3..5c1e18c 100644 --- a/src/cpp/link_creation_agent/link_create_template.h +++ b/src/cpp/link_creation_agent/link_create_template.h @@ -28,17 +28,17 @@ using LinkCreateTemplateTypes = std::variant args); ~CustomField(); std::string get_name(); - CustomFieldTypes get_value(); + std::vector> get_values(); std::string to_string(); private: std::string name; - CustomFieldTypes value; + std::vector> values; + // CustomFieldTypes value; }; enum class TargetType { NODE, TEMPLATE }; diff --git a/src/cpp/tests/link_creation_agent_test.cc b/src/cpp/tests/link_creation_agent_test.cc index 30e85b0..3e45109 100644 --- a/src/cpp/tests/link_creation_agent_test.cc +++ b/src/cpp/tests/link_creation_agent_test.cc @@ -1,4 +1,5 @@ #include "agent.h" +#include "link_create_template.h" #include #include #include @@ -13,48 +14,77 @@ class LinkCreationAgentTest : public ::testing::Test { void SetUp() override { // Create a temporary config file for testing - ofstream config_file("test_config.cfg"); - config_file << "requests_interval_seconds=1\n"; - config_file << "link_creation_agent_thread_count=1\n"; - config_file << "query_agent_client_id=localhost:8080\n"; - config_file << "query_agent_server_id=localhost:8081\n"; - config_file << "link_creation_agent_server_id=localhost:8082\n"; - config_file << "das_agent_client_id=localhost:8083\n"; - config_file << "das_agent_server_id=localhost:8083\n"; - config_file << "requests_buffer_file=test_buffer.bin\n"; - config_file.close(); + // ofstream config_file("test_config.cfg"); + // config_file << "requests_interval_seconds=1\n"; + // config_file << "link_creation_agent_thread_count=1\n"; + // config_file << "query_agent_client_id=localhost:8080\n"; + // config_file << "query_agent_server_id=localhost:8081\n"; + // config_file << "link_creation_agent_server_id=localhost:8082\n"; + // config_file << "das_agent_client_id=localhost:8083\n"; + // config_file << "das_agent_server_id=localhost:8083\n"; + // config_file << "requests_buffer_file=test_buffer.bin\n"; + // config_file.close(); } void TearDown() override { - remove("test_config.cfg"); - remove("test_buffer.bin"); + // remove("test_config.cfg"); + // remove("test_buffer.bin"); } }; -TEST_F(LinkCreationAgentTest, TestRequest) { - // Simulate a request - vector request = {"query1", "LINK_CREATE", "query2", "10", "5", "test_context", "true"}; - LinkCreationAgentRequest* lca_request = LinkCreationAgent::create_request(request); - EXPECT_EQ(lca_request->query, vector({"query1"})); - EXPECT_EQ(lca_request->link_template, vector({"LINK_CREATE", "query2"})); - EXPECT_EQ(lca_request->max_results, 10); - EXPECT_EQ(lca_request->repeat, 5); - EXPECT_EQ(lca_request->context, "test_context"); - EXPECT_EQ(lca_request->update_attention_broker, true); -} +// TEST_F(LinkCreationAgentTest, TestRequest) { +// // Simulate a request +// vector request = {"query1", "LINK_CREATE", "query2", "10", "5", "test_context", "true"}; +// LinkCreationAgentRequest* lca_request = LinkCreationAgent::create_request(request); +// EXPECT_EQ(lca_request->query, vector({"query1"})); +// EXPECT_EQ(lca_request->link_template, vector({"LINK_CREATE", "query2"})); +// EXPECT_EQ(lca_request->max_results, 10); +// EXPECT_EQ(lca_request->repeat, 5); +// EXPECT_EQ(lca_request->context, "test_context"); +// EXPECT_EQ(lca_request->update_attention_broker, true); +// } -TEST_F(LinkCreationAgentTest, TestConfig){ - agent = new LinkCreationAgent("test_config.cfg"); - delete agent; -} +// TEST_F(LinkCreationAgentTest, TestConfig){ +// agent = new LinkCreationAgent("test_config.cfg"); +// delete agent; +// } -TEST_F(LinkCreationAgentTest, TestOutputBuffer){ - agent = new LinkCreationAgent("test_config.cfg"); - delete agent; -} +// TEST_F(LinkCreationAgentTest, TestOutputBuffer){ +// agent = new LinkCreationAgent("test_config.cfg"); +// delete agent; +// } +// TEST(LinkCreateTemplate, TestCustomField){ +// vector args = {"CUSTOM_FIELD", "field1", "2", "value1", "value2"}; +// CustomField custom_field(args); +// EXPECT_EQ(custom_field.get_name(), "field1"); +// vector> values = custom_field.get_values(); +// EXPECT_EQ(values.size(), 2); +// EXPECT_EQ(get(get<1>(values[0])), "value1"); +// EXPECT_EQ(get(get<1>(values[1])), "value2"); +// } + + +TEST(LinkCreateTemplate, TestLinkCreateTemplate){ + // vector link_template = {"LINK_CREATE", "link_type", "2", "1", "NODE", "type1", "value1", "VARIABLE", "var1", "CUSTOM_FIELD", "field1", "1", "value1", "value2"}; + vector link_template = {"LINK_CREATE", "Similarity", "3", "2", "VARIABLE", "V1", "LINK_CREATE", "Test", "3","0", "NODE", "Symbol", "A", "VARIABLE", "V2", "LINK_CREATE", "Test2", "1","1", "NODE", "Symbol", "C", "CUSTOM_FIELD", "inter", "1", "inter_name", "inter_value", "NODE", "Symbol", "B", "CUSTOM_FIELD", "truth_value", "2", "CUSTOM_FIELD", "mean", "2", "count", "10", "avg", "0.9", "confidence", "0.9"}; + string link_template_str = "LINK_CREATE Similarity 3 1 VARIABLE V1 LINK_CREATE Test 3 0 NODE Symbol A VARIABLE V2 LINK_CREATE Test2 1 1 NODE Symbol C CUSTOM_FIELD inter 1 inter_name inter_value NODE Symbol B CUSTOM_FIELD truth_value 2 CUSTOM_FIELD mean 2 count 10 avg 0.9 confidence 0.9"; + LinkCreateTemplate lct(link_template); + EXPECT_EQ(lct.get_link_type(), "Similarity"); + EXPECT_EQ(lct.to_string(), link_template_str); + link_template.clear(); + link_template_str.clear(); + link_template = {"LINK_CREATE", "I", "3", "0", "VARIABLE", "V1", "LINK_CREATE", "Test", "3","0", "NODE", "Symbol", "A", "VARIABLE", "V2", "LINK_CREATE", "Test2", "1","0", "NODE", "Symbol", "C", "NODE", "Symbol", "B"}; + link_template_str = "LINK_CREATE I 3 0 VARIABLE V1 LINK_CREATE Test 3 0 NODE Symbol A VARIABLE V2 LINK_CREATE Test2 1 0 NODE Symbol C NODE Symbol B"; + LinkCreateTemplate lct2(link_template); + EXPECT_EQ(lct2.get_link_type(), "I"); + EXPECT_EQ(lct2.to_string(), link_template_str); + EXPECT_EQ(lct2.get_targets().size(), 3); + EXPECT_EQ(get(lct.get_targets()[0]).name, "V1"); + +} \ No newline at end of file From 3932ec5acad047cab927868652cc27a32f52fc85 Mon Sep 17 00:00:00 2001 From: Edgar Brissow Date: Mon, 3 Feb 2025 14:10:24 -0300 Subject: [PATCH 04/10] Working on exceptions --- src/cpp/link_creation_agent/agent.cc | 20 -- .../link_create_template.cc | 93 +++++---- .../link_create_template.h | 4 +- src/cpp/tests/link_creation_agent_test.cc | 180 ++++++++++++++++-- 4 files changed, 223 insertions(+), 74 deletions(-) diff --git a/src/cpp/link_creation_agent/agent.cc b/src/cpp/link_creation_agent/agent.cc index c9c7527..a91d90f 100644 --- a/src/cpp/link_creation_agent/agent.cc +++ b/src/cpp/link_creation_agent/agent.cc @@ -188,32 +188,12 @@ LinkCreationAgentRequest* LinkCreationAgent::create_request(vector reque } } lca_request->infinite = (lca_request->repeat == -1); - cout << "template starting" << endl; - // for(auto arg : lca_request->link_template){ - // cout << arg << endl; - // } auto link_template = new LinkCreateTemplate(lca_request->link_template); cout << "template ok" << endl; cout << "Link Type: " << link_template->get_link_type() << endl; cout << "CREATE_LINK" << endl; cout << link_template->to_string() << endl; - // for(auto target : link_template->get_targets()){ - // if (holds_alternative(target)) { - // Node node = get(target); - // cout << "Node: " << node.type << " " << node.value << endl; - // } - // if (holds_alternative(target)) { - // Variable var = get(target); - // cout << "Variable: " << var.name << endl; - // } - - // // else { - // // shared_ptr sub_link = get>(target); - // // cout << "Sub Link: " << sub_link->get_link_type() << endl; - // // } - // } - return lca_request; } catch (exception& e) { cout << "Error parsing request: " << e.what() << endl; diff --git a/src/cpp/link_creation_agent/link_create_template.cc b/src/cpp/link_creation_agent/link_create_template.cc index 095ef85..edf1e89 100644 --- a/src/cpp/link_creation_agent/link_create_template.cc +++ b/src/cpp/link_creation_agent/link_create_template.cc @@ -2,42 +2,60 @@ #include #include +#include using namespace link_creation_agent; -CustomField::CustomField(std::vector args) { - if (args[0] != "CUSTOM_FIELD") +bool is_number(const std::string& s) { + return !s.empty() && + std::find_if(s.begin(), s.end(), [](unsigned char c) { return !std::isdigit(c); }) == s.end(); +} + +int string_to_int(const std::string& s) { + if (!is_number(s)) { + throw std::invalid_argument("Can not convert string to int: Invalid arguments"); + } + return std::stoi(s); +} + +std::string get_token(std::vector& link_template, int cursor) { + if (cursor >= link_template.size()) { + throw std::invalid_argument("Can not get token: Invalid arguments"); + } + return link_template[cursor]; +} + +CustomField::CustomField(std::vector& custom_fields) { + if (get_token(custom_fields, 0) != "CUSTOM_FIELD") throw std::invalid_argument("Can not create Custom Field: Invalid arguments"); int cursor = 0; - int custom_field_size = std::stoi(args[2]); - std::string custom_field_name = args[1]; + std::string custom_field_name = get_token(custom_fields, 1); this->name = custom_field_name; cursor += 3; - while (cursor < args.size()) { - - if (args[cursor] == "CUSTOM_FIELD") { + while (cursor < custom_fields.size()) { + if (custom_fields[cursor] == "CUSTOM_FIELD") { std::vector custom_field_args; - int sub_custom_field_size = std::stoi(args[cursor + 2]); - std::string sub_custom_field_name = args[cursor + 1]; - custom_field_args.push_back(args[cursor]); // CUSTOM_FIELD - custom_field_args.push_back(args[cursor + 1]); // field name - custom_field_args.push_back(args[cursor + 2]); // field size + int sub_custom_field_size = string_to_int(custom_fields[cursor + 2]); + std::string sub_custom_field_name = custom_fields[cursor + 1]; + custom_field_args.push_back(custom_fields[cursor]); // CUSTOM_FIELD + custom_field_args.push_back(custom_fields[cursor + 1]); // field name + custom_field_args.push_back(custom_fields[cursor + 2]); // field size cursor += 3; - while (cursor < args.size()) { + while (cursor < custom_fields.size()) { if (sub_custom_field_size == 0) { break; } - custom_field_args.push_back(args[cursor]); - if (args[cursor] == "CUSTOM_FIELD") { - sub_custom_field_size += std::stoi(args[cursor + 2]); - custom_field_args.push_back(args[cursor + 1]); // field name - custom_field_args.push_back(args[cursor + 2]); // field size + custom_field_args.push_back(custom_fields[cursor]); + if (custom_fields[cursor] == "CUSTOM_FIELD") { + sub_custom_field_size += string_to_int(custom_fields[cursor + 2]); + custom_field_args.push_back(custom_fields[cursor + 1]); // field name + custom_field_args.push_back(custom_fields[cursor + 2]); // field size cursor += 3; sub_custom_field_size--; } else { - custom_field_args.push_back(args[cursor + 1]); + custom_field_args.push_back(custom_fields[cursor + 1]); cursor += 2; sub_custom_field_size--; } @@ -46,7 +64,7 @@ CustomField::CustomField(std::vector args) { this->values.push_back( std::make_tuple(sub_custom_field_name, std::make_shared(custom_field))); } else { - this->values.push_back(std::make_tuple(args[cursor], args[cursor + 1])); + this->values.push_back(std::make_tuple(custom_fields[cursor], custom_fields[cursor + 1])); cursor += 2; } } @@ -58,9 +76,12 @@ std::string CustomField::get_name() { return this->name; } std::vector> CustomField::get_values() { return this->values; } -std::vector parse_sub_custom_field(std::vector link_template, size_t& cursor) { +std::vector parse_sub_custom_field(std::vector& link_template, + size_t& cursor) { + if (link_template[cursor] != "CUSTOM_FIELD" || link_template.size() < cursor + 3) + throw std::invalid_argument("Can not create Custom Field: Invalid arguments"); std::vector custom_field_args; - int custom_field_size = std::stoi(link_template[cursor + 2]); + int custom_field_size = string_to_int(link_template[cursor + 2]); custom_field_args.push_back(link_template[cursor]); // CUSTOM_FIELD custom_field_args.push_back(link_template[cursor + 1]); // field name custom_field_args.push_back(link_template[cursor + 2]); // field size @@ -73,7 +94,7 @@ std::vector parse_sub_custom_field(std::vector link_te if (link_template[cursor] == "CUSTOM_FIELD") { custom_field_args.push_back(link_template[cursor + 1]); custom_field_args.push_back(link_template[cursor + 2]); - custom_field_size += std::stoi(link_template[cursor + 2]); + custom_field_size += string_to_int(link_template[cursor + 2]); custom_field_size--; cursor += 3; } else { @@ -85,10 +106,12 @@ std::vector parse_sub_custom_field(std::vector link_te return custom_field_args; } -std::vector parse_sub_link_template(std::vector link_template, +std::vector parse_sub_link_template(std::vector& link_template, size_t& cursor) { - int sub_link_template_size = std::stoi(link_template[cursor + 2]); - int sub_link_custom_field_size = std::stoi(link_template[cursor + 3]); + if (link_template[cursor] != "LINK_CREATE" || link_template.size() < cursor + 4) + throw std::invalid_argument("Can not create Link Template: Invalid arguments"); + int sub_link_template_size = string_to_int(link_template[cursor + 2]); + int sub_link_custom_field_size = string_to_int(link_template[cursor + 3]); int custom_field_value_size = 0; std::vector sub_link_template; int current_ptr = 0; // link create default size @@ -114,12 +137,12 @@ std::vector parse_sub_link_template(std::vector link_t } if (link_template[cursor] == "LINK_CREATE") { current_ptr = 4; - sub_link_template_size += std::stoi(link_template[cursor + 2]); - sub_link_custom_field_size = std::stoi(link_template[cursor + 3]); + sub_link_template_size += string_to_int(link_template[cursor + 2]); + sub_link_custom_field_size = string_to_int(link_template[cursor + 3]); sub_link_template_size--; } if (sub_link_custom_field_size > 0 && link_template[cursor] == "CUSTOM_FIELD") { - current_ptr = 3 + (std::stoi(link_template[cursor + 2]) * 2); + current_ptr = 3 + (string_to_int(link_template[cursor + 2]) * 2); sub_link_custom_field_size--; } @@ -129,7 +152,7 @@ std::vector parse_sub_link_template(std::vector link_t return sub_link_template; } -LinkCreateTemplate::LinkCreateTemplate(std::vector link_template) { +LinkCreateTemplate::LinkCreateTemplate(std::vector& link_template) { int stating_pos = 0; if (link_template[0] == "LINK_CREATE") { stating_pos = 1; @@ -137,8 +160,8 @@ LinkCreateTemplate::LinkCreateTemplate(std::vector link_template) { this->link_type = link_template[stating_pos]; std::size_t cursor = stating_pos; - std::size_t link_template_size = std::stoi(link_template[stating_pos + 1]); - std::size_t custom_field_size = std::stoi(link_template[stating_pos + 2]); + std::size_t link_template_size = string_to_int(link_template[stating_pos + 1]); + std::size_t custom_field_size = string_to_int(link_template[stating_pos + 2]); while (cursor < link_template.size()) { if (link_template[cursor] == "NODE") { Node node; @@ -159,11 +182,13 @@ LinkCreateTemplate::LinkCreateTemplate(std::vector link_template) { std::vector sub_custom_field = parse_sub_custom_field(link_template, cursor); CustomField custom_field = CustomField(sub_custom_field); this->custom_fields.push_back(custom_field); - cursor++; } else { cursor++; } } + if (this->targets.size() != link_template_size || this->custom_fields.size() != custom_field_size) { + throw std::invalid_argument("Can not create Link Template: Invalid arguments"); + } } LinkCreateTemplate::~LinkCreateTemplate() {} @@ -172,6 +197,8 @@ std::string LinkCreateTemplate::get_link_type() { return this->link_type; } std::vector LinkCreateTemplate::get_targets() { return this->targets; } +std::vector LinkCreateTemplate::get_custom_fields() { return this->custom_fields; } + std::string LinkCreateTemplate::to_string() { std::string link_template = "LINK_CREATE " + this->link_type + " " + std::to_string(this->targets.size()) + " " + diff --git a/src/cpp/link_creation_agent/link_create_template.h b/src/cpp/link_creation_agent/link_create_template.h index 5c1e18c..e4be463 100644 --- a/src/cpp/link_creation_agent/link_create_template.h +++ b/src/cpp/link_creation_agent/link_create_template.h @@ -28,7 +28,7 @@ using LinkCreateTemplateTypes = std::variant args); + CustomField(std::vector &custom_fields); ~CustomField(); std::string get_name(); std::vector> get_values(); @@ -48,7 +48,7 @@ enum class TargetType { NODE, TEMPLATE }; */ class LinkCreateTemplate { public: - LinkCreateTemplate(std::vector link_template); + LinkCreateTemplate(std::vector &link_template); ~LinkCreateTemplate(); std::string get_link_type(); std::vector get_targets(); diff --git a/src/cpp/tests/link_creation_agent_test.cc b/src/cpp/tests/link_creation_agent_test.cc index 3e45109..bbf1c43 100644 --- a/src/cpp/tests/link_creation_agent_test.cc +++ b/src/cpp/tests/link_creation_agent_test.cc @@ -1,19 +1,21 @@ -#include "agent.h" -#include "link_create_template.h" #include -#include -#include + #include +#include +#include + +#include "agent.h" +#include "link_create_template.h" using namespace std; using namespace link_creation_agent; class LinkCreationAgentTest : public ::testing::Test { -protected: + protected: LinkCreationAgent* agent; void SetUp() override { - // Create a temporary config file for testing + // Create a temporary config file for testing // ofstream config_file("test_config.cfg"); // config_file << "requests_interval_seconds=1\n"; // config_file << "link_creation_agent_thread_count=1\n"; @@ -32,8 +34,6 @@ class LinkCreationAgentTest : public ::testing::Test { } }; - - // TEST_F(LinkCreationAgentTest, TestRequest) { // // Simulate a request // vector request = {"query1", "LINK_CREATE", "query2", "10", "5", "test_context", "true"}; @@ -46,19 +46,16 @@ class LinkCreationAgentTest : public ::testing::Test { // EXPECT_EQ(lca_request->update_attention_broker, true); // } - // TEST_F(LinkCreationAgentTest, TestConfig){ // agent = new LinkCreationAgent("test_config.cfg"); // delete agent; // } - // TEST_F(LinkCreationAgentTest, TestOutputBuffer){ // agent = new LinkCreationAgent("test_config.cfg"); // delete agent; // } - // TEST(LinkCreateTemplate, TestCustomField){ // vector args = {"CUSTOM_FIELD", "field1", "2", "value1", "value2"}; // CustomField custom_field(args); @@ -69,22 +66,167 @@ class LinkCreationAgentTest : public ::testing::Test { // EXPECT_EQ(get(get<1>(values[1])), "value2"); // } - -TEST(LinkCreateTemplate, TestLinkCreateTemplate){ - // vector link_template = {"LINK_CREATE", "link_type", "2", "1", "NODE", "type1", "value1", "VARIABLE", "var1", "CUSTOM_FIELD", "field1", "1", "value1", "value2"}; - vector link_template = {"LINK_CREATE", "Similarity", "3", "2", "VARIABLE", "V1", "LINK_CREATE", "Test", "3","0", "NODE", "Symbol", "A", "VARIABLE", "V2", "LINK_CREATE", "Test2", "1","1", "NODE", "Symbol", "C", "CUSTOM_FIELD", "inter", "1", "inter_name", "inter_value", "NODE", "Symbol", "B", "CUSTOM_FIELD", "truth_value", "2", "CUSTOM_FIELD", "mean", "2", "count", "10", "avg", "0.9", "confidence", "0.9"}; - string link_template_str = "LINK_CREATE Similarity 3 1 VARIABLE V1 LINK_CREATE Test 3 0 NODE Symbol A VARIABLE V2 LINK_CREATE Test2 1 1 NODE Symbol C CUSTOM_FIELD inter 1 inter_name inter_value NODE Symbol B CUSTOM_FIELD truth_value 2 CUSTOM_FIELD mean 2 count 10 avg 0.9 confidence 0.9"; +vector split(const string& s, char delimiter) { + vector tokens; + string token; + istringstream tokenStream(s); + while (getline(tokenStream, token, delimiter)) { + tokens.push_back(token); + } + return tokens; +} + +TEST(LinkCreateTemplate, TestLinkCreateTemplate) { + /** #NOTE Different from the original test, the to_string() method is not returning the same order + as the input string. to_string is placing the custom fields after the targets + */ + string link_template_str = + "LINK_CREATE Similarity 3 1 VARIABLE V1 LINK_CREATE Test 3 0 NODE Symbol A VARIABLE V2 " + "LINK_CREATE Test2 1 1 NODE Symbol C CUSTOM_FIELD inter 1 inter_name inter_value NODE Symbol B " + "CUSTOM_FIELD truth_value 2 CUSTOM_FIELD mean 2 count 10 avg 0.9 confidence 0.9"; + auto link_template = split(link_template_str, ' '); LinkCreateTemplate lct(link_template); EXPECT_EQ(lct.get_link_type(), "Similarity"); EXPECT_EQ(lct.to_string(), link_template_str); link_template.clear(); link_template_str.clear(); - link_template = {"LINK_CREATE", "I", "3", "0", "VARIABLE", "V1", "LINK_CREATE", "Test", "3","0", "NODE", "Symbol", "A", "VARIABLE", "V2", "LINK_CREATE", "Test2", "1","0", "NODE", "Symbol", "C", "NODE", "Symbol", "B"}; - link_template_str = "LINK_CREATE I 3 0 VARIABLE V1 LINK_CREATE Test 3 0 NODE Symbol A VARIABLE V2 LINK_CREATE Test2 1 0 NODE Symbol C NODE Symbol B"; + + link_template_str = + "LINK_CREATE I 3 0 VARIABLE V1 LINK_CREATE Test 3 0 NODE Symbol A VARIABLE V2 LINK_CREATE Test2 " + "1 0 NODE Symbol C NODE Symbol B"; + link_template = split(link_template_str, ' '); LinkCreateTemplate lct2(link_template); EXPECT_EQ(lct2.get_link_type(), "I"); EXPECT_EQ(lct2.to_string(), link_template_str); EXPECT_EQ(lct2.get_targets().size(), 3); EXPECT_EQ(get(lct.get_targets()[0]).name, "V1"); + link_template.clear(); + link_template_str.clear(); + + link_template_str = + "LINK_CREATE Similarity 2 1 VARIABLE V1 VARIABLE V2 CUSTOM_FIELD truth_value 2 CUSTOM_FIELD " + "mean 2 count 10 avg 0.9 confidence 0.9"; + link_template = split(link_template_str, ' '); + LinkCreateTemplate lct3(link_template); + EXPECT_EQ(lct3.get_link_type(), "Similarity"); + EXPECT_EQ(lct3.to_string(), link_template_str); + link_template.clear(); + link_template_str.clear(); + + link_template_str = + "LINK_CREATE link_type 2 1 NODE type1 value1 VARIABLE var1 CUSTOM_FIELD field1 1 value1 value2"; + link_template = split(link_template_str, ' '); + LinkCreateTemplate lct4(link_template); + EXPECT_EQ(lct4.get_link_type(), "link_type"); + EXPECT_EQ(lct4.to_string(), link_template_str); + link_template.clear(); + link_template_str.clear(); + + link_template_str = + "LINK_CREATE TestLink 4 1 NODE NodeType1 Value1 VARIABLE Var1 CUSTOM_FIELD Field1 2 valuename1 " + "Value1 valuename2 Value2 NODE NodeType2 Value2 VARIABLE Var2"; + link_template = split(link_template_str, ' '); + LinkCreateTemplate lct5(link_template); + EXPECT_EQ(lct5.get_link_type(), "TestLink"); + EXPECT_EQ(lct5.to_string(), + "LINK_CREATE TestLink 4 1 NODE NodeType1 Value1 VARIABLE Var1 NODE NodeType2 Value2 " + "VARIABLE Var2 CUSTOM_FIELD Field1 2 valuename1 Value1 valuename2 Value2"); + EXPECT_EQ(lct5.get_targets().size(), 4); + EXPECT_EQ(get(lct5.get_targets()[0]).type, "NodeType1"); + EXPECT_EQ(get(lct5.get_targets()[0]).value, "Value1"); + EXPECT_EQ(get(lct5.get_targets()[1]).name, "Var1"); + link_template.clear(); + link_template_str.clear(); -} \ No newline at end of file + link_template_str = + "LINK_CREATE AnotherLink 2 1 VARIABLE VarA NODE NodeTypeA ValueA CUSTOM_FIELD FieldA 1 NameA " + "ValueA"; + link_template = split(link_template_str, ' '); + LinkCreateTemplate lct6(link_template); + EXPECT_EQ(lct6.get_link_type(), "AnotherLink"); + EXPECT_EQ(lct6.to_string(), link_template_str); + EXPECT_EQ(lct6.get_targets().size(), 2); + EXPECT_EQ(get(lct6.get_targets()[0]).name, "VarA"); + EXPECT_EQ(get(lct6.get_targets()[1]).type, "NodeTypeA"); + EXPECT_EQ(get(lct6.get_targets()[1]).value, "ValueA"); + EXPECT_EQ(lct6.get_custom_fields().size(), 1); + EXPECT_EQ(lct6.get_custom_fields()[0].get_name(), "FieldA"); + EXPECT_EQ(lct6.get_custom_fields()[0].get_values().size(), 1); + EXPECT_EQ(get<0>(lct6.get_custom_fields()[0].get_values()[0]), "NameA"); + EXPECT_EQ(get(get<1>(lct6.get_custom_fields()[0].get_values()[0])), "ValueA"); + + link_template.clear(); + link_template_str.clear(); + + link_template_str = + "LINK_CREATE ComplexLink 4 2 NODE Type1 Val1 VARIABLE Var1 CUSTOM_FIELD Field1 2 N1 Val1 N2 " + "Val2 NODE Type2 Val2 VARIABLE Var2 CUSTOM_FIELD Field2 1 N3 Val3"; + link_template = split(link_template_str, ' '); + LinkCreateTemplate lct7(link_template); + EXPECT_EQ(lct7.get_link_type(), "ComplexLink"); + EXPECT_EQ(lct7.to_string(), + "LINK_CREATE ComplexLink 4 2 NODE Type1 Val1 VARIABLE Var1 NODE Type2 Val2 VARIABLE Var2 " + "CUSTOM_FIELD Field1 2 N1 Val1 N2 Val2 CUSTOM_FIELD Field2 1 N3 Val3"); + EXPECT_EQ(lct7.get_targets().size(), 4); + EXPECT_EQ(get(lct7.get_targets()[0]).type, "Type1"); + EXPECT_EQ(get(lct7.get_targets()[0]).value, "Val1"); + EXPECT_EQ(get(lct7.get_targets()[1]).name, "Var1"); + EXPECT_EQ(get(lct7.get_targets()[2]).type, "Type2"); + EXPECT_EQ(get(lct7.get_targets()[2]).value, "Val2"); + EXPECT_EQ(get(lct7.get_targets()[3]).name, "Var2"); + EXPECT_EQ(lct7.get_custom_fields()[0].get_name(), "Field1"); + EXPECT_EQ(lct7.get_custom_fields()[0].get_values().size(), 2); + EXPECT_EQ(get<0>(lct7.get_custom_fields()[0].get_values()[0]), "N1"); + EXPECT_EQ(get(get<1>(lct7.get_custom_fields()[0].get_values()[0])), "Val1"); + EXPECT_EQ(get<0>(lct7.get_custom_fields()[0].get_values()[1]), "N2"); + EXPECT_EQ(get(get<1>(lct7.get_custom_fields()[0].get_values()[1])), "Val2"); + EXPECT_EQ(lct7.get_custom_fields()[1].get_name(), "Field2"); + EXPECT_EQ(lct7.get_custom_fields()[1].get_values().size(), 1); + EXPECT_EQ(get<0>(lct7.get_custom_fields()[1].get_values()[0]), "N3"); + EXPECT_EQ(get(get<1>(lct7.get_custom_fields()[1].get_values()[0])), "Val3"); + link_template.clear(); + link_template_str.clear(); + + link_template_str = "LINK_CREATE SimpleLink 2 0 VARIABLE SimpleVar NODE SimpleNode SimpleValue"; + link_template = split(link_template_str, ' '); + LinkCreateTemplate lct8(link_template); + EXPECT_EQ(lct8.get_link_type(), "SimpleLink"); + EXPECT_EQ(lct8.to_string(), link_template_str); + EXPECT_EQ(lct8.get_targets().size(), 2); + EXPECT_EQ(get(lct8.get_targets()[0]).name, "SimpleVar"); + EXPECT_EQ(get(lct8.get_targets()[1]).type, "SimpleNode"); + EXPECT_EQ(get(lct8.get_targets()[1]).value, "SimpleValue"); + link_template.clear(); + link_template_str.clear(); +} + +TEST(LinkCreateTemplate, TestInvalidLinkType) { + string link_template_str = "LINK_CREATE 3 1 VARIABLE V1 NODE Symbol A"; + auto link_template = split(link_template_str, ' '); + EXPECT_THROW(LinkCreateTemplate lct(link_template), invalid_argument); +} + +TEST(LinkCreateTemplate, TestInvalidTargetCount) { + string link_template_str = "LINK_CREATE Similarity 3 1 VARIABLE V1 NODE Symbol A"; + auto link_template = split(link_template_str, ' '); + EXPECT_THROW(LinkCreateTemplate lct(link_template), invalid_argument); +} + +TEST(LinkCreateTemplate, TestInvalidCustomField) { + string link_template_str = + "LINK_CREATE Similarity 2 1 VARIABLE V1 NODE Symbol A CUSTOM_FIELD field1"; + auto link_template = split(link_template_str, ' '); + EXPECT_THROW(LinkCreateTemplate lct(link_template), invalid_argument); +} + +TEST(LinkCreateTemplate, TestInvalidVariable) { + string link_template_str = "LINK_CREATE Similarity 2 1 VARIABLE NODE Symbol A"; + auto link_template = split(link_template_str, ' '); + EXPECT_THROW(LinkCreateTemplate lct(link_template), invalid_argument); +} + +TEST(LinkCreateTemplate, TestInvalidNode) { + string link_template_str = "LINK_CREATE Similarity 2 1 VARIABLE V1 NODE Symbol"; + auto link_template = split(link_template_str, ' '); + EXPECT_THROW(LinkCreateTemplate lct(link_template), invalid_argument); +} From e68596a3ca55081e376dcaf69c0d94628e1d9452 Mon Sep 17 00:00:00 2001 From: Edgar Brissow Date: Mon, 3 Feb 2025 14:18:59 -0300 Subject: [PATCH 05/10] Working on exceptions --- .../link_create_template.cc | 106 +++++++++--------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/src/cpp/link_creation_agent/link_create_template.cc b/src/cpp/link_creation_agent/link_create_template.cc index edf1e89..6d830af 100644 --- a/src/cpp/link_creation_agent/link_create_template.cc +++ b/src/cpp/link_creation_agent/link_create_template.cc @@ -34,28 +34,28 @@ CustomField::CustomField(std::vector& custom_fields) { this->name = custom_field_name; cursor += 3; while (cursor < custom_fields.size()) { - if (custom_fields[cursor] == "CUSTOM_FIELD") { + if (get_token(custom_fields, cursor) == "CUSTOM_FIELD") { std::vector custom_field_args; - int sub_custom_field_size = string_to_int(custom_fields[cursor + 2]); - std::string sub_custom_field_name = custom_fields[cursor + 1]; - custom_field_args.push_back(custom_fields[cursor]); // CUSTOM_FIELD - custom_field_args.push_back(custom_fields[cursor + 1]); // field name - custom_field_args.push_back(custom_fields[cursor + 2]); // field size + int sub_custom_field_size = string_to_int(get_token(custom_fields, cursor + 2)); + std::string sub_custom_field_name = get_token(custom_fields, cursor + 1); + custom_field_args.push_back(get_token(custom_fields, cursor)); // CUSTOM_FIELD + custom_field_args.push_back(get_token(custom_fields, cursor + 1)); // field name + custom_field_args.push_back(get_token(custom_fields, cursor + 2)); // field size cursor += 3; while (cursor < custom_fields.size()) { if (sub_custom_field_size == 0) { break; } - custom_field_args.push_back(custom_fields[cursor]); - if (custom_fields[cursor] == "CUSTOM_FIELD") { - sub_custom_field_size += string_to_int(custom_fields[cursor + 2]); - custom_field_args.push_back(custom_fields[cursor + 1]); // field name - custom_field_args.push_back(custom_fields[cursor + 2]); // field size + custom_field_args.push_back(get_token(custom_fields, cursor)); + if (get_token(custom_fields, cursor) == "CUSTOM_FIELD") { + sub_custom_field_size += string_to_int(get_token(custom_fields, cursor + 2)); + custom_field_args.push_back(get_token(custom_fields, cursor + 1)); // field name + custom_field_args.push_back(get_token(custom_fields, cursor + 2)); // field size cursor += 3; sub_custom_field_size--; } else { - custom_field_args.push_back(custom_fields[cursor + 1]); + custom_field_args.push_back(get_token(custom_fields, cursor + 1)); cursor += 2; sub_custom_field_size--; } @@ -64,7 +64,7 @@ CustomField::CustomField(std::vector& custom_fields) { this->values.push_back( std::make_tuple(sub_custom_field_name, std::make_shared(custom_field))); } else { - this->values.push_back(std::make_tuple(custom_fields[cursor], custom_fields[cursor + 1])); + this->values.push_back(std::make_tuple(get_token(custom_fields, cursor), get_token(custom_fields, cursor + 1))); cursor += 2; } } @@ -78,27 +78,27 @@ std::vector> CustomField::get_values() std::vector parse_sub_custom_field(std::vector& link_template, size_t& cursor) { - if (link_template[cursor] != "CUSTOM_FIELD" || link_template.size() < cursor + 3) + if (get_token(link_template, cursor) != "CUSTOM_FIELD" || link_template.size() < cursor + 3) throw std::invalid_argument("Can not create Custom Field: Invalid arguments"); std::vector custom_field_args; - int custom_field_size = string_to_int(link_template[cursor + 2]); - custom_field_args.push_back(link_template[cursor]); // CUSTOM_FIELD - custom_field_args.push_back(link_template[cursor + 1]); // field name - custom_field_args.push_back(link_template[cursor + 2]); // field size + int custom_field_size = string_to_int(get_token(link_template, cursor + 2)); + custom_field_args.push_back(get_token(link_template, cursor)); // CUSTOM_FIELD + custom_field_args.push_back(get_token(link_template, cursor + 1)); // field name + custom_field_args.push_back(get_token(link_template, cursor + 2)); // field size cursor += 3; while (cursor < link_template.size()) { if (custom_field_size == 0) { break; } - custom_field_args.push_back(link_template[cursor]); - if (link_template[cursor] == "CUSTOM_FIELD") { - custom_field_args.push_back(link_template[cursor + 1]); - custom_field_args.push_back(link_template[cursor + 2]); - custom_field_size += string_to_int(link_template[cursor + 2]); + custom_field_args.push_back(get_token(link_template, cursor)); + if (get_token(link_template, cursor) == "CUSTOM_FIELD") { + custom_field_args.push_back(get_token(link_template, cursor + 1)); + custom_field_args.push_back(get_token(link_template, cursor + 2)); + custom_field_size += string_to_int(get_token(link_template, cursor + 2)); custom_field_size--; cursor += 3; } else { - custom_field_args.push_back(link_template[cursor + 1]); + custom_field_args.push_back(get_token(link_template, cursor + 1)); custom_field_size--; cursor += 2; } @@ -108,41 +108,41 @@ std::vector parse_sub_custom_field(std::vector& link_t std::vector parse_sub_link_template(std::vector& link_template, size_t& cursor) { - if (link_template[cursor] != "LINK_CREATE" || link_template.size() < cursor + 4) + if (get_token(link_template, cursor) != "LINK_CREATE" || link_template.size() < cursor + 4) throw std::invalid_argument("Can not create Link Template: Invalid arguments"); - int sub_link_template_size = string_to_int(link_template[cursor + 2]); - int sub_link_custom_field_size = string_to_int(link_template[cursor + 3]); + int sub_link_template_size = string_to_int(get_token(link_template, cursor + 2)); + int sub_link_custom_field_size = string_to_int(get_token(link_template, cursor + 3)); int custom_field_value_size = 0; std::vector sub_link_template; int current_ptr = 0; // link create default size - sub_link_template.push_back(link_template[cursor]); // LINK_CREATE - sub_link_template.push_back(link_template[cursor + 1]); // link type - sub_link_template.push_back(link_template[cursor + 2]); // link size - sub_link_template.push_back(link_template[cursor + 3]); // custom field size + sub_link_template.push_back(get_token(link_template, cursor)); // LINK_CREATE + sub_link_template.push_back(get_token(link_template, cursor + 1)); // link type + sub_link_template.push_back(get_token(link_template, cursor + 2)); // link size + sub_link_template.push_back(get_token(link_template, cursor + 3)); // custom field size cursor += 4; while (cursor < link_template.size()) { if (sub_link_template_size == 0 && current_ptr == 0 && sub_link_custom_field_size == 0 && custom_field_value_size == 0) { break; } - sub_link_template.push_back(link_template[cursor]); + sub_link_template.push_back(get_token(link_template, cursor)); - if (link_template[cursor] == "NODE") { + if (get_token(link_template, cursor) == "NODE") { current_ptr = 3; sub_link_template_size--; } - if (link_template[cursor] == "VARIABLE") { + if (get_token(link_template, cursor) == "VARIABLE") { current_ptr = 2; sub_link_template_size--; } - if (link_template[cursor] == "LINK_CREATE") { + if (get_token(link_template, cursor) == "LINK_CREATE") { current_ptr = 4; - sub_link_template_size += string_to_int(link_template[cursor + 2]); - sub_link_custom_field_size = string_to_int(link_template[cursor + 3]); + sub_link_template_size += string_to_int(get_token(link_template, cursor + 2)); + sub_link_custom_field_size = string_to_int(get_token(link_template, cursor + 3)); sub_link_template_size--; } - if (sub_link_custom_field_size > 0 && link_template[cursor] == "CUSTOM_FIELD") { - current_ptr = 3 + (string_to_int(link_template[cursor + 2]) * 2); + if (sub_link_custom_field_size > 0 && get_token(link_template, cursor) == "CUSTOM_FIELD") { + current_ptr = 3 + (string_to_int(get_token(link_template, cursor + 2)) * 2); sub_link_custom_field_size--; } @@ -153,32 +153,32 @@ std::vector parse_sub_link_template(std::vector& link_ } LinkCreateTemplate::LinkCreateTemplate(std::vector& link_template) { - int stating_pos = 0; - if (link_template[0] == "LINK_CREATE") { - stating_pos = 1; + int starting_pos = 0; + if (get_token(link_template, 0) == "LINK_CREATE") { + starting_pos = 1; } - this->link_type = link_template[stating_pos]; - std::size_t cursor = stating_pos; - std::size_t link_template_size = string_to_int(link_template[stating_pos + 1]); - std::size_t custom_field_size = string_to_int(link_template[stating_pos + 2]); + this->link_type = get_token(link_template, starting_pos); + std::size_t cursor = starting_pos; + std::size_t link_template_size = string_to_int(get_token(link_template, starting_pos + 1)); + std::size_t custom_field_size = string_to_int(get_token(link_template, starting_pos + 2)); while (cursor < link_template.size()) { - if (link_template[cursor] == "NODE") { + if (get_token(link_template, cursor) == "NODE") { Node node; - node.type = link_template[cursor + 1]; - node.value = link_template[cursor + 2]; + node.type = get_token(link_template, cursor + 1); + node.value = get_token(link_template, cursor + 2); this->targets.push_back(node); cursor += 2; - } else if (link_template[cursor] == "VARIABLE") { + } else if (get_token(link_template, cursor) == "VARIABLE") { Variable var; - var.name = link_template[cursor + 1]; + var.name = get_token(link_template, cursor + 1); this->targets.push_back(var); cursor += 1; - } else if (link_template[cursor] == "LINK_CREATE") { + } else if (get_token(link_template, cursor) == "LINK_CREATE") { std::vector sub_link_template = parse_sub_link_template(link_template, cursor); LinkCreateTemplateTypes sub_link = std::make_shared(sub_link_template); this->targets.push_back(sub_link); - } else if (link_template[cursor] == "CUSTOM_FIELD") { + } else if (get_token(link_template, cursor) == "CUSTOM_FIELD") { std::vector sub_custom_field = parse_sub_custom_field(link_template, cursor); CustomField custom_field = CustomField(sub_custom_field); this->custom_fields.push_back(custom_field); From 89cdef6c102d0ba39f60f5f28bb069ddd7c697e7 Mon Sep 17 00:00:00 2001 From: Edgar Brissow Date: Mon, 3 Feb 2025 14:42:52 -0300 Subject: [PATCH 06/10] Tests done --- src/cpp/link_creation_agent/agent.cc | 1 - src/cpp/tests/link_creation_agent_test.cc | 111 +++++++++++++--------- 2 files changed, 68 insertions(+), 44 deletions(-) diff --git a/src/cpp/link_creation_agent/agent.cc b/src/cpp/link_creation_agent/agent.cc index a91d90f..4f969f0 100644 --- a/src/cpp/link_creation_agent/agent.cc +++ b/src/cpp/link_creation_agent/agent.cc @@ -50,7 +50,6 @@ void LinkCreationAgent::run() { int current_buffer_position = 0; while (true) { if(is_stoping) break; - // cout << "LinkCreationAgent running" << endl; LinkCreationAgentRequest* lca_request = NULL; bool is_from_buffer = false; if (!link_creation_node_server->is_query_empty()) { diff --git a/src/cpp/tests/link_creation_agent_test.cc b/src/cpp/tests/link_creation_agent_test.cc index bbf1c43..5b09ec0 100644 --- a/src/cpp/tests/link_creation_agent_test.cc +++ b/src/cpp/tests/link_creation_agent_test.cc @@ -16,55 +16,80 @@ class LinkCreationAgentTest : public ::testing::Test { void SetUp() override { // Create a temporary config file for testing - // ofstream config_file("test_config.cfg"); - // config_file << "requests_interval_seconds=1\n"; - // config_file << "link_creation_agent_thread_count=1\n"; - // config_file << "query_agent_client_id=localhost:8080\n"; - // config_file << "query_agent_server_id=localhost:8081\n"; - // config_file << "link_creation_agent_server_id=localhost:8082\n"; - // config_file << "das_agent_client_id=localhost:8083\n"; - // config_file << "das_agent_server_id=localhost:8083\n"; - // config_file << "requests_buffer_file=test_buffer.bin\n"; - // config_file.close(); + ofstream config_file("test_config.cfg"); + config_file << "requests_interval_seconds=1\n"; + config_file << "link_creation_agent_thread_count=1\n"; + config_file << "query_agent_client_id=localhost:8080\n"; + config_file << "query_agent_server_id=localhost:8081\n"; + config_file << "link_creation_agent_server_id=localhost:8082\n"; + config_file << "das_agent_client_id=localhost:8083\n"; + config_file << "das_agent_server_id=localhost:8083\n"; + config_file << "requests_buffer_file=test_buffer.bin\n"; + config_file.close(); } void TearDown() override { - // remove("test_config.cfg"); - // remove("test_buffer.bin"); + remove("test_config.cfg"); + remove("test_buffer.bin"); } }; -// TEST_F(LinkCreationAgentTest, TestRequest) { -// // Simulate a request -// vector request = {"query1", "LINK_CREATE", "query2", "10", "5", "test_context", "true"}; -// LinkCreationAgentRequest* lca_request = LinkCreationAgent::create_request(request); -// EXPECT_EQ(lca_request->query, vector({"query1"})); -// EXPECT_EQ(lca_request->link_template, vector({"LINK_CREATE", "query2"})); -// EXPECT_EQ(lca_request->max_results, 10); -// EXPECT_EQ(lca_request->repeat, 5); -// EXPECT_EQ(lca_request->context, "test_context"); -// EXPECT_EQ(lca_request->update_attention_broker, true); -// } - -// TEST_F(LinkCreationAgentTest, TestConfig){ -// agent = new LinkCreationAgent("test_config.cfg"); -// delete agent; -// } - -// TEST_F(LinkCreationAgentTest, TestOutputBuffer){ -// agent = new LinkCreationAgent("test_config.cfg"); -// delete agent; -// } - -// TEST(LinkCreateTemplate, TestCustomField){ -// vector args = {"CUSTOM_FIELD", "field1", "2", "value1", "value2"}; -// CustomField custom_field(args); -// EXPECT_EQ(custom_field.get_name(), "field1"); -// vector> values = custom_field.get_values(); -// EXPECT_EQ(values.size(), 2); -// EXPECT_EQ(get(get<1>(values[0])), "value1"); -// EXPECT_EQ(get(get<1>(values[1])), "value2"); -// } +TEST_F(LinkCreationAgentTest, TestRequest) { + // Simulate a request + vector request = {"query1", "LINK_CREATE", "test", "1", "0", "VARIABLE", "V1", "10", "5", "test_context", "true"}; + LinkCreationAgentRequest* lca_request = LinkCreationAgent::create_request(request); + EXPECT_EQ(lca_request->query, vector({"query1"})); + EXPECT_EQ(lca_request->link_template, vector({"LINK_CREATE", "test", "1", "0", "VARIABLE", "V1"})); + EXPECT_EQ(lca_request->max_results, 10); + EXPECT_EQ(lca_request->repeat, 5); + EXPECT_EQ(lca_request->context, "test_context"); + EXPECT_EQ(lca_request->update_attention_broker, true); +} + +TEST_F(LinkCreationAgentTest, TestConfig){ + agent = new LinkCreationAgent("test_config.cfg"); + delete agent; +} + + +TEST(LinkCreateTemplate, TestCustomField){ + vector args = {"CUSTOM_FIELD", "field1", "2", "N1", "value1", "N2", "value2"}; + CustomField custom_field(args); + EXPECT_EQ(custom_field.get_name(), "field1"); + vector> values = custom_field.get_values(); + EXPECT_EQ(values.size(), 2); + EXPECT_EQ(get(get<1>(values[0])), "value1"); + EXPECT_EQ(get(get<1>(values[1])), "value2"); + + // Test custom field with no values + vector args_empty = {"CUSTOM_FIELD", "empty_field", "0"}; + CustomField custom_field_empty(args_empty); + EXPECT_EQ(custom_field_empty.get_name(), "empty_field"); + EXPECT_EQ(custom_field_empty.get_values().size(), 0); + + // Test custom field with multiple values + vector args_multiple = {"CUSTOM_FIELD", "multi_field", "3", "N1", "value1", "N2", "value2", "N3", "value3"}; + CustomField custom_field_multiple(args_multiple); + EXPECT_EQ(custom_field_multiple.get_name(), "multi_field"); + vector> values_multiple = custom_field_multiple.get_values(); + EXPECT_EQ(values_multiple.size(), 3); + EXPECT_EQ(get(get<1>(values_multiple[0])), "value1"); + EXPECT_EQ(get(get<1>(values_multiple[1])), "value2"); + EXPECT_EQ(get(get<1>(values_multiple[2])), "value3"); + + // Test nested custom fields + vector args_nested = {"CUSTOM_FIELD", "nested_field", "2", "N1", "value1", "CUSTOM_FIELD", "inner_field", "1", "N2", "value2"}; + CustomField custom_field_nested(args_nested); + EXPECT_EQ(custom_field_nested.get_name(), "nested_field"); + vector> values_nested = custom_field_nested.get_values(); + EXPECT_EQ(values_nested.size(), 2); + EXPECT_EQ(get(get<1>(values_nested[0])), "value1"); + shared_ptr inner_field = get>(get<1>(values_nested[1])); + EXPECT_EQ(inner_field->get_name(), "inner_field"); + vector> inner_values = inner_field->get_values(); + EXPECT_EQ(inner_values.size(), 1); + EXPECT_EQ(get(get<1>(inner_values[0])), "value2"); +} vector split(const string& s, char delimiter) { vector tokens; From e6d5f148ac7a1a4b3c12129e11b4a077ddb35e4b Mon Sep 17 00:00:00 2001 From: Edgar Brissow Date: Mon, 3 Feb 2025 14:44:10 -0300 Subject: [PATCH 07/10] Tests done --- src/scripts/bazel_build.sh | 80 +++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/src/scripts/bazel_build.sh b/src/scripts/bazel_build.sh index 6c7aa2b..16c6c16 100755 --- a/src/scripts/bazel_build.sh +++ b/src/scripts/bazel_build.sh @@ -7,43 +7,43 @@ BAZELISK_BUILD_CMD="${BAZELISK_CMD} build --jobs ${JOBS} --enable_bzlmod" # CPP build cd $CPP_WORKSPACE_DIR \ && $BAZELISK_BUILD_CMD //:link_creation_server \ -&& mv bazel-bin/link_creation_server $BIN_DIR -# && $BAZELISK_BUILD_CMD //:link_creation_agent_client \ -# && mv bazel-bin/link_creation_agent_client $BIN_DIR \ -# && $BAZELISK_BUILD_CMD //:word_query \ -# && mv bazel-bin/word_query $BIN_DIR \ -# && $BAZELISK_BUILD_CMD //:attention_broker_service \ -# && mv bazel-bin/attention_broker_service $BIN_DIR \ -# && $BAZELISK_BUILD_CMD //:query_broker \ -# && mv bazel-bin/query_broker $BIN_DIR \ -# && $BAZELISK_BUILD_CMD //:query \ -# && mv bazel-bin/query $BIN_DIR \ -# && $BAZELISK_BUILD_CMD \ -# //hyperon_das_atomdb_cpp:hyperon_das_atomdb_cpp_wheel \ -# --define=ATOMDB_VERSION=0.8.11 \ -# && mv bazel-bin/hyperon_das_atomdb_cpp/*.whl "$BIN_DIR" - -# # Python build -# cd "$PYTHON_WORKSPACE_DIR" - -# $BAZELISK_CMD run --jobs ${JOBS} \ -# --noenable_bzlmod --enable_workspace \ -# //deps:requirements.update - -# $BAZELISK_CMD run --jobs ${JOBS} \ -# --noenable_bzlmod --enable_workspace \ -# //deps:requirements_dev.update - -# $BAZELISK_CMD build --jobs ${JOBS} \ -# --noenable_bzlmod --enable_workspace \ -# //hyperon_das_atomdb:hyperon_das_atomdb_wheel \ -# --define=ATOMDB_VERSION=0.8.11 - -# $BAZELISK_CMD build --jobs ${JOBS} \ -# --noenable_bzlmod --enable_workspace \ -# //hyperon_das:hyperon_das_wheel \ -# --define=DAS_VERSION=0.9.17 - - -# mv bazel-bin/hyperon_das_atomdb/*.whl "$BIN_DIR" -# mv bazel-bin/hyperon_das/*.whl "$BIN_DIR" \ No newline at end of file +&& mv bazel-bin/link_creation_server $BIN_DIR \ +&& $BAZELISK_BUILD_CMD //:link_creation_agent_client \ +&& mv bazel-bin/link_creation_agent_client $BIN_DIR \ +&& $BAZELISK_BUILD_CMD //:word_query \ +&& mv bazel-bin/word_query $BIN_DIR \ +&& $BAZELISK_BUILD_CMD //:attention_broker_service \ +&& mv bazel-bin/attention_broker_service $BIN_DIR \ +&& $BAZELISK_BUILD_CMD //:query_broker \ +&& mv bazel-bin/query_broker $BIN_DIR \ +&& $BAZELISK_BUILD_CMD //:query \ +&& mv bazel-bin/query $BIN_DIR \ +&& $BAZELISK_BUILD_CMD \ + //hyperon_das_atomdb_cpp:hyperon_das_atomdb_cpp_wheel \ + --define=ATOMDB_VERSION=0.8.11 \ +&& mv bazel-bin/hyperon_das_atomdb_cpp/*.whl "$BIN_DIR" + +# Python build +cd "$PYTHON_WORKSPACE_DIR" + +$BAZELISK_CMD run --jobs ${JOBS} \ + --noenable_bzlmod --enable_workspace \ + //deps:requirements.update + +$BAZELISK_CMD run --jobs ${JOBS} \ + --noenable_bzlmod --enable_workspace \ + //deps:requirements_dev.update + +$BAZELISK_CMD build --jobs ${JOBS} \ + --noenable_bzlmod --enable_workspace \ + //hyperon_das_atomdb:hyperon_das_atomdb_wheel \ + --define=ATOMDB_VERSION=0.8.11 + +$BAZELISK_CMD build --jobs ${JOBS} \ + --noenable_bzlmod --enable_workspace \ + //hyperon_das:hyperon_das_wheel \ + --define=DAS_VERSION=0.9.17 + + +mv bazel-bin/hyperon_das_atomdb/*.whl "$BIN_DIR" +mv bazel-bin/hyperon_das/*.whl "$BIN_DIR" \ No newline at end of file From ca49ff5be6c47b5193f9e6dbbd1094b84649ff8c Mon Sep 17 00:00:00 2001 From: Edgar Brissow Date: Mon, 3 Feb 2025 14:50:47 -0300 Subject: [PATCH 08/10] Docs --- .../link_create_template.cc | 7 +- .../link_create_template.h | 85 +++++++++++++++++-- src/cpp/tests/link_creation_agent_test.cc | 29 +++++-- 3 files changed, 100 insertions(+), 21 deletions(-) diff --git a/src/cpp/link_creation_agent/link_create_template.cc b/src/cpp/link_creation_agent/link_create_template.cc index 6d830af..d35d716 100644 --- a/src/cpp/link_creation_agent/link_create_template.cc +++ b/src/cpp/link_creation_agent/link_create_template.cc @@ -1,8 +1,8 @@ #include "link_create_template.h" +#include #include #include -#include using namespace link_creation_agent; @@ -64,7 +64,8 @@ CustomField::CustomField(std::vector& custom_fields) { this->values.push_back( std::make_tuple(sub_custom_field_name, std::make_shared(custom_field))); } else { - this->values.push_back(std::make_tuple(get_token(custom_fields, cursor), get_token(custom_fields, cursor + 1))); + this->values.push_back( + std::make_tuple(get_token(custom_fields, cursor), get_token(custom_fields, cursor + 1))); cursor += 2; } } @@ -114,7 +115,7 @@ std::vector parse_sub_link_template(std::vector& link_ int sub_link_custom_field_size = string_to_int(get_token(link_template, cursor + 3)); int custom_field_value_size = 0; std::vector sub_link_template; - int current_ptr = 0; // link create default size + int current_ptr = 0; // link create default size sub_link_template.push_back(get_token(link_template, cursor)); // LINK_CREATE sub_link_template.push_back(get_token(link_template, cursor + 1)); // link type sub_link_template.push_back(get_token(link_template, cursor + 2)); // link size diff --git a/src/cpp/link_creation_agent/link_create_template.h b/src/cpp/link_creation_agent/link_create_template.h index e4be463..e55d98e 100644 --- a/src/cpp/link_creation_agent/link_create_template.h +++ b/src/cpp/link_creation_agent/link_create_template.h @@ -12,50 +12,117 @@ namespace link_creation_agent { -class CustomField; -class LinkCreateTemplate; +class CustomField; // Forward declaration +class LinkCreateTemplate; // Forward declaration + +/** + * @struct Node + * @brief Represents a node with a type and value. + * + * @var Node::type + * Type of the node. + * + * @var Node::value + * Value of the node. + */ struct Node { std::string type; std::string value; }; +/** + * @struct Variable + * @brief Represents a variable with a name. + * + * @var Variable::name + * Name of the variable. + */ struct Variable { std::string name; }; +/** + * @typedef CustomFieldTypes + * @brief A variant type that can hold either a std::string or a std::shared_ptr to a CustomField. + */ using CustomFieldTypes = std::variant>; +/** + * @typedef LinkCreateTemplateTypes + * @brief A variant type that can hold either a Variable, Node, or a std::shared_ptr to a + * LinkCreateTemplate. + */ using LinkCreateTemplateTypes = std::variant>; +/** + * @class CustomField + * @brief Represents a custom field with a name and a list of values. + */ class CustomField { public: - CustomField(std::vector &custom_fields); + /** + * @brief Constructor that initializes the custom field with a list of custom fields. + */ + CustomField(std::vector& custom_fields); + /** + * @brief Destructor for the CustomField class. + */ ~CustomField(); + /** + * @brief Gets the name of the custom field. + * @return The name of the custom field. + */ std::string get_name(); + /** + * @brief Gets the values of the custom field. + * @return A vector of tuples containing the name and value of the custom field. + */ std::vector> get_values(); + /** + * @brief Converts the custom field to a string representation. + * @return A string representation of the custom field. + */ std::string to_string(); - private: std::string name; std::vector> values; - // CustomFieldTypes value; }; -enum class TargetType { NODE, TEMPLATE }; - /** * @class LinkCreateTemplate + * @brief Represents a link creation template with a link type, targets, and custom fields. */ class LinkCreateTemplate { public: - LinkCreateTemplate(std::vector &link_template); + /** + * @brief Constructor that initializes the link creation template with a list of link templates. + */ + LinkCreateTemplate(std::vector& link_template); + /** + * @brief Destructor for the LinkCreateTemplate class. + */ ~LinkCreateTemplate(); + /** + * @brief Gets the link type of the template. + * @return The link type of the template. + */ std::string get_link_type(); + /** + * @brief Gets the targets of the link creation template. + * @return A vector of LinkCreateTemplateTypes representing the targets. + */ std::vector get_targets(); + /** + * @brief Gets the custom fields of the link creation template. + * @return A vector of CustomField objects representing the custom fields. + */ std::vector get_custom_fields(); + /** + * @brief Converts the link creation template to a string representation. + * @return A string representation of the link creation template. + */ std::string to_string(); - private: std::string link_type; std::vector targets; diff --git a/src/cpp/tests/link_creation_agent_test.cc b/src/cpp/tests/link_creation_agent_test.cc index 5b09ec0..17c6971 100644 --- a/src/cpp/tests/link_creation_agent_test.cc +++ b/src/cpp/tests/link_creation_agent_test.cc @@ -36,23 +36,24 @@ class LinkCreationAgentTest : public ::testing::Test { TEST_F(LinkCreationAgentTest, TestRequest) { // Simulate a request - vector request = {"query1", "LINK_CREATE", "test", "1", "0", "VARIABLE", "V1", "10", "5", "test_context", "true"}; + vector request = { + "query1", "LINK_CREATE", "test", "1", "0", "VARIABLE", "V1", "10", "5", "test_context", "true"}; LinkCreationAgentRequest* lca_request = LinkCreationAgent::create_request(request); EXPECT_EQ(lca_request->query, vector({"query1"})); - EXPECT_EQ(lca_request->link_template, vector({"LINK_CREATE", "test", "1", "0", "VARIABLE", "V1"})); + EXPECT_EQ(lca_request->link_template, + vector({"LINK_CREATE", "test", "1", "0", "VARIABLE", "V1"})); EXPECT_EQ(lca_request->max_results, 10); EXPECT_EQ(lca_request->repeat, 5); EXPECT_EQ(lca_request->context, "test_context"); EXPECT_EQ(lca_request->update_attention_broker, true); } -TEST_F(LinkCreationAgentTest, TestConfig){ - agent = new LinkCreationAgent("test_config.cfg"); - delete agent; +TEST_F(LinkCreationAgentTest, TestConfig) { + agent = new LinkCreationAgent("test_config.cfg"); + delete agent; } - -TEST(LinkCreateTemplate, TestCustomField){ +TEST(LinkCreateTemplate, TestCustomField) { vector args = {"CUSTOM_FIELD", "field1", "2", "N1", "value1", "N2", "value2"}; CustomField custom_field(args); EXPECT_EQ(custom_field.get_name(), "field1"); @@ -68,7 +69,8 @@ TEST(LinkCreateTemplate, TestCustomField){ EXPECT_EQ(custom_field_empty.get_values().size(), 0); // Test custom field with multiple values - vector args_multiple = {"CUSTOM_FIELD", "multi_field", "3", "N1", "value1", "N2", "value2", "N3", "value3"}; + vector args_multiple = { + "CUSTOM_FIELD", "multi_field", "3", "N1", "value1", "N2", "value2", "N3", "value3"}; CustomField custom_field_multiple(args_multiple); EXPECT_EQ(custom_field_multiple.get_name(), "multi_field"); vector> values_multiple = custom_field_multiple.get_values(); @@ -78,7 +80,16 @@ TEST(LinkCreateTemplate, TestCustomField){ EXPECT_EQ(get(get<1>(values_multiple[2])), "value3"); // Test nested custom fields - vector args_nested = {"CUSTOM_FIELD", "nested_field", "2", "N1", "value1", "CUSTOM_FIELD", "inner_field", "1", "N2", "value2"}; + vector args_nested = {"CUSTOM_FIELD", + "nested_field", + "2", + "N1", + "value1", + "CUSTOM_FIELD", + "inner_field", + "1", + "N2", + "value2"}; CustomField custom_field_nested(args_nested); EXPECT_EQ(custom_field_nested.get_name(), "nested_field"); vector> values_nested = custom_field_nested.get_values(); From ec33df2f73989cc0452d51fd4e0a4140829ebec2 Mon Sep 17 00:00:00 2001 From: Edgar Brissow Date: Mon, 3 Feb 2025 14:58:54 -0300 Subject: [PATCH 09/10] Removing couts --- src/cpp/link_creation_agent/agent.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/cpp/link_creation_agent/agent.cc b/src/cpp/link_creation_agent/agent.cc index 4f969f0..08bd5a1 100644 --- a/src/cpp/link_creation_agent/agent.cc +++ b/src/cpp/link_creation_agent/agent.cc @@ -187,12 +187,6 @@ LinkCreationAgentRequest* LinkCreationAgent::create_request(vector reque } } lca_request->infinite = (lca_request->repeat == -1); - auto link_template = new LinkCreateTemplate(lca_request->link_template); - cout << "template ok" << endl; - cout << "Link Type: " << link_template->get_link_type() << endl; - cout << "CREATE_LINK" << endl; - cout << link_template->to_string() << endl; - return lca_request; } catch (exception& e) { cout << "Error parsing request: " << e.what() << endl; From 8ae90af11a5ecde86f54da7b1164db2bbb9e5bc5 Mon Sep 17 00:00:00 2001 From: Edgar Brissow Date: Fri, 7 Feb 2025 11:17:41 -0300 Subject: [PATCH 10/10] Fixing static functions --- .../link_creation_agent/link_create_template.cc | 11 ++++++----- src/cpp/tests/link_creation_agent_test.cc | 14 +++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/cpp/link_creation_agent/link_create_template.cc b/src/cpp/link_creation_agent/link_create_template.cc index d35d716..ddb1395 100644 --- a/src/cpp/link_creation_agent/link_create_template.cc +++ b/src/cpp/link_creation_agent/link_create_template.cc @@ -6,19 +6,20 @@ using namespace link_creation_agent; -bool is_number(const std::string& s) { +// TODO move this to a utils file +static bool is_number(const std::string& s) { return !s.empty() && std::find_if(s.begin(), s.end(), [](unsigned char c) { return !std::isdigit(c); }) == s.end(); } - -int string_to_int(const std::string& s) { +// TODO move this to a utils file +static int string_to_int(const std::string& s) { if (!is_number(s)) { throw std::invalid_argument("Can not convert string to int: Invalid arguments"); } return std::stoi(s); } - -std::string get_token(std::vector& link_template, int cursor) { +// TODO move this to a utils file +static std::string get_token(std::vector& link_template, int cursor) { if (cursor >= link_template.size()) { throw std::invalid_argument("Can not get token: Invalid arguments"); } diff --git a/src/cpp/tests/link_creation_agent_test.cc b/src/cpp/tests/link_creation_agent_test.cc index 17c6971..cb48be5 100644 --- a/src/cpp/tests/link_creation_agent_test.cc +++ b/src/cpp/tests/link_creation_agent_test.cc @@ -19,11 +19,11 @@ class LinkCreationAgentTest : public ::testing::Test { ofstream config_file("test_config.cfg"); config_file << "requests_interval_seconds=1\n"; config_file << "link_creation_agent_thread_count=1\n"; - config_file << "query_agent_client_id=localhost:8080\n"; - config_file << "query_agent_server_id=localhost:8081\n"; - config_file << "link_creation_agent_server_id=localhost:8082\n"; - config_file << "das_agent_client_id=localhost:8083\n"; - config_file << "das_agent_server_id=localhost:8083\n"; + config_file << "query_agent_client_id=localhost:7001\n"; + config_file << "query_agent_server_id=localhost:7002\n"; + config_file << "link_creation_agent_server_id=localhost:7003\n"; + config_file << "das_agent_client_id=localhost:7004\n"; + config_file << "das_agent_server_id=localhost:7005\n"; config_file << "requests_buffer_file=test_buffer.bin\n"; config_file.close(); } @@ -113,8 +113,8 @@ vector split(const string& s, char delimiter) { } TEST(LinkCreateTemplate, TestLinkCreateTemplate) { - /** #NOTE Different from the original test, the to_string() method is not returning the same order - as the input string. to_string is placing the custom fields after the targets + /** #NOTE Different from the original string test, the to_string() method is not returning the same + order as the input string. to_string is placing the custom fields after the targets */ string link_template_str = "LINK_CREATE Similarity 3 1 VARIABLE V1 LINK_CREATE Test 3 0 NODE Symbol A VARIABLE V2 "