Skip to content
Snippets Groups Projects
Commit e077211f authored by Alexis Nasr's avatar Alexis Nasr
Browse files

added default movement in transition machine

parent 22101d33
No related branches found
No related tags found
No related merge requests found
......@@ -235,6 +235,7 @@ void maca_tm_decoder(context *ctx)
int parser_state_nb = tm_get_parser_state(ctx->machine);
int morpho_state_nb = tm_get_morpho_state(ctx->machine);
int tagger_state_nb = tm_get_tagger_state(ctx->machine);
mvt_tagset *std_mvt_tagset = mvt_tagset_std();
/* printf("tagger state nb = %d\n", tagger_state_nb); */
/* printf("parser state nb = %d\n", parser_state_nb); */
......@@ -247,6 +248,10 @@ void maca_tm_decoder(context *ctx)
if(ctx->f2p)
add_signature_to_words_in_word_buffer(c->bf, ctx->f2p);
while(tm_state_num_has_forced_transition(ctx->machine, c->current_state_nb)){
tm_take_forced_transition(c, ctx->machine, std_mvt_tagset);
}
/* horrible trick : when at the end of buffer, skip tagger mode stay in parser mode */
if((c->current_state_nb == tagger_state_nb) && word_buffer_end(config_get_buffer(c)))
c->current_state_nb = parser_state_nb;
......
......@@ -37,6 +37,7 @@ int movement_apply(config *c, int mvt_code, mvt_tagset *tagset, int root_code, t
break;
case MVT_POS :
result = movement_add_pos(c, mvt_label);
result = movement_forward(c);
break;
case MVT_CPOS :
result = movement_add_cpos(c, mvt_label);
......
......@@ -158,3 +158,12 @@ mvt_tagset *mvt_tagset_morpho(dico *d_labels)
/* mvt_tagset_print(t); */
return t;
}
mvt_tagset *mvt_tagset_std(void)
{
mvt_tagset *t = mvt_tagset_new("std", NULL);
t->start[MVT_FWD] = t->end[MVT_FWD] = t->nbelem++;
/* mvt_tagset_print(t); */
return t;
}
......@@ -30,9 +30,9 @@ int mvt_tagset_get_label(mvt_tagset *t, int code);
int mvt_tagset_get_type(mvt_tagset *t, int code);
int mvt_tagset_get_code(mvt_tagset *t, int type, int label);
void mvt_tagset_print_mvt(FILE *f, mvt_tagset *t, int code);
int mvt_tagset_type_string2int(mvt_tagset *t, char *mvt_type_str);
mvt_tagset *mvt_tagset_parser(dico *d_labels);
mvt_tagset *mvt_tagset_tagger(dico *d_labels);
int mvt_tagset_type_string2int(mvt_tagset *t, char *mvt_type_str);
mvt_tagset *mvt_tagset_morpho(dico *d_labels);
mvt_tagset *mvt_tagset_std(void);
#endif
......@@ -5,6 +5,7 @@
#include"util.h"
#include"tm.h"
#include"classifier_vec.h"
#include"movements.h"
int tm_get_parser_state(tm *machine)
......@@ -44,6 +45,7 @@ tm_state *tm_state_new(char *name, classifier *classif, int classifier_nb, int i
state->is_accept = is_accept;
state->classif = classif;
state->classifier_nb = classifier_nb;
state->forced_transition = 0;
return state;
}
......@@ -111,6 +113,57 @@ void tm_add_transition(tm *machine, char *origin_state_name, char *destination_s
origin_state->trans_list = tm_transition_new(mvt_code, destination_state_num, origin_state->trans_list);
}
void tm_add_forced_transition(tm *machine, char *origin_state_name, char *destination_state_name, int mvt_code)
{
int origin_state_num = dico_string2int(machine->d_states, origin_state_name);
int destination_state_num = dico_string2int(machine->d_states, destination_state_name);
tm_state *origin_state = NULL;
if(origin_state_num == -1){
fprintf(stderr, "state %s does not exist\n", origin_state_name);
exit(1);
}
origin_state = machine->state_array[origin_state_num];
if(destination_state_num == -1){
fprintf(stderr, "state %s does not exist\n", destination_state_name);
exit(1);
}
origin_state->forced_transition = 1;
origin_state->trans_list = tm_transition_new(mvt_code, destination_state_num, NULL);
}
int tm_take_forced_transition(config *c, tm *machine, mvt_tagset *std_mvt_tagset)
{
int res;
tm_state *state = machine->state_array[c->current_state_nb];
if(state->forced_transition){
res = movement_apply(c, state->trans_list->label, std_mvt_tagset, -1, machine);
}
return res;
}
int tm_state_has_forced_transition(tm *machine, char *state_name)
{
int state_num = dico_string2int(machine->d_states, state_name);
if(state_num == -1){
fprintf(stderr, "state %s does not exist\n", state_name);
exit(1);
}
tm_state *state = machine->state_array[state_num];
return state->forced_transition;
}
int tm_state_num_has_forced_transition(tm *machine, int state_num)
{
if(state_num == -1){
fprintf(stderr, "state %d out of range\n", state_num);
exit(1);
}
tm_state *state = machine->state_array[state_num];
return state->forced_transition;
}
void tm_print(FILE *f, tm *machine)
{
int i;
......@@ -251,9 +304,10 @@ tm *tm_load(char *filename, char *absolute_path, int verbose)
}
/* read transition description */
if(section == 't'){
char forced_str[10];
strcpy(mvt_type_str, "");
strcpy(mvt_label_str, "");
sscanf(line, "%s %s %s %s", state1_name, state2_name, mvt_type_str, mvt_label_str);
int fields_nb = sscanf(line, "%s %s %s %s %s", state1_name, state2_name, mvt_type_str, mvt_label_str, forced_str);
if(verbose) fprintf(stderr, "loading TM : creating transition %s - -> %s\n", state1_name, state2_name);
......@@ -272,6 +326,7 @@ tm *tm_load(char *filename, char *absolute_path, int verbose)
classif = state1->classif;
output_tagset = classif->output_tagset;
if(!strcmp(mvt_type_str, "*")){
/* transitions from state1 to state2 on all movements */
for(i=0; i < output_tagset->nbelem; i++){
......@@ -288,13 +343,28 @@ tm *tm_load(char *filename, char *absolute_path, int verbose)
}
else{
mvt_label = dico_string2int(output_tagset->d_labels, mvt_label_str);
/* transitions from state1 to state2 on movement of type mvt_type and label mvt_label */
if((fields_nb == 5) && !strcmp(forced_str, "F")){
if(tm_state_has_forced_transition(machine, state1_name)){
fprintf(stderr, "loading TM : if a state has a forced transition it must be unique\n");
exit(1);
}
/* add a forced transition from state1 to state 2 on movement type mvt_type and label mvt_label */
tm_add_forced_transition(machine, state1_name, state2_name, mvt_tagset_get_code(output_tagset, mvt_type, mvt_label));
}
else{
if(tm_state_has_forced_transition(machine, state1_name)){
fprintf(stderr, "loading TM : a state cannot have a forced and a standard transition\n");
exit(1);
}
/* add a standard transitions from state1 to state2 on movement of type mvt_type and label mvt_label */
tm_add_transition(machine, state1_name, state2_name, mvt_tagset_get_code(output_tagset, mvt_type, mvt_label));
}
}
continue;
}
}
continue;
}
fclose(f);
......
......@@ -20,6 +20,7 @@ typedef struct{
tm_transition *trans_list;
int is_accept;
int classifier_nb;
int forced_transition;
} tm_state;
typedef struct{
......@@ -52,5 +53,7 @@ int tm_check_integrity(tm *machine);
int tm_get_parser_state(tm *machine);
int tm_get_tagger_state(tm *machine);
int tm_get_morpho_state(tm *machine);
int tm_state_has_forced_transition(tm *machine, char *state_name);
int tm_state_num_has_forced_transition(tm *machine, int state_num);
int tm_take_forced_transition(config *c, tm *machine, mvt_tagset *std_mvt_tagset);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment