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
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# "Incremental Processing Architecture # "Incremental Processing Architecture
# for Artificial Conversational Agents". # for Artificial Conversational Agents".
# #
# Copyright (c) 2009-2013 Sociable Agents Group # Copyright (c) 2009-2022 Sociable Agents Group
# CITEC, Bielefeld University # CITEC, Bielefeld University
# #
# http://opensource.cit-ec.de/projects/ipaaca/ # http://opensource.cit-ec.de/projects/ipaaca/
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# "Incremental Processing Architecture # "Incremental Processing Architecture
# for Artificial Conversational Agents". # for Artificial Conversational Agents".
# #
# Copyright (c) 2009-2013 Sociable Agents Group # Copyright (c) 2009-2022 Sociable Agents Group
# CITEC, Bielefeld University # CITEC, Bielefeld University
# #
# http://opensource.cit-ec.de/projects/ipaaca/ # http://opensource.cit-ec.de/projects/ipaaca/
......
...@@ -5,7 +5,7 @@ project (ipaaca_soa_cpp) ...@@ -5,7 +5,7 @@ project (ipaaca_soa_cpp)
install( install(
DIRECTORY include DIRECTORY include
DESTINATION / DESTINATION .
FILES_MATCHING PATTERN "*.h" PATTERN "*.hh" PATTERN "*.hpp" PATTERN "*.inl" FILES_MATCHING PATTERN "*.h" PATTERN "*.hh" PATTERN "*.hpp" PATTERN "*.inl"
) )
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of IPAACA, the
# "Incremental Processing Architecture
# for Artificial Conversational Agents".
#
# Copyright (c) 2009-2015 Social Cognitive Systems 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.
from __future__ import division, print_function
import sys
import ipaaca
import traceback
import io
def pretty_printed_time(t):
if t<0:
t = -t
sign = '-'
else:
sign = ' '
s = float(t)
h = int(s/3600)
m = int(s/60) - h*60
s -= h*3600 + m*60
ms = int((s-int(s))*1000)
return sign+'%01d:%02d:%02d.%03d'%(h, m, int(s), ms)
REPLACEMENT_COLORS={
'30': 'black',
'31': 'red',
'32': 'green',
'33': 'cyan',
'34': 'blue',
'35': 'brown',
'36': 'magenta',
'37': 'grey',
'248': 'lightgray',
# should add more colors
}
def replace_ansi_html(s):
r = u''
in_esc = False
last_color = u''
#skip_one_double_wide_bar = False
for c in s:
if in_esc:
if c=='m':
in_esc = False
itms = last_color.replace('[','').replace(']','').split(';')
col = None
bold = False
if itms[0]=='':
r += '</code></font><code>'
else:
for i in itms:
if i=='1':
bold = True
elif i in REPLACEMENT_COLORS:
col = REPLACEMENT_COLORS[i]
if col is None:
if bold:
col = 'grey'
else:
col = 'black'
print('Warning: unknown colors '+str(itms))
r += '</code><font color="'+col+'"><code>'
else:
last_color += c
else:
#if c in u'▁▂▃▄▅▆▇█':
# if skip_one_double_wide_bar:
# skip_one_double_wide_bar = False
# else:
# r += c
# skip_one_double_wide_bar = True
#el
if c=='':
in_esc = True
last_color = ''
else:
r += c
return r
def print_header(formt, fields):
s = u''
if formt=='html':
s += '<html><head><meta charset="UTF-8"><title>flexdiam log view</title></head>\n<body>\n<table width="100%" border="1" bordercolor="lightgray" style="white-space:pre">\n<tr>'
for f in fields:
s+='<th>'+f+'</th>'
s += '</tr>'
return s
def print_footer(formt):
s = u''
if formt=='html':
s += '</tr>\n</body>\n</html>'
return s
def print_record(data, delimiter, formt):
if formt=='html':
s = u'<tr>'
for d in data:
d2 = d.replace('<', '&lt;').replace('>', '&gt;').replace('\n', '<br/>').replace('"', '&quot;')
d3 = replace_ansi_html(d2)
#s += u'<td><code>' + d2.replace('<', '&lt;').replace('>', '&gt;').replace('\n', '<br/>') + u'</code></td>'
s += u'<td><code>' + d3 + u'</code></td>'
s += u'</tr>'
return s
else:
return delimiter.join(data)
def modify(key, value, strip=False, pretty_printed_times=False, time_offset=0.0):
if key=='time':
f = float(value.strip()) - time_offset
return pretty_printed_time(f) if pretty_printed_times else str(f)
else:
return value.strip() if strip else value
if __name__=='__main__':
try:
iap = ipaaca.IpaacaArgumentParser('ipaaca-logcat')
iap.add_argument(
'-s', '--strip-fields',
dest='strip', action='store_true',
default=False,
help='Strip leading/trailing whitespace from all fields')
iap.add_argument(
'-p', '--pretty-printed-times',
dest='pretty_printed_times', action='store_true',
default=False,
help='Print human-readable times (hh:mm:ss.ms) instead of float seconds')
iap.add_argument(
'--format',
dest='format', nargs=1,
default=['plain'],
help='output format (plain, html) (default plain)')
iap.add_argument(
'-o', '--output-file',
dest='output_file', nargs=1,
default=['-'],
help='output file name (default \'-\' -> standard terminal output)')
iap.add_argument(
'-d', '--delimiter',
dest='delimiter', nargs=1,
default=['\t'],
help='field delimiter, interpreted as python unicode string (default \'\\t\')')
iap.add_argument(
'-t', '--align-times',
dest='align_times', nargs=2,
default=['0', '0'],
help='Calculate relative output timestamps (default: 0 0 => keep)\nFirst argument is a reference event timestamp from the log file\nSecond argument is the new output time for that same event')
iap.add_argument(
'-f', '--fields',
dest='fields', default=['time', 'text'], nargs='+',
help='fields to print (defaults: \'time\' \'text\')')
arguments = iap.parse_args()
delimiter = eval("u'"+arguments.delimiter[0]+"'", {"__builtins__":None}, {} )
ref_t, out_t = float(arguments.align_times[0]), float(arguments.align_times[1])
time_offset = ref_t - out_t
#print(arguments); sys.exit(1)
#modify = (lambda s: s.strip()) if arguments.strip else (lambda s: s)
#modify = lambda s: type(s).__name__
fil = sys.stdout
if arguments.output_file[0] != '-':
fil = io.open(arguments.output_file[0], 'w', encoding='utf8')
fil.write(print_header(arguments.format[0], arguments.fields)+'\n')
for line in sys.stdin:
record = eval(line.strip(), {"__builtins__":None}, {} )
data = [modify(f, unicode(record[f]), arguments.strip, arguments.pretty_printed_times, time_offset) for f in arguments.fields]
u = print_record(data, delimiter, arguments.format[0])
res = u'{}'.format(u) #.decode('utf-8')
fil.write(u''+res+'\n' )
fil.write(print_footer(arguments.format[0])+'\n')
if fil != sys.stdout: fil.close()
except (KeyboardInterrupt, SystemExit):
pass # ret below
except Exception, e:
print(u'Exception: '+unicode(traceback.format_exc()))
ipaaca.exit(1)
ipaaca.exit(0)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of IPAACA, the
# "Incremental Processing Architecture
# for Artificial Conversational Agents".
#
# Copyright (c) 2009-2015 Social Cognitive Systems 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.
#from __future__ import division, print_function
import itertools
import os
import platform
import sys
import time
import ipaaca
def iu_update_handler(iu, event_type, local):
try:
print(event_type + ': ' + str(iu))
except:
print(u"An error occurred printing an IU for an event of type "+event_type)
parser = ipaaca.IpaacaArgumentParser(description='Ipaaca IU Injector -- Sent ipaaca messages or IUs from the command line')
parser.add_argument(
'-t', '--type',
default='Message',
dest='iu_type',
choices = ['Message', 'IU'],
help="choose IU type to be send (default: 'Message')")
parser.add_argument(
'-k', '--keep-alive',
default=3.0,
dest='keep_alive',
metavar='SECONDS',
type=float,
help='set time in seconds to wait for potential IU updates (default: 3.0)')
parser.add_argument(
'-j', '--json-payload',
dest='json_payload',
action='store_true',
help='allow structured data to be sent (treats payload VALUE arguments as Python expressions)')
parser.add_argument(
'-c', '--category',
dest='category',
metavar='CATEGORY',
required=True,
help='set Message/IU category')
parser.add_argument(
'-p', '--payload',
default=[],
dest='payload',
metavar='KEY VALUE',
nargs='+',
help='set Message/IU payload ')
if __name__ == '__main__':
arguments = parser.parse_args()
print('BackEnd is '+str(ipaaca.backend.get_default_backend().name))
ob = ipaaca.OutputBuffer('IpaacaIUInjector')
ob.register_handler(iu_update_handler)
iu = ipaaca.Message(arguments.category) if arguments.iu_type == 'Message' else ipaaca.IU(arguments.category)
if arguments.json_payload:
# Treat payload values as Python expressions
iu.payload = {k: eval(v) for (k, v) in itertools.zip_longest(arguments.payload[::2], arguments.payload[1::2])}
else:
iu.payload = {k: v for (k, v) in itertools.zip_longest(arguments.payload[::2], arguments.payload[1::2])}
ob.add(iu)
print(
u'Sent {iu_type} with category "{category}" and payload {{'.format(**vars(arguments)),
end='\n' if len(iu.payload) > 0 else '')
for k, v in iu.payload.items():
print(u" '{key}': {value},".format(key=k, value=v))
print(u'}.')
# Wait for updates to the IU
try:
if arguments.iu_type == 'IU':
print('Waiting %s s for the IU to be updated.' % arguments.keep_alive)
time.sleep(arguments.keep_alive)
else:
time.sleep(0.1)
except KeyboardInterrupt:
pass
except Exception as e:
print(u'Exception: '+str(traceback.format_exc()))
ipaaca.exit(1)
ipaaca.exit(0)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of IPAACA, the
# "Incremental Processing Architecture
# for Artificial Conversational Agents".
#
# Copyright (c) 2009-2015 Social Cognitive Systems 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.
#from __future__ import division, print_function
import logging
import os
import platform
import re
import sys
import time
import ipaaca
def event_type_color(typ):
colors = {
'ADDED': '32;1',
'RETRACTED': '31;1',
'UPDATED': '33;1',
'MESSAGE': '34;1',
'COMMITTED': '35;1',
'LINKSUPDATED': '36;1',
'RETRACTED': '37',
}
return colors.get(typ, '1')
def highlight_if_color(s, c='1'):
return s if arguments.color else '[' + c + 'm' + s +''
def pretty_printed_dict(d):
s='{\n'
for k, v in d.items():
if isinstance(v, str) or isinstance(v, str):
v = "'"+str(v)+"'"
else:
v = str(v)
v2 = v if len(v) <= arguments.max_size else v[:arguments.max_size] + '<excess length omitted>'
v2.replace('\\','\\\\').replace('\n', highlight_if_color('\\n'))
s += "\t '%s': %s,\n" % (highlight_if_color(str(k),'1'), str(v2))
s+='}'
return s
def pretty_printed_iu_event(iu, event_type, local):
s = ''
t = time.time()
lt = time.localtime(t)
s += highlight_if_color('%.3f' % t, '1')
s += ' %02d:%02d:%02d' % (lt.tm_hour, lt.tm_min, lt.tm_sec)
s += ' ' + highlight_if_color('%-9s' % event_type, event_type_color(event_type))
s += ' category=' + highlight_if_color(iu.category,event_type_color(event_type))
s += ' channel=' + iu.buffer._channel
s += ' uid=' + iu.uid
s += ' owner=' + iu.owner_name
if event_type is not 'MESSAGE':
s += '\nlinks=' + pretty_printed_dict(iu.get_all_links())
s += '\npayload=' + pretty_printed_dict(iu.payload)
return s
def iu_event_handler(iu, event_type, local):
if arguments.regex:
for cat in arguments.categories: # actually now regexs, not categories
if re.match(cat, iu.category):
break
else:
return
print(pretty_printed_iu_event(iu, event_type, local), end='\n\n')
def exit(code):
ipaaca.exit(code)
#if platform.system() == 'Windows':
# os._exit(code)
#else:
# sys.exit(code)
parser = ipaaca.IpaacaArgumentParser(description='Ipaaca IU Sniffer -- Selectively listen to IPAACA traffic')
parser.add_argument(
'--channels',
dest='channels',
default=['default'],
metavar='CHANNEL',
nargs='+',
help="set the channels to listen on (otherwise 'default')")
parser.add_argument(
'-c', '--categories',
default=[''],
dest='categories',
metavar='CATEGORY',
nargs='+',
help='set categories (or regex patterns) to be matched')
parser.add_argument(
'-e', '--event-types',
default=None,
dest='event_types',
metavar='EVENT-TYPE',
nargs='+',
help='set event types ({})'.format(' '.join(ipaaca.iu.IUEventType._choices)))
parser.add_argument(
'-r', '--regex',
action='store_true',
dest='regex',
help='match categories by regular expressions')
parser.add_argument(
'--no-color',
action='store_true',
dest='color',
help='do not colorize output')
parser.add_argument(
'--size-limit',
default=2048,
dest='max_size',
metavar='LIMIT',
type=int,
help='limit payload display chars (default: 2048)')
if __name__ == '__main__':
arguments = parser.parse_args()
buffers = {}
backend_name = str(ipaaca.backend.get_default_backend().name)
print('BackEnd is '+backend_name)
universal_listener_category = ''
if backend_name == 'mqtt':
universal_listener_category = '#'
if arguments.categories == ['']: arguments.categories = ['#']
elif backend_name == 'ros':
if arguments.categories == [''] or arguments.regex:
print('ATTENTION: listening to all categories not implemented for ROS back-end!')
print(' (By extension, the same goes for filtering all categories by regex.)')
print(' !! You will receive nothing, please provide fixed category names. !!')
# Create one input buffer for each channel we are listening on
for channel in arguments.channels:
buffers[channel] = ipaaca.InputBuffer(
'IpaacaIUSniffer',
category_interests=arguments.categories if not arguments.regex else [universal_listener_category],
channel=channel,
resend_active=True)
# Check whether the specified event_types are valid
if arguments.event_types is not None:
for et in arguments.event_types:
if et.upper() not in ipaaca.iu.IUEventType._choices:
print('ERROR: "{et}" is not a valid IPAACA event type.'.format(et=et.upper()))
exit(code=1)
buffers[channel].register_handler(
iu_event_handler,
for_event_types=[et.upper() for et in arguments.event_types] if arguments.event_types is not None else None)
# Tell user what we are doing
print('ipaaca-iu-sniffer listening')
print(' * on channel(s): ' + ', '.join(arguments.channels))
print(' * for event type(s): ', end='')
if arguments.event_types is None:
print('any')
else:
print(', '.join([highlight_if_color(et.upper(), event_type_color(et.upper())) for et in arguments.event_types]))
print(' * for category/ies', end='')
if arguments.categories == [universal_listener_category]:
print(': any')
else:
if arguments.regex:
print(' that match the regex', end='')
print(': ' + ', '.join(arguments.categories))
# Wait for the user to kill the sniffer
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
except Exception as e:
print(u'Exception: '+str(traceback.format_exc()))
ipaaca.exit(1)
ipaaca.exit(0)
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of IPAACA, the # This file is part of IPAACA, the
# "Incremental Processing Architecture # "Incremental Processing Architecture
# for Artificial Conversational Agents". # for Artificial Conversational Agents".
# #
# Copyright (c) 2009-2013 Sociable Agents Group # Copyright (c) 2009-2015 Social Cognitive Systems Group
# CITEC, Bielefeld University # CITEC, Bielefeld University
# #
# http://opensource.cit-ec.de/projects/ipaaca/ # http://opensource.cit-ec.de/projects/ipaaca/
# http://purl.org/net/ipaaca # http://purl.org/net/ipaaca
...@@ -22,7 +23,7 @@ ...@@ -22,7 +23,7 @@
# You should have received a copy of the LGPL along with this # You should have received a copy of the LGPL along with this
# program. If not, go to http://www.gnu.org/licenses/lgpl.html # program. If not, go to http://www.gnu.org/licenses/lgpl.html
# or write to the Free Software Foundation, Inc., # or write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# #
# The development of this software was supported by the # The development of this software was supported by the
# Excellence Cluster EXC 277 Cognitive Interaction Technology. # Excellence Cluster EXC 277 Cognitive Interaction Technology.
...@@ -30,61 +31,47 @@ ...@@ -30,61 +31,47 @@
# Forschungsgemeinschaft (DFG) in the context of the German # Forschungsgemeinschaft (DFG) in the context of the German
# Excellence Initiative. # Excellence Initiative.
import logging from __future__ import division, print_function
import sys import sys
import time import time
import ipaaca import ipaaca
import ipaaca.util.logger as ipaacalog
def my_update_handler(iu, event_type, local):
print(event_type+': '+str(iu))
if len(sys.argv)<2:
print "Please use the program as follows:"
print " "+sys.argv[0]+" [--class IU|Message] [--timeout <sec>] <categoryname> [<payloadkey> <payloadvalue>] [<k2> <v2>] ..."
sys.exit(1)
iu_class = 'Message'
timeout = 3.0
idx = 1
keep_going = True
while keep_going:
keep_going = False
if sys.argv[idx]=='--class':
t = sys.argv[idx+1]
if t in ['Message', 'IU']:
iu_class = t
else:
print "Unknown IU class: "+t
sys.exit(1)
idx += 2
keep_going = True
elif sys.argv[idx]=='--timeout':
timeout = float(sys.argv[idx+1])
idx += 2
keep_going = True
cate = sys.argv[idx]
idx += 1
pl={}
while len(sys.argv)>idx+1:
pl[sys.argv[idx]] = sys.argv[idx+1]
idx+=2
print "Sending "+iu_class+" of category "+cate def main(log_mode, filename=None):
print " with payload "+str(pl) ipaacalog.logger_send_ipaaca_logs(False)
il = ipaacalog.LoggerComponent(filename, log_mode)
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
il.close_logfile()
print('Logging-Component closed by keyboard interrupt.')
ob = ipaaca.OutputBuffer('IUInjector')
ob.register_handler(my_update_handler)
iu_top = ipaaca.IU(cate)
iu_top.payload = pl
ob.add(iu_top)
print iu_class+" sent."
if iu_class=="IU": if __name__ == '__main__':
print "Waiting "+str(timeout)+" sec for remote modifications..." import traceback
time.sleep(timeout) try:
else: iap = ipaaca.IpaacaArgumentParser(
time.sleep(0.1) 'ipaaca-logger')
print "done." iap.add_argument(
'-m', '--log-mode', dest='log_mode',
choices=ipaacalog.LOG_MODES,
default='append',
help="set what to do when logfile exists "
"(default: 'append'; 'timestamp' adds timestamp in any case)")
iap.add_argument(
'filename', nargs='?',
metavar='FILE',
help='set name of logfile')
arguments = iap.parse_args()
main(arguments.log_mode, arguments.filename)
except KeyboardInterrupt:
pass
except Exception, e:
print(u'Exception: '+unicode(traceback.format_exc()))
ipaaca.exit(1)
ipaaca.exit(0)
#!/usr/bin/env python
import ipaaca
import time
class PingSender(object):
def __init__(self):
self.pings = []
self.times = []
self.ob = ipaaca.OutputBuffer('IpaacaPing')
self.ob.register_handler(self.iu_event_handler)
def iu_event_handler(self, iu, event_type, local):
recv_t = time.time()
if event_type=='UPDATED':
print('OK')
send_t = float(iu.payload['sender_local_t'])
receiver_recv_t = float(iu.payload['receiver_local_t'])
round_trip_t = recv_t - send_t
locally_estimated_receiver_recv_t = (recv_t + send_t) / 2
estimated_clock_skew = receiver_recv_t - locally_estimated_receiver_recv_t
self.times.append(estimated_clock_skew)
average_clock_difference = sum(self.times) / len(self.times)
self.pings.append(500.0 * round_trip_t)
average_estimated_single_trip = sum(self.pings) / len(self.pings)
print('Received ping reply')
print(' measured round trip time [ms]: %0.3f'%(1000.0 * round_trip_t))
print(' estimated single trip [ms]: %0.3f'%(500.0 * round_trip_t))
print(' averaged single trip [ms]: %0.3f'%(average_estimated_single_trip))
print(' estimated system clock difference [s]: %0.3f'%(average_clock_difference))
def send_ping(self):
t = time.time()
iu = ipaaca.IU('ipaacaPing')
iu.payload['sender_local_t'] = t
self.ob.add(iu)
iap = ipaaca.IpaacaArgumentParser('ipaaca-ping')
arguments = iap.parse_args()
ps = PingSender()
while True:
ps.send_ping()
time.sleep(1)
#!/usr/bin/env python
import ipaaca
import time
def iu_event_handler(iu, event_type, local):
if event_type=='ADDED':
iu.payload['receiver_local_t'] = time.time()
print('Sent IPAACA ping reply')
iap = ipaaca.IpaacaArgumentParser('ipaaca-pong')
arguments = iap.parse_args()
ib = ipaaca.InputBuffer('IpaacaPong', ['ipaacaPing'])
ib.register_handler(iu_event_handler)
while True:
time.sleep(1)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of IPAACA, the
# "Incremental Processing Architecture
# for Artificial Conversational Agents".
#
# Copyright (c) 2009-2015 Social Cognitive Systems 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.
from __future__ import division, print_function
import logging
import os
import platform
import re
import sys
import time
import ipaaca
def event_type_color(typ):
colors = {
'ADDED': '32;1',
'RETRACTED': '31;1',
'UPDATED': '33;1',
'MESSAGE': '34;1',
'COMMITTED': '35;1',
'LINKSUPDATED': '36;1',
'RETRACTED': '37;1',
}
return colors.get(typ, '1')
def highlight_if_color(s, c='1'):
return s if arguments.color else '[' + c + 'm' + s +''
def pretty_printed_dict(d):
s='{\n'
for k, v in d.items():
if isinstance(v, unicode) or isinstance(v, str):
v = "'"+unicode(v)+"'"
else:
v = unicode(v)
v2 = v if len(v) <= arguments.max_size else v[:arguments.max_size] + '<excess length omitted>'
v2.replace('\\','\\\\').replace('\n', highlight_if_color('\\n'))
s += "\t '%s': %s,\n" % (highlight_if_color(unicode(k),'1'), unicode(v2))
s+='}'
return s
def pretty_printed_iu_event(iu, event_type, local):
s = ''
t = time.time()
lt = time.localtime(t)
s += highlight_if_color('%.3f' % t, '1')
s += ' %02d:%02d:%02d' % (lt.tm_hour, lt.tm_min, lt.tm_sec)
s += ' ' + highlight_if_color('%-9s' % event_type, event_type_color(event_type))
s += ' category=' + highlight_if_color(iu.category,event_type_color(event_type))
s += ' channel=' + iu.buffer._channel
s += ' uid=' + iu.uid
s += ' owner=' + iu.owner_name
if event_type is not 'MESSAGE':
s += '\nlinks=' + pretty_printed_dict(iu.get_all_links())
s += '\npayload=' + pretty_printed_dict(iu.payload)
return s
def machine_formatted_iu_event(iu, event_type, local):
return repr({
'time': time.time(),
'uid': iu.uid,
'category': iu.category,
'type': event_type,
'payload': iu.payload,
#'links': iu.links,
}).encode('utf-8')
def iu_event_recorder_handler(logfile, iu, event_type, local):
if arguments.regex:
for cat in arguments.categories: # actually now regexs, not categories
if re.match(cat, iu.category):
break
else:
return
if logfile is None:
# requested log to stdout, only printing the structured data
print(machine_formatted_iu_event(iu, event_type, local)+'\n')
else:
# write structured data to log file
logfile.write(machine_formatted_iu_event(iu, event_type, local)+'\n')
# duplicate human-readable on terminal (unless data being sent there)
print(pretty_printed_iu_event(iu, event_type, local), end='\n\n')
def exit(code):
ipaaca.exit(code)
#if platform.system() == 'Windows':
# os._exit(code)
#else:
# sys.exit(code)
parser = ipaaca.IpaacaArgumentParser(description='Ipaaca IU Session Recorder -- Selectively record [and print] IU streams')
parser.add_argument(
'-o', '--output-file',
dest='output_file',
default=['default.ipaacasession'],
metavar='OUTPUT-FILE',
nargs=1,
help="set the channels to listen on (otherwise 'default')")
parser.add_argument(
'--channels',
dest='channels',
default=['default'],
metavar='CHANNEL',
nargs='+',
help="set the channels to listen on (otherwise 'default')")
parser.add_argument(
'-c', '--categories',
default=[''],
dest='categories',
metavar='CATEGORY',
nargs='+',
help='set categories (or regex patterns) to be matched')
parser.add_argument(
'-e', '--event-types',
default=None,
dest='event_types',
metavar='EVENT-TYPE',
nargs='+',
help='set event types ({})'.format(' '.join(ipaaca.iu.IUEventType._choices)))
parser.add_argument(
'-r', '--regex',
action='store_true',
dest='regex',
help='match categories by regular expressions')
parser.add_argument(
'--no-color',
action='store_true',
dest='color',
help='do not colorize output')
parser.add_argument(
'--size-limit',
default=2048,
dest='max_size',
metavar='LIMIT',
type=int,
help='limit payload display chars (default: 2048)')
if __name__ == '__main__':
arguments = parser.parse_args()
buffers = {}
log_file = None if (arguments.output_file[0]=='-') else open(arguments.output_file[0], 'w')
# Create one input buffer for each channel we are listening on
for channel in arguments.channels:
buffers[channel] = ipaaca.InputBuffer(
'IpaacaIUSniffer',
category_interests=arguments.categories if not arguments.regex else [''],
channel=channel,
resend_active=True)
# Check whether the specified event_types are valid
if arguments.event_types is not None:
for et in arguments.event_types:
if et.upper() not in ipaaca.iu.IUEventType._choices:
print('ERROR: "{et}" is not a valid IPAACA event type.'.format(et=et.upper()))
exit(code=1)
buffers[channel].register_handler(
lambda iu,typ,loc: iu_event_recorder_handler(log_file, iu, typ, loc),
for_event_types=[et.upper() for et in arguments.event_types] if arguments.event_types is not None else None)
# Tell user what we are doing
print('ipaaca-session-record listening')
print(' * writing to file: '+('(stdout)' if log_file is None else arguments.output_file[0]))
print(' * on channel(s): ' + ', '.join(arguments.channels))
print(' * for event type(s): ', end='')
if arguments.event_types is None:
print('any')
else:
print(', '.join([highlight_if_color(et.upper(), event_type_color(et.upper())) for et in arguments.event_types]))
print(' * for category/ies', end='')
if arguments.categories == ['']:
print(': any')
else:
if arguments.regex:
print(' that match the regex', end='')
print(': ' + ', '.join(arguments.categories))
# Wait for the user to kill the sniffer
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
except Exception, e:
print(u'Exception: '+unicode(traceback.format_exc()))
if log_file is not None:
log_file.close()
ipaaca.exit(1)
if log_file is not None:
log_file.close()
ipaaca.exit(0)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of IPAACA, the
# "Incremental Processing Architecture
# for Artificial Conversational Agents".
#
# Copyright (c) 2009-2015 Social Cognitive Systems 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.
from __future__ import division, print_function
import itertools
import os
import platform
import sys
import time
import traceback
import ipaaca
def iu_update_handler(iu, event_type, local):
try:
print(event_type + ': ' + unicode(iu))
except:
print(u"An error occurred printing an IU for an event of type "+event_type)
parser = ipaaca.IpaacaArgumentParser(description='Ipaaca Session Replay -- Replay IU event logs from the command line')
parser.add_argument(
'-i', '--input-file',
default=['default.ipaacasession'],
dest='input_file',
metavar='INPUT-FILE',
nargs=1,
help='file from which to read IU data for replay')
parser.add_argument(
'-k', '--keep-alive',
default=1.0,
dest='keep_alive',
metavar='SECONDS',
type=float,
help='set time in seconds to wait for final remote IU updates (default: 1.0)')
parser.add_argument(
'-c', '--categories',
dest='categories',
metavar='CATEGORIES',
required=False,
default=[],
nargs='*',
help='send events for these categories only')
if __name__ == '__main__':
arguments = parser.parse_args()
for_categories = list(arguments.categories)
ob = ipaaca.OutputBuffer('IpaacaSessionReplay')
# CAUTION: special semantics for replay script: do NOT auto-retract at shutdown
# (should only replicate observed retractions form the data file!)
ob._teardown = lambda: True
ob.register_handler(iu_update_handler)
known_ius = {}
log_file = sys.stdin if (arguments.input_file[0]=='-') else open(arguments.input_file[0], 'r')
ref_time = None
last_time = None
for line in log_file:
record = eval(line, {'__builtins__': None}, {})
# event data
uid = record['uid']
category = record['category']
typ = record['type']
payload = record['payload']
# consider only if category filter passes
if len(for_categories)==0 or category in for_categories:
# take ref time from first event
if ref_time is None:
ref_time = record['time']
last_time = ref_time
# recreate delay from previous event
print('Sleep for '+str(record['time'] - last_time)+' s')
time.sleep(record['time'] - last_time)
last_time = record['time']
# do it
print('Synthesize event '+typ+' for IU UID '+uid+', category "'+category+'"')
if typ=='MESSAGE':
msg = ipaaca.Message(category)
msg.payload = payload
ob.add(msg)
elif typ=='ADDED':
if uid in known_ius:
print('ERROR - already added UID '+uid+' before!')
else:
iu = ipaaca.IU(category)
iu.payload = payload
ob.add(iu)
known_ius[uid] = iu
elif typ=='UPDATED':
if uid not in known_ius:
print('ERROR - have not received IU with UID '+uid+' before!')
else:
iu = known_ius[uid]
iu.payload = payload
elif typ=='COMMITTED':
if uid not in known_ius:
print('ERROR - have not received IU with UID '+uid+' before!')
else:
iu = known_ius[uid]
iu.commit()
elif typ=='RETRACTED':
if uid not in known_ius:
print('ERROR - have not received IU with UID '+uid+' before!')
else:
iu = known_ius[uid]
ob.remove(iu)
try:
print('Waiting; specified grace time '+str(arguments.keep_alive)+' s')
time.sleep(arguments.keep_alive)
except KeyboardInterrupt:
pass
except Exception, e:
print(u'Exception: '+unicode(traceback.format_exc()))
if log_file is not sys.stdin:
log_file.close()
ipaaca.exit(1)
if log_file is not sys.stdin:
log_file.close()
ipaaca.exit(0)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of IPAACA, the
# "Incremental Processing Architecture
# for Artificial Conversational Agents".
#
# Copyright (c) 2009-2016 Social Cognitive Systems 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.
from __future__ import division, print_function
import os
import platform
import sys
import time
import traceback
import ipaaca
def exit(code):
ipaaca.exit(code)
#if platform.system() == 'Windows':
# os._exit(code)
#else:
# sys.exit(code)
parser = ipaaca.IpaacaArgumentParser(description='Ipaaca Maintainor')
if __name__ == '__main__':
arguments = parser.parse_args()
# Warn if user tries to configure a transport other than socket or a
# server mode other than server
if (ipaaca.defaults.IPAACA_DEFAULT_RSB_TRANSPORT is not None and
ipaaca.defaults.IPAACA_DEFAULT_RSB_TRANSPORT != 'socket'):
print("ERROR: Works only with RSB transport type 'socket'.")
ipaaca.exit(1)
if (ipaaca.defaults.IPAACA_DEFAULT_RSB_SOCKET_SERVER is not None and
ipaaca.defaults.IPAACA_DEFAULT_RSB_SOCKET_SERVER != '1'):
print("ERROR: Works only in socket server mode '0'.")
ipaaca.exit(1)
# Configure rsb socket transport
ipaaca.defaults.IPAACA_DEFAULT_RSB_TRANSPORT = 'socket'
ipaaca.defaults.IPAACA_DEFAULT_RSB_SOCKET_SERVER = '1'
ob = ipaaca.OutputBuffer("IPAACAMaintainor")
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
decision = raw_input('Shutdown the IPAACA socket transport hub (y/[n])?')
if decision in 'yY':
break
except Exception, e:
print(u'Exception: '+unicode(traceback.format_exc()))
ipaaca.exit(1)
ipaaca.exit(0)