From c3d40393d8146d2bf151adafad29eb26a9409fe2 Mon Sep 17 00:00:00 2001
From: Alexis Nasr <alexis.nasr@lif.univ-mrs.fr>
Date: Tue, 4 Oct 2016 09:54:17 -0400
Subject: [PATCH] code refactoring

---
 maca_common/src/word.c                        | 27 +++++--------------
 maca_lemmatizer/src/context.c                 |  4 +--
 maca_trans_parser/src/depset.c                |  8 ++----
 maca_trans_parser/src/simple_decoder_parser.c | 17 +++---------
 4 files changed, 14 insertions(+), 42 deletions(-)

diff --git a/maca_common/src/word.c b/maca_common/src/word.c
index 8cc623c..b2c4aa6 100644
--- a/maca_common/src/word.c
+++ b/maca_common/src/word.c
@@ -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)
diff --git a/maca_lemmatizer/src/context.c b/maca_lemmatizer/src/context.c
index f83fae2..81daf46 100644
--- a/maca_lemmatizer/src/context.c
+++ b/maca_lemmatizer/src/context.c
@@ -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);
diff --git a/maca_trans_parser/src/depset.c b/maca_trans_parser/src/depset.c
index c7f5cfe..ee7f0fd 100644
--- a/maca_trans_parser/src/depset.c
+++ b/maca_trans_parser/src/depset.c
@@ -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)
 {
diff --git a/maca_trans_parser/src/simple_decoder_parser.c b/maca_trans_parser/src/simple_decoder_parser.c
index 9478441..f803a81 100644
--- a/maca_trans_parser/src/simple_decoder_parser.c
+++ b/maca_trans_parser/src/simple_decoder_parser.c
@@ -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); */
-- 
GitLab