Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
interface
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
homeostasis
interface
Commits
b9bbf763
Commit
b9bbf763
authored
10 years ago
by
Benoit Favre
Browse files
Options
Downloads
Patches
Plain Diff
improve slu synchronization
parent
d813dc2b
No related branches found
No related tags found
No related merge requests found
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
.options.txt
+2
-2
2 additions, 2 deletions
.options.txt
main.py
+21
-6
21 additions, 6 deletions
main.py
slu.py
+14
-2
14 additions, 2 deletions
slu.py
slu/homeostasis_25nov.action
+234
-0
234 additions, 0 deletions
slu/homeostasis_25nov.action
xmlview.py
+32
-14
32 additions, 14 deletions
xmlview.py
with
303 additions
and
24 deletions
.options.txt
+
2
−
2
View file @
b9bbf763
slu:
1
slu:
0
xml_filename: data/homeostasis_25nov.xml
osc_host: 127.0.0.1
osc_port: 1234
asr_model: asr/mika-fred-
2
.cfg
asr_model: asr/mika-fred-
1
.cfg
This diff is collapsed.
Click to expand it.
main.py
+
21
−
6
View file @
b9bbf763
...
...
@@ -60,7 +60,10 @@ class ScriptedASR(Gtk.Window):
found
=
re
.
search
(
'
section(\d+)\.fst$
'
,
section_fst
)
if
found
:
section_id
=
int
(
found
.
group
(
1
))
self
.
slu
[
section_id
-
1
]
=
slu
.
SLU
(
prefix
%
'
dico_word.txt
'
,
prefix
%
'
dico_action.txt
'
,
section_fst
,
prefix
%
'
clean_tail.fst
'
,
library
=
library
)
self
.
slu
[
section_id
-
1
]
=
slu
.
SLU
(
prefix
%
'
dico_word.txt
'
,
prefix
%
'
dico_action.txt
'
,
section_fst
,
prefix
%
'
clean_tail.fst
'
,
'
slu/homeostasis_25nov.action
'
,
library
=
library
)
if
slu_type
==
0
:
for
keyword
in
self
.
xmlview
.
keywords
:
keyword
.
add_listener
(
self
.
set_slu_history
)
import
alternate_slu
self
.
slu2
=
alternate_slu
.
SLU
(
xml_filename
)
...
...
@@ -124,7 +127,8 @@ class ScriptedASR(Gtk.Window):
self
.
xmlview
.
set_section
(
section_id
)
def
slu_finished
(
self
,
model
,
slu_output
):
slu_output
=
str
(
slu_output
)
#slu_output = str(slu_output)
#print slu_output
self
.
slu_actions
=
model
.
get_actions
().
split
()
self
.
slu_output
=
slu_output
print
'
SLU output:
"
%s
"
, actions:
"
%s
"'
%
(
self
.
slu_output
,
'
'
.
join
(
self
.
slu_actions
))
...
...
@@ -133,22 +137,22 @@ class ScriptedASR(Gtk.Window):
for
action_id
in
range
(
len
(
self
.
kept_actions
),
len
(
self
.
slu_actions
)):
print
'
NEW ACTION:
'
,
action_id
,
self
.
slu_actions
[
action_id
]
action
=
actions
.
parse_slu_action
(
self
.
slu_actions
[
action_id
])
print
action
.
text
if
action
.
text
.
startswith
(
'
#ENDSEQUENCE(
'
):
pass
elif
action
.
text
.
startswith
(
'
#ENDSECTION(
'
):
new_section
=
self
.
xmlview
.
get_section
()
+
1
self
.
confirmer
.
confirm
(
'
Go to section %d?
'
%
(
new_section
+
1
),
3
,
lambda
:
self
.
set_section
(
new_section
))
else
:
self
.
xmlview
.
highlight
(
action
)
actions
.
perform_action
(
action
,
False
)
self
.
kept_history
=
self
.
slu_output
self
.
kept_actions
=
self
.
slu_actions
def
hyp_changed
(
self
,
hyp
):
#hyp = ' '.join(hyp).replace('[noise]', ' ').split()
if
len
(
hyp
)
>
len
(
self
.
current_section_history
):
self
.
current_section_history
.
append
(
''
)
self
.
kept_history
=
self
.
slu_output
self
.
kept_actions
=
self
.
slu_actions
#
self.kept_history = self.slu_output
#
self.kept_actions = self.slu_actions
words
=
hyp
[
-
1
].
strip
().
replace
(
'
_
'
,
'
'
).
split
()
if
len
(
words
)
==
0
:
...
...
@@ -172,6 +176,17 @@ class ScriptedASR(Gtk.Window):
model
.
process
(
words
,
self
.
kept_history
,
self
.
slu_finished
,
False
)
self
.
current_section_history
[
-
1
]
=
'
'
.
join
(
words
)
def
set_slu_history
(
self
,
keyword
,
uri
,
num
):
for
keyword
in
self
.
xmlview
.
keywords
[:
num
+
1
]:
keyword
.
highlight
()
for
keyword
in
self
.
xmlview
.
keywords
[
num
+
1
:]:
keyword
.
highlight
(
False
)
self
.
kept_actions
=
[
x
.
action
for
x
in
self
.
xmlview
.
keywords
[:
num
+
1
]]
self
.
kept_history
=
self
.
slu
[
self
.
current_section
].
get_action_history
(
num
)
print
'
SLU set history: history=
"
%s
"
, actions=
"
%s
"'
%
(
self
.
kept_history
,
'
'
.
join
(
self
.
kept_actions
))
self
.
slu_output
=
''
self
.
slu_actions
=
[]
def
hyp_changed2
(
self
,
hyp
):
section_id
=
self
.
xmlview
.
get_section
()
if
self
.
slu2_last_section
!=
section_id
:
...
...
This diff is collapsed.
Click to expand it.
slu.py
+
14
−
2
View file @
b9bbf763
...
...
@@ -7,7 +7,7 @@ _semaphore = None
class
SLU
:
#/src.new/rocio_slu -word "$prefix"_dico_word.txt -action "$prefix"_dico_action.txt -fstmodel "$prefix".fst -fstclean "$prefix"_clean_tail.fst
def
__init__
(
self
,
word_lexicon
,
action_lexicon
,
model_fst
,
cleaner_fst
,
library
=
'
slu/src/librocio_slu.so
'
):
def
__init__
(
self
,
word_lexicon
,
action_lexicon
,
model_fst
,
cleaner_fst
,
action_history
,
library
=
'
slu/src/librocio_slu.so
'
):
global
_backend
,
_semaphore
if
_backend
==
None
:
_backend
=
cdll
.
LoadLibrary
(
library
)
...
...
@@ -45,11 +45,23 @@ class SLU:
_backend
.
free
.
restype
=
None
_semaphore
=
threading
.
Semaphore
()
self
.
load_action_history
(
action_history
)
_semaphore
.
acquire
()
thread
=
threading
.
Thread
(
target
=
self
.
_init_thread
,
args
=
[
word_lexicon
,
action_lexicon
,
model_fst
,
cleaner_fst
])
thread
.
daemon
=
True
thread
.
start
()
def
load_action_history
(
self
,
action_history
):
self
.
action_history
=
[]
with
open
(
action_history
)
as
fp
:
for
line
in
fp
:
action
,
history
=
line
.
strip
().
split
(
'
\t
'
)
if
not
(
'
#ENDSEQUENCE
'
in
action
or
'
#ENDSECTION
'
in
action
):
self
.
action_history
.
append
([
action
,
history
])
def
get_action_history
(
self
,
action_num
):
return
self
.
action_history
[
action_num
][
1
]
def
_init_thread
(
self
,
word_lexicon
,
action_lexicon
,
model_fst
,
cleaner_fst
):
global
_backend
,
_semaphore
self
.
slu
=
_backend
.
init_slu
(
word_lexicon
,
action_lexicon
,
model_fst
,
cleaner_fst
)
...
...
@@ -69,7 +81,7 @@ class SLU:
_semaphore
.
acquire
()
c_output
=
_backend
.
run_slu
(
self
.
slu
,
c_words
,
len
(
words
),
-
1
,
old_words
)
_semaphore
.
release
()
output
=
cast
(
c_output
,
c_char_p
).
value
output
=
str
(
cast
(
c_output
,
c_char_p
).
value
)
_backend
.
free
(
c_output
)
GLib
.
idle_add
(
callback
,
self
,
output
)
...
...
This diff is collapsed.
Click to expand it.
slu/homeostasis_25nov.action
0 → 100644
+
234
−
0
View file @
b9bbf763
This diff is collapsed.
Click to expand it.
xmlview.py
+
32
−
14
View file @
b9bbf763
...
...
@@ -86,13 +86,13 @@ class Line(Gtk.HBox):
self
.
elements
=
elements
self
.
get_style_context
().
add_class
(
'
text-line
'
)
def
highlight
(
self
,
active
=
True
,
scrollable
=
None
):
if
active
:
self
.
label
.
get_style_context
().
add_class
(
'
highlighted
'
)
else
:
self
.
label
.
get_style_context
().
remove_class
(
'
highlighted
'
)
if
scrollable
!=
None
:
animate
.
scroll_to
(
scrollable
,
self
)
#
def highlight(self, active=True, scrollable=None):
#
if active:
#
self.label.get_style_context().add_class('highlighted')
#
else:
#
self.label.get_style_context().remove_class('highlighted')
#
if scrollable != None:
#
animate.scroll_to(scrollable, self)
class
Keyword
(
Gtk
.
Label
):
def
__init__
(
self
,
text
,
action
,
lang
):
...
...
@@ -103,15 +103,29 @@ class Keyword(Gtk.Label):
self
.
set_markup
(
text
+
'
[<a href=
"
%s
"
>%s</a>]
'
%
(
action
,
action
))
self
.
get_style_context
().
add_class
(
'
keyword
'
)
self
.
connect
(
'
activate-link
'
,
self
.
link_clicked
)
self
.
listeners
=
[]
self
.
num
=
0
def
highlight
(
self
,
active
=
True
,
scrollable
=
None
):
if
active
:
self
.
get_style_context
().
remove_class
(
'
keyword
'
)
self
.
get_style_context
().
add_class
(
'
keyword-highlighted
'
)
if
scrollable
!=
None
:
animate
.
scroll_to
(
scrollable
,
self
)
else
:
self
.
get_style_context
().
add_class
(
'
keyword
'
)
self
.
get_style_context
().
remove_class
(
'
keyword-highlighted
'
)
def
add_listener
(
self
,
listener
):
self
.
listeners
.
append
(
listener
)
def
highlight
(
self
,
scrollable
=
None
):
self
.
get_style_context
().
remove_class
(
'
keyword
'
)
self
.
get_style_context
().
add_class
(
'
keyword-highlighted
'
)
if
scrollable
!=
None
:
animate
.
scroll_to
(
scrollable
,
self
)
def
set_num
(
self
,
num
):
self
.
num
=
num
def
link_clicked
(
self
,
widget
,
uri
):
actions
.
perform_action
(
actions
.
Action
(
uri
,
keyword
=
widget
),
False
)
for
listener
in
self
.
listeners
:
listener
(
self
,
uri
,
self
.
num
)
return
True
class
Text
(
Gtk
.
Label
):
...
...
@@ -144,6 +158,7 @@ class XmlView(Gtk.ScrolledWindow):
for
line
in
sequence
.
lines
:
for
element
in
line
.
elements
:
if
hasattr
(
element
,
'
action
'
):
element
.
set_num
(
len
(
self
.
keywords
))
self
.
keywords
.
append
(
element
)
self
.
last_highlighted
=
-
1
...
...
@@ -172,16 +187,19 @@ class XmlView(Gtk.ScrolledWindow):
def
section_clicked
(
self
,
current
):
self
.
set_section
(
int
(
current
.
name
)
-
1
)
for
keyword
in
self
.
keywords
:
keyword
.
highlight
(
False
)
def
highlight
(
self
,
action
):
if
hasattr
(
action
,
'
keyword
'
):
action
.
keyword
.
highlight
(
self
)
action
.
keyword
.
highlight
(
True
,
self
)
else
:
i
=
self
.
last_highlighted
+
1
while
i
<
len
(
self
.
keywords
):
if
self
.
keywords
[
i
].
action
==
action
.
text
:
self
.
keywords
[
i
].
highlight
(
self
)
self
.
keywords
[
i
].
highlight
(
True
,
self
)
self
.
last_highlighted
=
i
#print 'HIGHLIGHT:', action.text, self.last_highlighted
break
i
+=
1
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment