Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
ipaaca
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
Social Cognitive Systems
ipaaca
Compare revisions
7d902d8361cf5dc7d771c547c643f0b8802da3ca to master
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
scs/ipaaca
Select target project
No results found
master
Select Git revision
Swap
Target
ramin.yaghoubzadeh/ipaaca
Select target project
scs/ipaaca
ramin.yaghoubzadeh/ipaaca
2 results
7d902d8361cf5dc7d771c547c643f0b8802da3ca
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ipaacatools/scripts/ipaaca-session-record
+225
-0
225 additions, 0 deletions
ipaacatools/scripts/ipaaca-session-record
ipaacatools/scripts/ipaaca-session-replay
+157
-0
157 additions, 0 deletions
ipaacatools/scripts/ipaaca-session-replay
with
382 additions
and
0 deletions
ipaacatools/scripts/ipaaca-session-record
0 → 100755
View file @
460357ca
#!/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
+
'
[m
'
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
+=
'
\n
links=
'
+
pretty_printed_dict
(
iu
.
get_all_links
())
s
+=
'
\n
payload=
'
+
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
)
This diff is collapsed.
Click to expand it.
ipaacatools/scripts/ipaaca-session-replay
0 → 100755
View file @
460357ca
#!/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
)
This diff is collapsed.
Click to expand it.
Prev
1
…
4
5
6
7
8
Next