Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • scs/ipaaca
  • ramin.yaghoubzadeh/ipaaca
2 results
Show changes
Showing
with 3884 additions and 0 deletions
/*
* This file is part of IPAACA, the
* "Incremental Processing Architecture
* for Artificial Conversational Agents".
*
* Copyright (c) 2009-2022 Sociable Agents Group
* CITEC, Bielefeld University
*
* http://opensource.cit-ec.de/projects/ipaaca/
* http://purl.org/net/ipaaca
*
* This file may be licensed under the terms of of the
* GNU Lesser General Public License Version 3 (the ``LGPL''),
* or (at your option) any later version.
*
* Software distributed under the License is distributed
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the LGPL for the specific language
* governing rights and limitations.
*
* You should have received a copy of the LGPL along with this
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
* or write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The development of this software was supported by the
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
* The Excellence Cluster EXC 277 is a grant of the Deutsche
* Forschungsgemeinschaft (DFG) in the context of the German
* Excellence Initiative.
*/
//
// Ipaaca 2 (ipaaca-rsb)
//
// *****************************
// *** ***
// *** C++ usage example ***
// *** ***
// *****************************
//
// Example class highlighting the use of the C++ interface
// to ipaaca2. This class uses a setup similar to an ipaaca1
// 'Component' (the concept does not exist anymore in ipaaca2).
//
#include <ipaaca/ipaaca.h>
#include <typeinfo>
using namespace ipaaca;
/// Test component for ipaaca2
/// The interface is much more flexible than in ipaaca1.
/// This example class provides an interface similar to ipaaca1.
class LegacyComponent {
protected:
/// Make a buffer pair, as in ipaaca1.
/// NOTE1: This is no longer a restriction. You can have
/// multiple buffers, no input buffer, etc.
/// NOTE2: Most objects are referred to using smart pointers
/// using the type name <className>::ptr - don't use '*'
OutputBuffer::ptr _out_buf;
InputBuffer::ptr _in_buf;
public:
/// Constructor to set up the component
LegacyComponent();
/// IU event handler function. Can be a member function,
/// a static function, anything. Use boost::bind on registration.
/// NOTE1: you can register any number of handlers on any Buffer.
/// NOTE2: this example function has the appropriate signature.
void handle_iu_event(IUInterface::ptr iu, IUEventType event_type, bool local);
/// example publishing function to produce a 'grounded' IU
void publish_reply_iu(const std::string& text, const std::string& received_iu_uid);
void publish_reply_message(const std::string& text, const std::string& received_iu_uid);
void publish_hello_world();
};
LegacyComponent::LegacyComponent() {
/// First create the buffer pair
/// Create an output buffer
_out_buf = OutputBuffer::create("MyOutputBuffer");
/// Create an input buffer with category interest
/// NOTE: You can pass up to four categories as strings
// to the constructor, or use an std::vector<std::string>
_in_buf = InputBuffer::create("MyInputBuffer", "myCategoryInterest");
/// Now register the IU handler on both buffers.
/// NOTE1: we could register separate handlers instead.
/// NOTE2: boost::bind enables use of simple closures:
/// You could specify constants for the handler function, as long as the
/// remaining open arguments form the correct signature for IU handlers.
/// ** If you simply want to use a class member function, use it as below **
/// NOTE3: the Buffers are 'live' immediately on creation. As soon as
/// you connect a handler, it can be triggered (no backend connect etc.).
/// If this is not what you want, you should set a flag when you are
/// ready to actually start, and have the handlers honor that flag.
_out_buf->register_handler(boost::bind(&LegacyComponent::handle_iu_event, this, _1, _2, _3));
_in_buf->register_handler(boost::bind(&LegacyComponent::handle_iu_event, this, _1, _2, _3));
}
void LegacyComponent::handle_iu_event(IUInterface::ptr iu, IUEventType event_type, bool local)
{
if (local) {
std::cout << "[Received update of self-owned IU]" << std::endl;
// could do processing here to cope with remote change of own IU
} else {
// event on a remote IU
if (event_type == IU_MESSAGE) {
std::cout << "[Received new Message!]" << std::endl;
std::string description = iu->payload()["description"];
std::cout << "[ Current description: " << description << "]" << std::endl;
/// let's also react by emitting an IU ourselves (function below)
publish_reply_iu("important-result", iu->uid());
} else if (event_type == IU_ADDED) {
std::cout << "[Received new IU!]" << std::endl;
/// new Payload class enables dynamic typing to some degree (numeric default 0)
std::string description = iu->payload()["description"];
double fraction = iu->payload()["fraction"];
/// let's also get the grounded-in links
std::set<std::string> grin_links = iu->get_links("GRIN");
std::cout << "[ Current description: " << description << "]" << std::endl;
/// let's also react by emitting an IU ourselves (function below)
publish_reply_message("important-result", iu->uid());
} else if (event_type == IU_UPDATED) {
std::cout << "[Received IU payload update for IU " << iu->uid() << "]" << std::endl;
std::string description = iu->payload()["description"];
std::cout << "[ Current description: " << description << "]" << std::endl;
} else if (event_type == IU_LINKSUPDATED) {
std::cout << "[IU links updated.]" << std::endl;
} else if (event_type == IU_COMMITTED) {
std::cout << "[IU " << iu->uid() << " has been committed to.]" << std::endl;
} else if (event_type == IU_RETRACTED) {
std::cout << "[IU " << iu->uid() << " has been retracted.]" << std::endl;
} else if (event_type == IU_DELETED) {
std::cout << "[IU " << iu->uid() << " has been deleted.]" << std::endl;
} else {
// Possible to stringify the type:
std::cout << "[(IU event " << iu_event_type_to_str(event_type) << " " << iu->uid() << ")]" << std::endl;
}
}
}
void LegacyComponent::publish_reply_iu(const std::string& text, const std::string& received_iu_uid) {
/// create a new IU
IU::ptr iu = IU::create( "myResultCategory" );
/// Add something to the payload
iu->payload()["description"] = "SomeResult";
/// Now add a grounded-in link pointing to the IU received before
/// There are no limitations to the link group names.
/// "GRIN" is a convention for the "grounded-in" function of the GAM.
iu->add_link("GRIN", received_iu_uid);
/// add to output buffer ( = "publish")
_out_buf->add(iu);
}
void LegacyComponent::publish_reply_message(const std::string& text, const std::string& received_iu_uid) {
IU::ptr iu = Message::create( "myResultCategory" );
iu->payload()["description"] = "SomeResult";
iu->add_link("GRIN", received_iu_uid);
_out_buf->add(iu);
}
void LegacyComponent::publish_hello_world() {
IU::ptr iu = Message::create( "myCategoryInterest"); //helloWorld" );
iu->payload()["description"] = "Hello world";
_out_buf->add(iu);
}
int main() {
std::cout << "Creating buffers..." << std::endl;
LegacyComponent compo;
sleep(1);
std::cout << "Publishing an initial IU..." << std::endl;
compo.publish_hello_world();
std::cout << "*** Running main loop, press Ctrl-C to cancel... ***" << std::endl;
/// NOTE: custom main loop no longer required.
while (true) sleep(1);
}
/**
* `b64.h' - b64
*
* copyright (c) 2014 joseph werle
*/
/*
From https://github.com/littlstar/b64.c/blob/master/LICENSE :
The MIT License (MIT)
Copyright (c) 2014 Little Star Media, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef B64_H
#define B64_H 1
// RYT start
#include <string>
std::string base64_encode(const std::string& bin);
std::string base64_decode(const std::string& b64);
// RYT end
/**
* Memory allocation functions to use. You can define b64_malloc and
* b64_realloc to custom functions if you want.
*/
#ifndef b64_malloc
# define b64_malloc(ptr) malloc(ptr)
#endif
#ifndef b64_realloc
# define b64_realloc(ptr, size) realloc(ptr, size)
#endif
/**
* Base64 index table.
*/
static const char b64_table[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
};
#ifdef __cplusplus
extern "C" {
#endif
/**
* Encode `unsigned char *' source with `size_t' size.
* Returns a `char *' base64 encoded string.
*/
char *
b64_encode (const unsigned char *, size_t);
/**
* Dencode `char *' source with `size_t' size.
* Returns a `unsigned char *' base64 decoded string.
*/
unsigned char *
b64_decode (const char *, size_t);
/**
* Dencode `char *' source with `size_t' size.
* Returns a `unsigned char *' base64 decoded string + size of decoded string.
*/
unsigned char *
b64_decode_ex (const char *, size_t, size_t *);
#ifdef __cplusplus
}
#endif
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* This file is part of IPAACA, the
* "Incremental Processing Architecture
* for Artificial Conversational Agents".
*
* Copyright (c) 2009-2022 Social Cognitive Systems Group
* (formerly the Sociable Agents Group)
* CITEC, Bielefeld University
*
* http://opensource.cit-ec.de/projects/ipaaca/
* http://purl.org/net/ipaaca
*
* This file may be licensed under the terms of of the
* GNU Lesser General Public License Version 3 (the ``LGPL''),
* or (at your option) any later version.
*
* Software distributed under the License is distributed
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the LGPL for the specific language
* governing rights and limitations.
*
* You should have received a copy of the LGPL along with this
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
* or write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The development of this software was supported by the
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
* The Excellence Cluster EXC 277 is a grant of the Deutsche
* Forschungsgemeinschaft (DFG) in the context of the German
* Excellence Initiative.
*/
/**
* \file ipaaca-backend.h
*
* \brief Header file for abstract backend participant implementation
* (used in the core library and as a base to derive specific backends).
*
* Users should not include this file directly, but use ipaaca.h
*
* \b Note: This file is only included during compilation of ipaaca,
* for regular use, the full internal API is not exposed.
* Users generally need never touch the internal transport layer.
*
* \author Ramin Yaghoubzadeh Torky (ryaghoubzadeh@uni-bielefeld.de)
* \date December, 2018
*/
#ifndef __ipaaca_config_h_INCLUDED__
#define __ipaaca_config_h_INCLUDED__
#ifndef __ipaaca_h_INCLUDED__
#error "Please do not include this file directly, use ipaaca.h instead"
#endif
class Config {
public:
typedef std::shared_ptr<Config> ptr;
protected:
std::map<std::string, std::string> _data;
std::set<std::string> _messages_delivered;
template<typename T> T get_with_default_internal(const std::string& key, T const& default_value, bool warn);
template<typename T> void config_key_not_found(const std::string& key, T const& default_value, bool warn)
{
if (!_messages_delivered.count(key)) {
if (warn) { IPAACA_WARNING("Config: no key '" << key << "', using default value " << default_value) }
else { IPAACA_DEBUG("Config: no key '" << key << "', using default value " << default_value) }
_messages_delivered.insert(key);
}
}
template<typename T> void config_conversion_failed(const std::string& key, T const& default_value)
{
if (!_messages_delivered.count(key)) {
IPAACA_WARNING("Config: failed conversion for key '" << key << "', using default value " << default_value)
_messages_delivered.insert(key);
}
}
bool get_key_and_value(const std::string& line, std::string& key, std::string& value);
public:
inline std::map<std::string, std::string>::const_iterator data_cbegin() const { return _data.begin(); }
inline std::map<std::string, std::string>::const_iterator data_cend() const { return _data.end(); }
void populate_from_global_sources();
void populate_from_environment();
void populate_from_any_conf_files();
void populate_from_conf_file(std::fstream& fs);
template<typename T> T get_with_default(const std::string& key, T const& default_value) {
return get_with_default_internal(key, default_value, false);
}
template<typename T> T get_with_default_and_warning(const std::string& key, T const& default_value) {
return get_with_default_internal(key, default_value, true);
}
//inline std::map<std::string, std::string>::iterator begin() { return std::map<std::string, std::string>::begin(); }
//inline std::map<std::string, std::string>::iterator end() { return std::map<std::string, std::string>::end(); }
};
Config::ptr get_global_config(bool auto_parse_on_demand=true);
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Copyright (C) 2011 Milo Yip
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
--
This software and license copied in January 2015 from
https://github.com/miloyip/rapidjson/