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

fixed few bugs in conll_lib

parent b86a0bf2
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ int conll_parse_line(FILE *f, conll_sentence *s); ...@@ -24,7 +24,7 @@ int conll_parse_line(FILE *f, conll_sentence *s);
void conll_compute_relative_index_of_heads(conll_sentence *s) void conll_compute_relative_index_of_heads(conll_sentence *s)
{ {
int i; unsigned i;
conll_word *w; conll_word *w;
for(i=1; i<s->l; i++){ for(i=1; i<s->l; i++){
...@@ -39,7 +39,7 @@ void conll_compute_relative_index_of_heads(conll_sentence *s) ...@@ -39,7 +39,7 @@ void conll_compute_relative_index_of_heads(conll_sentence *s)
void conll_renumber_sentence(conll_sentence *s) void conll_renumber_sentence(conll_sentence *s)
{ {
int i; unsigned i;
conll_word *w; conll_word *w;
for(i=0 ; i < s->l; i++){ for(i=0 ; i < s->l; i++){
s->words[i]->id = i; s->words[i]->id = i;
...@@ -56,21 +56,21 @@ void conll_renumber_sentence(conll_sentence *s) ...@@ -56,21 +56,21 @@ void conll_renumber_sentence(conll_sentence *s)
void conll_reset_sentence(conll_sentence *s) void conll_reset_sentence(conll_sentence *s)
{ {
int i; unsigned i;
for(i=0 ; i < s->l; i++){ for(i=0 ; i < s->l; i++){
if(s->words[i]){ if(s->words[i]){
free(s->words[i]); free(s->words[i]);
s->words[i] = NULL; s->words[i] = NULL;
} }
} }
s->words[0] = conll_allocate_word(0, "ROOT", "ROOT", "ROOT", "ROOT", "ROOT", -1, "ROOT"); s->words[0] = conll_allocate_word(0, (char *) "ROOT", (char *) "ROOT", (char *) "ROOT", (char *) "ROOT", (char *) "ROOT", -1, (char *) "ROOT");
s->l = 1; s->l = 1;
} }
void conll_free_sentence(conll_sentence *s) void conll_free_sentence(conll_sentence *s)
{ {
int i; unsigned i;
for(i=0 ; i < s->l; i++){ for(i=0 ; i < s->l; i++){
if(s->words[i]){ if(s->words[i]){
/* free(s->words[i]); */ /* free(s->words[i]); */
...@@ -104,7 +104,7 @@ conll_word *conll_allocate_word(unsigned id, char *form, char *lemma, char *cpos ...@@ -104,7 +104,7 @@ conll_word *conll_allocate_word(unsigned id, char *form, char *lemma, char *cpos
conll_sentence *conll_allocate_sentence(void) conll_sentence *conll_allocate_sentence(void)
{ {
conll_sentence *s; conll_sentence *s;
int i; unsigned i;
s = (conll_sentence *)malloc(sizeof(conll_sentence)); s = (conll_sentence *)malloc(sizeof(conll_sentence));
if(s == NULL){ if(s == NULL){
...@@ -123,7 +123,7 @@ conll_sentence *conll_allocate_sentence(void) ...@@ -123,7 +123,7 @@ conll_sentence *conll_allocate_sentence(void)
int conll_load_sentence(FILE *f, conll_sentence *s) int conll_load_sentence(FILE *f, conll_sentence *s)
{ {
int res; int res;
int i; unsigned i;
if(feof(f)) return 0; if(feof(f)) return 0;
conll_reset_sentence(s); conll_reset_sentence(s);
...@@ -136,7 +136,7 @@ int conll_load_sentence(FILE *f, conll_sentence *s) ...@@ -136,7 +136,7 @@ int conll_load_sentence(FILE *f, conll_sentence *s)
/* build the tree structure */ /* build the tree structure */
s->words[0]->mother = NULL; s->words[0]->mother = NULL;
for(i=1; i < s->l; ++i){ for(i=1; i < s->l; ++i){
if((s->words[i]->head >= 0) && (s->words[i]->head <= s->l)){ /* check that head attribute is not out of range */ if((s->words[i]->head >= 0) && (s->words[i]->head <= (int) s->l)){ /* check that head attribute is not out of range */
conll_add_daughter(s->words[i], s->words[s->words[i]->head]); conll_add_daughter(s->words[i], s->words[s->words[i]->head]);
} }
} }
...@@ -236,7 +236,7 @@ int conll_parse_line(FILE *f, conll_sentence *s) ...@@ -236,7 +236,7 @@ int conll_parse_line(FILE *f, conll_sentence *s)
void conll_print_sentence_mcf2(conll_sentence *s, int print_id, int print_form, int print_lemma, int print_cpostag, int print_postag, int print_feats, int print_head, int print_deprel) void conll_print_sentence_mcf2(conll_sentence *s, int print_id, int print_form, int print_lemma, int print_cpostag, int print_postag, int print_feats, int print_head, int print_deprel)
{ {
int i; unsigned i;
conll_word *w; conll_word *w;
if((s->l == 1) || (s->l == 0)) return; if((s->l == 1) || (s->l == 0)) return;
...@@ -267,7 +267,8 @@ void conll_print_sentence_mcf2(conll_sentence *s, int print_id, int print_form, ...@@ -267,7 +267,8 @@ void conll_print_sentence_mcf2(conll_sentence *s, int print_id, int print_form,
void conll_print_sentence_mcf3(conll_sentence *s, char *columns, int nb_col) void conll_print_sentence_mcf3(conll_sentence *s, char *columns, int nb_col)
{ {
int i,j; unsigned i;
int j;
conll_word *w; conll_word *w;
if((s->l == 1) || (s->l == 0)) return; if((s->l == 1) || (s->l == 0)) return;
...@@ -312,7 +313,7 @@ void conll_print_sentence_mcf3(conll_sentence *s, char *columns, int nb_col) ...@@ -312,7 +313,7 @@ void conll_print_sentence_mcf3(conll_sentence *s, char *columns, int nb_col)
void conll_print_sentence_mcf(conll_sentence *s, int coarse_pos) void conll_print_sentence_mcf(conll_sentence *s, int coarse_pos)
{ {
int i; unsigned i;
conll_word *w; conll_word *w;
if((s->l == 1) || (s->l == 0)) return; if((s->l == 1) || (s->l == 0)) return;
...@@ -342,7 +343,7 @@ void conll_print_sentence_mcf(conll_sentence *s, int coarse_pos) ...@@ -342,7 +343,7 @@ void conll_print_sentence_mcf(conll_sentence *s, int coarse_pos)
void conll_print_sentence(conll_sentence *s) void conll_print_sentence(conll_sentence *s)
{ {
int i; unsigned i;
conll_word *w; conll_word *w;
if((s->l == 1) || (s->l == 0)) return; if((s->l == 1) || (s->l == 0)) return;
...@@ -369,7 +370,7 @@ void conll_print_sentence(conll_sentence *s) ...@@ -369,7 +370,7 @@ void conll_print_sentence(conll_sentence *s)
void conll_compact_sentence(conll_sentence *s) void conll_compact_sentence(conll_sentence *s)
{ {
int i,j; unsigned i,j;
for(i=0; i < s->l; i++){ for(i=0; i < s->l; i++){
if(s->words[i] == NULL){ if(s->words[i] == NULL){
for(j = i; j < s->l - 1; j++){ for(j = i; j < s->l - 1; j++){
...@@ -397,7 +398,7 @@ void conll_add_daughter(conll_word *daughter, conll_word *mother) ...@@ -397,7 +398,7 @@ void conll_add_daughter(conll_word *daughter, conll_word *mother)
void conll_remove_daughter(conll_sentence *s, int i) void conll_remove_daughter(conll_sentence *s, int i)
{ {
int j,k; unsigned j,k;
conll_word *dep = s->words[i]; conll_word *dep = s->words[i];
conll_word *gov; conll_word *gov;
if(dep){ if(dep){
...@@ -417,7 +418,7 @@ void conll_remove_daughter(conll_sentence *s, int i) ...@@ -417,7 +418,7 @@ void conll_remove_daughter(conll_sentence *s, int i)
void conll_remove_word_rec(conll_sentence *s, int i) void conll_remove_word_rec(conll_sentence *s, int i)
{ {
int j; unsigned j;
conll_word *w = s->words[i]; conll_word *w = s->words[i];
for(j=1; j < s->l; j++){ for(j=1; j < s->l; j++){
...@@ -437,22 +438,22 @@ void conll_remove_subtree(conll_sentence *s, int root) ...@@ -437,22 +438,22 @@ void conll_remove_subtree(conll_sentence *s, int root)
void conll_add_word(conll_sentence *s, conll_word *w, int index, conll_word *gov) void conll_add_word(conll_sentence *s, conll_word *w, int index, conll_word *gov)
{ {
int i; unsigned i;
if(s->words[index] != NULL){ if(s->words[index] != NULL){
for(i=s->l; i>index; i--){ for(i=s->l; i> (unsigned)index; i--){
s->words[i] = s->words[i-1]; s->words[i] = s->words[i-1];
} }
s->l++; s->l++;
} }
s->words[index] = w; s->words[index] = w;
if(index >= s->l) s->l = index+1; if((unsigned)index >= s->l) s->l = (unsigned)index+1;
if(gov != NULL) if(gov != NULL)
conll_add_daughter(w, gov); conll_add_daughter(w, gov);
} }
void conll_split_node_in_two(conll_sentence *s, int index, conll_word *gov, conll_word *dep, int index_gov, int index_dep) void conll_split_node_in_two(conll_sentence *s, int index, conll_word *gov, conll_word *dep, int index_gov, int index_dep)
{ {
int i; unsigned i;
conll_word *w = s->words[index]; conll_word *w = s->words[index];
conll_word *mother = w->mother; conll_word *mother = w->mother;
...@@ -473,7 +474,7 @@ void conll_split_node_in_two(conll_sentence *s, int index, conll_word *gov, conl ...@@ -473,7 +474,7 @@ void conll_split_node_in_two(conll_sentence *s, int index, conll_word *gov, conl
void conll_change_cpos(conll_sentence *s, hash_str *h_cpos) void conll_change_cpos(conll_sentence *s, hash_str *h_cpos)
{ {
int i; unsigned i;
conll_word *w; conll_word *w;
char *val; char *val;
...@@ -495,7 +496,7 @@ void conll_change_cpos(conll_sentence *s, hash_str *h_cpos) ...@@ -495,7 +496,7 @@ void conll_change_cpos(conll_sentence *s, hash_str *h_cpos)
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
void conll_change_pos(conll_sentence *s, hash_str *h_pos) void conll_change_pos(conll_sentence *s, hash_str *h_pos)
{ {
int i; unsigned i;
conll_word *w; conll_word *w;
char *val; char *val;
...@@ -520,7 +521,7 @@ void conll_change_pos(conll_sentence *s, hash_str *h_pos) ...@@ -520,7 +521,7 @@ void conll_change_pos(conll_sentence *s, hash_str *h_pos)
void conll_change_fct(conll_sentence *s, hash_str *h_fct) void conll_change_fct(conll_sentence *s, hash_str *h_fct)
{ {
int i; unsigned i;
conll_word *w; conll_word *w;
char *val; char *val;
...@@ -554,7 +555,7 @@ int conll_is_num(char *s) ...@@ -554,7 +555,7 @@ int conll_is_num(char *s)
void conll_renumber_sentence_offset(conll_sentence *s, int offset) void conll_renumber_sentence_offset(conll_sentence *s, int offset)
{ {
int i; unsigned i;
for(i=0 ; i < s->l; i++){ for(i=0 ; i < s->l; i++){
s->words[i]->id = i + offset; s->words[i]->id = i + offset;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment