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

moved word_buffer to maca_common

parent 4fc0c025
Branches
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ set(SOURCES src/util.c
src/form2pos.c
src/word.c
src/sentence.c
src/word_buffer.c
)
#compiling library
......
......@@ -5,6 +5,22 @@
#include"word.h"
#include"mcd.h"
#define word_buffer_get_size(wb) (wb)->size
#define word_buffer_get_nbelem(wb) (wb)->nbelem
#define word_buffer_get_lookahead(wb) (wb)->lookahead
#define word_buffer_get_current_index(wb) (wb)->current_index
#define word_buffer_get_input_file(wb) (wb)->input_file
#define word_buffer_get_mcd(wb) (wb)->input_mcd_struct
#define word_buffer_b0(wb) ((wb)->nbelem == 0)? NULL : (wb)->array[(wb)->current_index]
#define word_buffer_b1(wb) ((wb)->current_index + 1 >= (wb)->nbelem)? NULL : (wb)->array[(wb)->current_index + 1]
#define word_buffer_b2(wb) ((wb)->current_index + 2 >= (wb)->nbelem)? NULL : (wb)->array[(wb)->current_index + 2]
#define word_buffer_b3(wb) ((wb)->current_index + 3 >= (wb)->nbelem)? NULL : (wb)->array[(wb)->current_index + 3]
#define word_buffer_bm1(wb) ((wb)->current_index - 1 < 0)? NULL : (wb)->array[(wb)->current_index - 1]
#define word_buffer_bm2(wb) ((wb)->current_index - 2 < 0)? NULL : (wb)->array[(wb)->current_index - 2]
#define word_buffer_bm3(wb) ((wb)->current_index - 3 < 0)? NULL : (wb)->array[(wb)->current_index - 3]
typedef struct {
int size; /* size of the array used to store words */
int nbelem; /* number of words in the buffer */
......@@ -20,6 +36,11 @@ word_buffer *word_buffer_new(FILE *input_file, mcd *mcd_struct, int lookahead);
void word_buffer_free(word_buffer *wb);
int word_buffer_add(word_buffer *wb, word *w);
word *word_buffer_get_word_relative(word_buffer *wb, int dist);
int word_buffer_read_next_word(word_buffer *wb);
int word_buffer_move_right(word_buffer *wb);
int word_buffer_move_left(word_buffer *wb);
void word_buffer_print(FILE *f, word_buffer *wb);
/*
word *word_buffer_b0(word_buffer *wb);
word *word_buffer_b1(word_buffer *wb);
word *word_buffer_b2(word_buffer *wb);
......@@ -27,9 +48,7 @@ word *word_buffer_b3(word_buffer *wb);
word *word_buffer_bm1(word_buffer *wb);
word *word_buffer_bm2(word_buffer *wb);
word *word_buffer_bm3(word_buffer *wb);
int word_buffer_read_next_word(word_buffer *wb);
int word_buffer_move_right(word_buffer *wb);
int word_buffer_move_left(word_buffer *wb);
void word_buffer_print(FILE *f, word_buffer *wb);
*/
#endif
......@@ -64,6 +64,41 @@ word *word_buffer_get_word(word_buffer *wb, int offset)
return ((wb->current_index + offset >=0) && (wb->current_index + offset <= wb->nbelem))? wb->array[wb->current_index + offset] : NULL;
}
int word_buffer_read_next_word(word_buffer *wb)
{
word *w = NULL;
int index;
w = word_read(wb->input_file, wb->mcd_struct);
if(w == NULL) return -1;
index = word_buffer_add(wb, w);
word_set_relative_index(w, index);
return index;
}
int word_buffer_move_right(word_buffer *wb)
{
if((wb->nbelem - 1 - wb->current_index) <= wb->lookahead)
word_buffer_read_next_word(wb);
if(wb->current_index == wb->nbelem - 1) return 0;
wb->current_index++;
return 1;
}
int word_buffer_move_left(word_buffer *wb)
{
if(wb->current_index > 0){
wb->current_index--;
return 1;
}
return 0;
}
/*
word *word_buffer_b0(word_buffer *wb)
{
return(wb->nbelem == 0)? NULL : wb->array[wb->current_index];
......@@ -98,37 +133,5 @@ word *word_buffer_bm3(word_buffer *wb)
{
return(wb->current_index - 3 < 0)? NULL : wb->array[wb->current_index - 3];
}
int word_buffer_read_next_word(word_buffer *wb)
{
word *w = NULL;
int index;
w = word_read(wb->input_file, wb->mcd_struct);
if(w == NULL) return -1;
index = word_buffer_add(wb, w);
word_set_relative_index(w, index);
return index;
}
int word_buffer_move_right(word_buffer *wb)
{
if((wb->nbelem - 1 - wb->current_index) <= wb->lookahead)
word_buffer_read_next_word(wb);
if(wb->current_index == wb->nbelem - 1) return 0;
wb->current_index++;
return 1;
}
int word_buffer_move_left(word_buffer *wb)
{
if(wb->current_index > 0){
wb->current_index--;
return 1;
}
return 0;
}
*/
......@@ -18,7 +18,6 @@ set(SOURCES src/context.c
src/queue.c
src/beam.c
src/feat_types.c
src/word_buffer.c
)
#compiling library
......
......@@ -57,7 +57,7 @@ context *context_new(void)
ctx->f2p_filename = NULL;
ctx->maca_data_path = NULL;
ctx->language = strdup("fr");
ctx->language = strdup("fr_stream");
ctx->root_label = strdup("root");
ctx->d_perceptron_features = NULL;
......@@ -67,7 +67,6 @@ context *context_new(void)
ctx->dico_labels = NULL;
ctx->f2p = NULL;
ctx->iteration_nb = 4;
ctx->debug_mode = 0;
ctx->feature_cutoff = 0;
......@@ -77,7 +76,7 @@ context *context_new(void)
ctx->beam_width = 1;
ctx->sent_nb = 1000000;
ctx->hidden_neurons_nb = 100;
ctx->stream_mode = 0;
ctx->stream_mode = 1;
ctx->conll = 0;
ctx->ifpls = 1;
......
......@@ -75,11 +75,21 @@ void depset_print2(FILE *f, depset *d, dico *dico_labels)
{
int i;
int distance;
char *label;
for(i=1; i < d->length; i++){
if((d->array[i].gov) && (d->array[i].dep)){
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));
/* fprintf(f, "%s\t%d\t%s\n", d->array[i].dep->input, distance, dico_int2string(dico_labels, d->array[i].label)); */
label = dico_int2string(dico_labels, d->array[i].label);
fprintf(f, "%s\t%d\t%s\t", d->array[i].dep->input, distance, label);
if(!strcmp(label, "eos"))
fprintf(f, "1\n");
else
fprintf(f, "0\n");
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment