Skip to content
Snippets Groups Projects
Commit 5d153ce5 authored by Marjorie Armando's avatar Marjorie Armando
Browse files

add lemma as a pattern feature

parent eeca92b7
Branches
No related tags found
No related merge requests found
feat_pos s1
feat_pos s1
feat_pos s2
feat_pos s1 s2
feat_pos s1
feat_pos s2
feat_pos s3
feat_pos s1 s2
feat_pos s1 s2 s3
feat_pos s1
feat_pos s2
feat_pos s3
feat_pos s4
feat_pos s1 s2
feat_pos s1 s2 s3
feat_pos s1 s2 s3 s4
feat_pos s1
feat_pos s2
feat_pos s3
feat_pos s4
feat_pos s5
feat_pos s1 s2
feat_pos s1 s2 s3
feat_pos s1 s2 s3 s4
feat_pos s1 s2 s3 s4 s5
feat_pos s1
feat_pos s2
feat_pos s3
feat_pos s4
feat_pos s5
feat_pos s6
feat_pos s1 s2
feat_pos s1 s2 s3
feat_pos s1 s2 s3 s4
feat_pos s1 s2 s3 s4 s5
feat_pos s1 s2 s3 s4 s5 s6
feat_pos s1
feat_pos s2
feat_pos s3
feat_pos s4
feat_pos s5
feat_pos s6
feat_pos s7
feat_pos s1 s2
feat_pos s1 s2 s3
feat_pos s1 s2 s3 s4
feat_pos s1 s2 s3 s4 s5
feat_pos s1 s2 s3 s4 s5 s6
feat_pos s1 s2 s3 s4 s5 s6 s7
...@@ -13,10 +13,10 @@ FPLM* new_fplm(void) ...@@ -13,10 +13,10 @@ FPLM* new_fplm(void)
void free_fplm(FPLM* fplm) void free_fplm(FPLM* fplm)
{ {
free(fplm->form); if(fplm->form != NULL) free(fplm->form);
free(fplm->pos); if(fplm->pos != NULL) free(fplm->pos);
free(fplm->lemma); if(fplm->lemma != NULL) free(fplm->lemma);
free(fplm->morpho); if(fplm->morpho != NULL) free(fplm->morpho);
free(fplm); free(fplm);
} }
......
...@@ -165,6 +165,31 @@ int feat_pos(FPLM* fplm) ...@@ -165,6 +165,31 @@ int feat_pos(FPLM* fplm)
return code; return code;
} }
int lemma_s1(FPLM* fplm)
{
char16* tmp = utf8tochar16(fplm->lemma);
int size = char16_strlen(tmp);
if(tmp == NULL || size - 1 < 0)
return -1;
return tmp[size - 1];
}
int lemma_s2(FPLM* fplm)
{
char16* tmp = utf8tochar16(fplm->lemma);
int size = char16_strlen(tmp);
if(tmp == NULL || size - 2 < 0)
return -1;
return tmp[size - 2];
}
int lemma_s3(FPLM* fplm)
{
char16* tmp = utf8tochar16(fplm->lemma);
int size = char16_strlen(tmp);
if(tmp == NULL || size - 3 < 0)
return -1;
return tmp[size - 3];
}
feat_lib *feat_lib_build(void) { feat_lib *feat_lib_build(void) {
feat_lib *fl = feat_lib_new(); feat_lib *fl = feat_lib_new();
...@@ -184,5 +209,8 @@ feat_lib *feat_lib_build(void) { ...@@ -184,5 +209,8 @@ feat_lib *feat_lib_build(void) {
feat_lib_add(fl, 1, (char *)"feat_number", feat_number); feat_lib_add(fl, 1, (char *)"feat_number", feat_number);
feat_lib_add(fl, 1, (char *)"feat_gender", feat_gender); feat_lib_add(fl, 1, (char *)"feat_gender", feat_gender);
feat_lib_add(fl, 1, (char *)"feat_tense", feat_tense); feat_lib_add(fl, 1, (char *)"feat_tense", feat_tense);
feat_lib_add(fl, 1, (char *)"lemma_s1", lemma_s1);
feat_lib_add(fl, 1, (char *)"lemma_s2", lemma_s2);
feat_lib_add(fl, 1, (char *)"lemma_s3", lemma_s3);
return fl; return fl;
} }
...@@ -347,7 +347,6 @@ void predict_target(context* ctx) ...@@ -347,7 +347,6 @@ void predict_target(context* ctx)
char predict_name[50]; char predict_name[50];
FPLM* fplm = new_fplm(); FPLM* fplm = new_fplm();
TARGET target; TARGET target;
FILE* tmp = fopen("../../Files/tmp.txt","w");
init_input_files(in_files, ctx->fplm_filename, ctx->code_class_filename, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); init_input_files(in_files, ctx->fplm_filename, ctx->code_class_filename, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
if(fscanf(in_files->code_class,"%s",target_name)!=1) if(fscanf(in_files->code_class,"%s",target_name)!=1)
{ {
...@@ -377,7 +376,6 @@ void predict_target(context* ctx) ...@@ -377,7 +376,6 @@ void predict_target(context* ctx)
} }
continue; continue;
} }
fprintf(tmp,"%s\t%s\t%s\t%s\n",fplm->form, fplm->pos, fplm->lemma, fplm->morpho);
line_nb++; line_nb++;
if(ctx->cascade) if(ctx->cascade)
fprintf(out_files->new_fplm,"%s\t%s\t%s\t",fplm->form, fplm->pos, fplm->lemma); fprintf(out_files->new_fplm,"%s\t%s\t%s\t",fplm->form, fplm->pos, fplm->lemma);
...@@ -535,6 +533,9 @@ void predict_each_and_all_targets(context* ctx) ...@@ -535,6 +533,9 @@ void predict_each_and_all_targets(context* ctx)
} }
compare_morpho_predicted_and_real_morphos(in_files->all_real_morphos, out_files->morpho_predicted, line_nb); compare_morpho_predicted_and_real_morphos(in_files->all_real_morphos, out_files->morpho_predicted, line_nb);
printf("Global success rate : %lf %%\n", 100-((float)global_error*100/line_nb)); printf("Global success rate : %lf %%\n", 100-((float)global_error*100/line_nb));
free_fplm(fplm);
free_input_files(in_files);
free_output_files(out_files);
} }
void calculate_global_success_rate(context* ctx, Input_files* in_files, FILE* morpho_predicted, int* global_error, int* class_predicted_array,char* morpho) void calculate_global_success_rate(context* ctx, Input_files* in_files, FILE* morpho_predicted, int* global_error, int* class_predicted_array,char* morpho)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment