Commit c3d40393 authored by Alexis Nasr's avatar Alexis Nasr
Browse files

code refactoring

parent d886a345
......@@ -27,15 +27,14 @@ word *word_new(char *input)
word *word_read(FILE *f, mcd *mcd_struct)
{
char buffer[10000];
if(feof(f)) return NULL; /* no more words to read */
/* look for a valid word */
while(fgets(buffer, 10000, f)){
if(feof(f)) return NULL; /* no more words to read */
if((buffer[0] != '\n') && (buffer[0] != ' ')){
/* printf("word = %s\n", buffer); */
return word_parse_buffer(buffer, mcd_struct);
}
/* ignore empty lines */
if((buffer[0] == '\n')) continue;
/* lines beginning with ## are comments */
if((buffer[0] == '#') && (buffer[1] == '#')) continue;
return word_parse_buffer(buffer, mcd_struct);
}
return NULL;
}
......@@ -69,6 +68,8 @@ word *word_parse_buffer(char *buffer, mcd *mcd_struct)
}
/* out of date, must be updated */
word *word_copy(word *w)
{
word *copy = word_new(w->input);
......@@ -109,10 +110,7 @@ word *word_create_dummy(mcd *mcd_struct)
void word_print2(FILE *f, word *w)
{
int i;
if(w == NULL) return;
if(w->input) fprintf(f, "%s\t", w->input);
printf("form = %d\t", word_get_form(w));
......@@ -120,24 +118,13 @@ void word_print2(FILE *f, word *w)
printf("pos = %d\t", word_get_pos(w));
printf("index = %d\t", word_get_index(w));
printf("rel index = %d\n", word_get_relative_index(w));
/*
if(dico_labels)
fprintf(f, "\t%s", dico_int2string(dico_labels, w->label));
else
fprintf(f, "\t%d", word_get_label(w));*/
}
void word_print(FILE *f, word *w, mcd *mcd_struct, dico *dico_labels)
{
int i;
if(w == NULL) return;
fprintf(f, "%s", w->input);
}
int word_is_eos(word *w, mcd *mcd_struct)
......
......@@ -110,10 +110,10 @@ context *context_read_options(int argc, char *argv[])
ctx->verbose = 1;
break;
case 'F':
ctx->form_column = atoi(optarg);
ctx->form_column = atoi(optarg) - 1;
break;
case 'P':
ctx->pos_column = atoi(optarg);
ctx->pos_column = atoi(optarg) - 1;
break;
case 'f':
ctx->fplm_filename = strdup(optarg);
......
......@@ -74,21 +74,16 @@ void depset_print(FILE *f, depset *d)
void depset_print2(FILE *f, depset *d, dico *dico_labels)
{
int i;
int root_code = dico_string2int(dico_labels, "root");
int distance;
for(i=1; i < d->length; i++){
if((d->array[i].gov) && (d->array[i].dep)){
/* if(d->array[i].label == root_code) */
/* fprintf(f, "%s\t%d\t%s\n", d->array[i].dep->input, 0, dico_int2string(dico_labels, d->array[i].label)); */
/* else{ */
distance = word_get_relative_index(d->array[i].gov) - word_get_relative_index(d->array[i].dep);
fprintf(f, "%s\t%d\t%s\n", d->array[i].dep->input, distance, dico_int2string(dico_labels, d->array[i].label));
/* } */
}
}
}
/*
void depset_print3(FILE *f, depset *d, dico *dico_labels)
{
int i;
......@@ -106,6 +101,7 @@ void depset_print3(FILE *f, depset *d, dico *dico_labels)
}
}
}
*/
char *skip_index(char *buffer)
{
......
......@@ -92,10 +92,7 @@ void simple_decoder_stream(context *ctx, FILE *f, feature_table *ft, int root_la
/* config_connect_subtrees(c, root_label); */
/* depset_print_new_index(stdout, c->ds, ctx->dico_labels); */
if(ctx->mcd_struct->wf2col[MCD_WF_INDEX] == -1)
depset_print3(stdout, c->ds, ctx->dico_labels);
else
depset_print2(stdout, c->ds, ctx->dico_labels);
depset_print2(stdout, c->ds, ctx->dico_labels);
/* pop the dummy word */
stack_pop(c->st);
......@@ -124,17 +121,9 @@ void simple_decoder_stream(context *ctx, FILE *f, feature_table *ft, int root_la
/* config_print(stdout, c); */
/* config_connect_subtrees(c, root_label); */
/* config_connect_subtrees(c, root_label); */
if(ctx->mcd_struct->wf2col[MCD_WF_INDEX] == -1)
depset_print3(stdout, c->ds, ctx->dico_labels);
else
depset_print2(stdout, c->ds, ctx->dico_labels);
/* depset_print_new_index(stdout, c->ds, ctx->dico_labels); */
depset_print2(stdout, c->ds, ctx->dico_labels);
/* config_free(c); */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment