Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/agents/context_broker/ContextBrokerProxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,34 @@ ContextBrokerProxy::ContextBrokerProxy(
this->context_created = false;
}

ContextBrokerProxy::ContextBrokerProxy(const string& name,
const vector<string>& query,
const string& determiner_schema,
const string& stimulus_schema)
: BaseQueryProxy(query, name) {
// Constructor for query-based context
this->command = ServiceBus::CONTEXT;
// Parse determiner_schema
auto determiner_list = Utils::split(determiner_schema, ',');
for (auto item : determiner_list) {
auto pair = Utils::split(item, ':');
if (pair.size() == 2) {
this->determiner_schema.push_back(make_pair(QueryAnswerElement::from_string(pair[0]),
QueryAnswerElement::from_string(pair[1])));
}
}
// Parse stimulus_schema
auto stimulus_list = Utils::split(stimulus_schema, ',');
for (auto item : stimulus_list) {
this->stimulus_schema.push_back(QueryAnswerElement::from_string(item));
}
set_default_query_parameters();
init(name);
this->update_attention_broker_parameters = false;
this->ongoing_attention_broker_set_parameters = false;
this->context_created = false;
}

ContextBrokerProxy::~ContextBrokerProxy() { this->abort(); }

// -------------------------------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions src/agents/context_broker/ContextBrokerProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ class ContextBrokerProxy : public BaseQueryProxy {
const vector<string>& query,
const vector<pair<QueryAnswerElement, QueryAnswerElement>>& determiner_schema,
const vector<QueryAnswerElement>& stimulus_schema);
/**
* Constructor for schema-based context.
* @param name Context name
* @param query Query tokens
* @param determiner_schema Determiner schema string, ex: "C1:C2,C3:C4"
* @param stimulus_schema Stimulus schema string, ex: "S1,S2,S3"
*/
ContextBrokerProxy(const string& name,
const vector<string>& query,
const string& determiner_schema,
const string& stimulus_schema);

/**
* Destructor.
Expand Down
11 changes: 3 additions & 8 deletions src/main/helpers/Helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ This client sends context management requests to the Context Broker via the serv
It requires the following arguments:
- context: The context in which the query should be evaluated.
- query: The query to be processed.
- determiner-schema: The determiner schema for the query.
- stimulus-schema: The stimulus schema for the query.
- determiner-schema: The determiner schema for the query, ex: "C1:C2,C3:C4".
- stimulus-schema: The stimulus schema for the query, ex: "S1,S2,S3".
Optional arguments:
- use-context-cache: Whether to use the context cache (true/false)
- enforce-cache-recreation: Whether to enforce cache recreation (true/false)
Expand Down Expand Up @@ -241,12 +241,7 @@ vector<string> Helper::get_required_arguments(const string& processor_type,
}
case ProcessorType::CONTEXT_BROKER:
if (caller_type == ServiceCallerType::CLIENT) {
return {CONTEXT,
QUERY,
DETERMINER_SCHEMA,
STIMULUS_SCHEMA,
USE_CONTEXT_CACHE,
ENFORCE_CACHE_RECREATION};
return {CONTEXT, QUERY, DETERMINER_SCHEMA, STIMULUS_SCHEMA};
} else {
return {ATTENTION_BROKER_ENDPOINT};
}
Expand Down
44 changes: 24 additions & 20 deletions src/main/helpers/ProxyFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,30 @@ class ProxyFactory {
"query", ""); // Note to reviewer: Helper::QUERY is not linking
string determiner_schema = params.get<string>(Helper::DETERMINER_SCHEMA);
string stimulus_schema = params.get<string>(Helper::STIMULUS_SCHEMA);
// auto proxy = make_shared<ContextBrokerProxy>();
// auto use_cache = params.get<string>(Helper::USE_CONTEXT_CACHE);
// auto enforce_cache_recreation = params.get<string>(Helper::ENFORCE_CACHE_RECREATION);
// auto initial_rent_rate = params.get<string>(Helper::INITIAL_RENT_RATE);
// auto initial_spreading_rate_lowerbound =
// params.get<string>(Helper::INITIAL_SPREADING_RATE_LOWERBOUND);
// auto initial_spreading_rate_upperbound =
// params.get<string>(Helper::INITIAL_SPREADING_RATE_UPPERBOUND);
// proxy->parameters[ContextBrokerProxy::USE_CACHE] =
// (use_cache == "true" || use_cache == "1");
// proxy->parameters[ContextBrokerProxy::ENFORCE_CACHE_RECREATION] =
// (enforce_cache_recreation == "true" || enforce_cache_recreation == "1");
// proxy->parameters[ContextBrokerProxy::INITIAL_RENT_RATE] = stod(initial_rent_rate);
// proxy->parameters[ContextBrokerProxy::INITIAL_SPREADING_RATE_LOWERBOUND] =
// stod(initial_spreading_rate_lowerbound);
// proxy->parameters[ContextBrokerProxy::INITIAL_SPREADING_RATE_UPPERBOUND] =
// stod(initial_spreading_rate_upperbound);
return nullptr;
auto proxy = make_shared<ContextBrokerProxy>(
context, Utils::split(query, ' '), determiner_schema, stimulus_schema);
auto params = &proxy->parameters;
set_param(*params,
ContextBrokerProxy::USE_CACHE,
params->get_or<string>(Helper::USE_CONTEXT_CACHE, ""),
ParamType::BOOL);
set_param(*params,
ContextBrokerProxy::ENFORCE_CACHE_RECREATION,
params->get_or<string>(Helper::ENFORCE_CACHE_RECREATION, ""),
ParamType::BOOL);
set_param(*params,
ContextBrokerProxy::INITIAL_RENT_RATE,
params->get_or<string>(Helper::INITIAL_RENT_RATE, ""),
ParamType::DOUBLE);
set_param(*params,
ContextBrokerProxy::INITIAL_SPREADING_RATE_LOWERBOUND,
params->get_or<string>(Helper::INITIAL_SPREADING_RATE_LOWERBOUND, ""),
ParamType::DOUBLE);
set_param(*params,
ContextBrokerProxy::INITIAL_SPREADING_RATE_UPPERBOUND,
params->get_or<string>(Helper::INITIAL_SPREADING_RATE_UPPERBOUND, ""),
ParamType::DOUBLE);
return proxy;
}
case ProcessorType::EVOLUTION_AGENT: {
string query =
Expand Down Expand Up @@ -167,8 +173,6 @@ class ProxyFactory {
return proxy;
}
case ProcessorType::ATOMDB_BROKER: {
// string action = params.get_or<string>(Helper::ACTION, "");
// string tokens = params.get_or<string>(Helper::TOKENS, "");
return make_shared<AtomDBProxy>();
}
default:
Expand Down