Skip to content
Snippets Groups Projects
Commit 8ba27038 authored by Benoit Favre's avatar Benoit Favre
Browse files

update slu and fix missing actions

parent 781145dc
No related branches found
No related tags found
No related merge requests found
......@@ -2,15 +2,16 @@
<joker> 1
change_section(1,"example1","go_to_section_one") 2
change_section(0,"example2","exit_section") 3
action(1,1,0,"example1","futures") 4
action(1,1,1,"example2","hidden_in_details") 5
action(1,1,2,"him","the_architect") 6
action(1,1,3,"action3","tossed_over") 7
action(1,1,4,"#ENDSEQUENCE(1)","") 8
action(1,1,4,"#ENDSECTION(1)","") 9
change_section(0,"close","") 10
change_section(0,"example2","") 4
action(1,1,0,"example1","futures") 5
action(1,1,1,"example2","hidden_in_details") 6
action(1,1,2,"him","the_architect") 7
action(1,1,3,"action3","tossed_over") 8
action(1,1,4,"#ENDSEQUENCE(1)","") 9
action(1,1,4,"#ENDSECTION(1)","") 10
change_section(2,"example3","open_section_two") 11
change_section(0,"example4","exit_section") 12
action(2,1,4,"action4","life") 13
action(2,1,5,"#ENDSEQUENCE(1)","") 14
action(2,1,6,"#ENDSECTION(2)","") 15
change_section(0,"example4","") 13
action(2,1,4,"action4","life") 14
action(2,1,5,"#ENDSEQUENCE(1)","") 15
action(2,1,6,"#ENDSECTION(2)","") 16
No preview for this file type
0 1 futures 4 0
0 1 futures 5 0
1 100
0 1 <joker> 4 100
1 2 hidden 5 0
0 1 <joker> 5 100
1 2 hidden 6 0
2 3 in 0 0
2 3 <epsilon> 0 10
3 4 details 0 0
4 100
1 4 <joker> 5 100
4 5 the 6 0
1 4 <joker> 6 100
4 5 the 7 0
5 6 architect 0 0
6 100
4 6 <joker> 6 100
6 7 tossed 7 0
4 6 <joker> 7 100
6 7 tossed 8 0
7 8 over 0 0
8 100
6 8 <joker> 7 100
8 9 <epsilon> 8 0
6 8 <joker> 8 100
8 9 <epsilon> 9 0
9 100
9 10 <epsilon> 9 0
10 11 <epsilon> 10 0
9 10 <epsilon> 10 0
10 11 <epsilon> 4 0
11
No preview for this file type
0 1 <epsilon> 9 0
1 2 life 13 0
0 1 <epsilon> 10 0
1 2 life 14 0
2 100
1 2 <joker> 13 100
2 3 <epsilon> 14 0
1 2 <joker> 14 100
2 3 <epsilon> 15 0
3 100
3 4 <epsilon> 15 0
4 5 <epsilon> 10 0
3 4 <epsilon> 16 0
4 5 <epsilon> 13 0
5
No preview for this file type
......@@ -91,10 +91,12 @@ char *get_field(char *ch, char *attribut, char *chfield)
{
int i,j;
chfield[0]='\0';
for(i=0;(ch[i])&&((ch[i]!=' ')||(strncmp(ch+i+1,attribut,strlen(attribut)))||(ch[i+1+strlen(attribut)]!='='));i++);
for(i=0;(ch[i])&&((ch[i]!=' ')||(strncmp(ch+i+1,attribut,strlen(attribut)))||((ch[i+1+strlen(attribut)]!='=')&&(ch[i+1+strlen(attribut)]!=' ')));i++);
if (ch[i])
{
for(j=0,i=i+1+strlen(attribut)+2;(ch[i])&&(ch[i]!='"');i++,j++) chfield[j]=ch[i];
for(i+=1+strlen(attribut);(ch[i])&&(ch[i]!='=');i++); if (!ch[i]) ERREUR("bad format in :",ch);
for(++i;(ch[i])&&(ch[i]!='"');i++); if (!ch[i]) ERREUR("bad format in :",ch);
for(j=0,i++;(ch[i])&&(ch[i]!='"');i++,j++) chfield[j]=ch[i];
if (ch[i]!='"') ERREUR("bad format1:",ch);
chfield[j]='\0';
}
......@@ -128,7 +130,8 @@ for(i=0;ch[i];i++) if (ch[i]==' ') ch[i]='_';
int main(int argc, char **argv)
{
int nbsection,i,j,k,nb,ordre,repetition,nbseq,actionsection,actionsequence,currentstate,statedebseq,action,findend,t_end[MAX_END_STATE],nbend,idac,actionfinsection,currentstatevoid;
int nbsection,i,j,k,nb,ordre,repetition,nbseq,actionsection,actionsequence,currentstate,statedebseq,action,findend,t_end[MAX_END_STATE],nbend,idac,
actionfinsection,actionfinsectionimplicit,currentstatevoid;
FILE *file,*filevoid,*fileexit;
char *pt,ch[TailleLigne],*t_field[MAX_FIELD],*chprefix,chname[TailleLigne],chfield[TailleLigne],chcontent[TailleLigne],ch2[TailleLigne];
......@@ -156,7 +159,7 @@ if (!(filevoid=fopen(ch,"wt"))) ERREUR("can't write in:",ch);
fprintf(filevoid,"0\n");
currentstatevoid=0;
ordre=STRICT; repetition=False; file=NULL; actionsection=0; findend=False; nbend=0; nbseq=0; actionfinsection=0;
ordre=STRICT; repetition=False; file=NULL; actionsection=0; findend=False; nbend=0; nbseq=0; actionfinsection=actionfinsectionimplicit=0;
for(idac=nbsection=0;fgets(ch,TailleLigne,stdin);)
{
if (strstr(ch,"<section"))
......@@ -172,11 +175,10 @@ for(idac=nbsection=0;fgets(ch,TailleLigne,stdin);)
{
sprintf(chcontent,"action(%d,%d,%d,\"#ENDSEQUENCE(%d)\",\"\")",nbsection,nbseq,idac,nbseq); actionsequence=from_action_to_index(chcontent);
sprintf(chcontent,"action(%d,%d,%d,\"#ENDSECTION(%d)\",\"\")",nbsection,nbseq,idac,nbsection); actionsection=from_action_to_index(chcontent);
sprintf(chcontent,"change_section(0,\"close\",\"\")"); actionfinsection=from_action_to_index(chcontent);
for(i=0;i<nbend;i++) fprintf(file,"%d\t%d\t<epsilon>\t%d\t0\n",t_end[i],currentstate+1,actionsequence);
fprintf(file,"%d\t%d\n",currentstate+1,PENALEND); /* in order to quit on ANY action */
fprintf(file,"%d\t%d\t<epsilon>\t%d\t0\n",currentstate+1,currentstate+2,actionsection);
fprintf(file,"%d\t%d\t<epsilon>\t%d\t0\n",currentstate+2,currentstate+3,actionfinsection);
fprintf(file,"%d\t%d\t<epsilon>\t%d\t0\n",currentstate+2,currentstate+3,actionfinsectionimplicit);
fprintf(file,"%d\n",currentstate+3);
currentstate+=2;
nbend=0;
......@@ -185,7 +187,7 @@ for(idac=nbsection=0;fgets(ch,TailleLigne,stdin);)
}
nbseq=0; currentstate=0; //idac=0;
get_field(ch,"id",chfield);
if (sscanf(chfield,"%d",&nbsection)!=1) ERREUR("bad value:",chfield);
if (sscanf(chfield,"%d",&nbsection)!=1) ERREUR("bad value:",ch);
sprintf(ch2,"%s_section%s.txt",chprefix,chfield);
if (!(file=fopen(ch2,"wt"))) ERREUR("can't write in:",ch2);
/* we look for the "start" field */
......@@ -208,9 +210,8 @@ for(idac=nbsection=0;fgets(ch,TailleLigne,stdin);)
if (!(fileexit=fopen(ch2,"wt"))) ERREUR("can't write in:",ch2);
get_field(ch,"action_end",chfield); if (!chfield[0]) { fprintf(stderr,"ERREUR: no action_end field in section: %d\n",nbsection); exit(0); }
get_field(ch,"end",chcontent); if (!chcontent[0]) { fprintf(stderr,"ERREUR: no end field in section: %d\n",nbsection); exit(0); }
sprintf(ch2,"change_section(0,\"%s\",\"%s\")",chfield,chcontent);
remove_space(ch2);
actionfinsection=from_action_to_index(ch2);
sprintf(ch2,"change_section(0,\"%s\",\"%s\")",chfield,chcontent); remove_space(ch2); actionfinsection=from_action_to_index(ch2);
sprintf(ch2,"change_section(0,\"%s\",\"\")",chfield); remove_space(ch2); actionfinsectionimplicit=from_action_to_index(ch2);
for(i=1,t_field[0]=strtok(chcontent," ");t_field[i-1];i++) t_field[i]=strtok(NULL," ");
for(i=0;t_field[i];i++)
{
......@@ -299,11 +300,10 @@ if ((file)&&(nbseq>0))
{
sprintf(chcontent,"action(%d,%d,%d,\"#ENDSEQUENCE(%d)\",\"\")",nbsection,nbseq,idac++,nbseq); actionsequence=from_action_to_index(chcontent);
sprintf(chcontent,"action(%d,%d,%d,\"#ENDSECTION(%d)\",\"\")",nbsection,nbseq,idac++,nbsection); actionsection=from_action_to_index(chcontent);
sprintf(chcontent,"change_section(0,\"close\",\"\")"); actionfinsection=from_action_to_index(chcontent);
for(i=0;i<nbend;i++) fprintf(file,"%d\t%d\t<epsilon>\t%d\t0\n",t_end[i],currentstate+1,actionsequence);
fprintf(file,"%d\t%d\n",currentstate+1,PENALEND); /* in order to quit on ANY action */
fprintf(file,"%d\t%d\t<epsilon>\t%d\t0\n",currentstate+1,currentstate+2,actionsection);
fprintf(file,"%d\t%d\t<epsilon>\t%d\t0\n",currentstate+2,currentstate+3,actionfinsection);
fprintf(file,"%d\t%d\t<epsilon>\t%d\t0\n",currentstate+2,currentstate+3,actionfinsectionimplicit);
fprintf(file,"%d\n",currentstate+3);
}
}
......
......@@ -55,9 +55,9 @@ class ScriptedASR(Gtk.Window):
vbox.pack_start(self.asr, False, True, 5)
# slu
#self.fake_asr = Gtk.Entry()
#self.fake_asr.connect('key-press-event', self.simulate_asr)
#vbox.pack_start(self.fake_asr, False, True, 5)
self.fake_asr = Gtk.Entry()
self.fake_asr.connect('key-press-event', self.simulate_asr)
vbox.pack_start(self.fake_asr, False, True, 5)
slu_prefix = config_dict['slu_prefix']
slu_actions = config_dict['slu_actions']
......@@ -136,10 +136,10 @@ class ScriptedASR(Gtk.Window):
def set_section(self, section_id):
self.xmlview.set_section(section_id)
#def simulate_asr(self, widget, event):
# if event.keyval == Gdk.KEY_Return:
# text = widget.get_text()
# print 'foo', text
def simulate_asr(self, widget, event):
if event.keyval == Gdk.KEY_Return:
text = widget.get_text()
self.hyp_changed([text.strip()])
def slu_finished(self, model, slu_output):
#slu_output = str(slu_output)
......@@ -150,6 +150,9 @@ class ScriptedASR(Gtk.Window):
#for action_id in range(0, len(self.slu_actions)):
for action_id in range(len(self.kept_actions), len(self.slu_actions)):
if action_id > len(self.slu_actions) - 1:
print "WARNING: spurious action", action_id
continue
print 'NEW ACTION:', action_id, self.slu_actions[action_id]
action = actions.parse_slu_action(self.slu_actions[action_id])
if action.name.startswith('#ENDSEQUENCE('):
......@@ -172,6 +175,7 @@ class ScriptedASR(Gtk.Window):
self.kept_actions = []
if new_section in self.slu:
self.slu[new_section].reset_slu()
actions.perform_action(action, False)
else:
actions.perform_action(action, False)
self.kept_history = self.slu_output
......
......@@ -144,6 +144,7 @@ class Keyword(Gtk.Label):
def set_num(self, num):
self.num = num
#self.set_markup(self.text + ' [<a href="%s">%s (%d)</a>] ' % (self.action, self.action, self.num))
def link_clicked(self, widget, uri):
actions.perform_action(actions.Action(uri, keyword=widget), False)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment