diff --git a/maca_morpho/src/predict_fct.c b/maca_morpho/src/predict_fct.c new file mode 100644 index 0000000000000000000000000000000000000000..0afe5ad9125fab6b700abfe6b4235e49dcad4f38 --- /dev/null +++ b/maca_morpho/src/predict_fct.c @@ -0,0 +1,89 @@ +#include <stdlib.h> +#include <stdio.h> +#include "predict.h" + +void predict_help_message(context *ctx) +{ + context_general_help_message(ctx); + context_language_help_message(ctx); + context_fplm_help_message(ctx); + context_maca_data_path_help_message(ctx); + context_features_filename_help_message(ctx); + context_weights_matrix_filename_help_message(ctx); + context_features_model_help_message(ctx); + exit(1); +} + +void create_predictions_file(context* ctx) +{ + FILE* fplm_test = NULL; + FILE* predictions = NULL; + feature_table *cfw = NULL; + feat_vec *fv = NULL; + dico *dico_features = NULL; + feat_model *fm = NULL; + int fields_nb; + char form[100]; + char pos[50]; + char lemma[100]; + char morpho[50]; + + fplm_test = fopen(ctx->fplm_filename,"r"); + if(fplm_test == NULL) + { + fprintf(stderr,"Could not open input file.\nYou can generate a fplm_test file with fplm2train_test\nThe fplm_test file will be in the Files directory.\n"); + exit(EXIT_FAILURE); + } + cfw = feature_table_load(ctx->cfw_filename, ctx->verbose); + fv = feat_vec_new(10); + dico_features = dico_read(ctx->features_filename, 0.5); + fm = feat_model_read(ctx->fm_filename, feat_lib_build(), ctx->verbose); + predictions = fopen("../../Files/prediction.txt","w"); + if(predictions==NULL) + { + fprintf(stderr,"Problem with the prediction file.\n"); + exit(EXIT_FAILURE); + } + + while((fields_nb = read_line_fplm(fplm_test, form, pos, lemma, morpho)) != -1) + { + if(fields_nb!=4) + { + if(1) + { + fprintf(stderr, "form = %s pos = %s lemma = %s morpho = %s\n", form, pos, lemma, morpho); + fprintf(stderr, "incorrect fplm entry, skipping it\n"); + } + continue; + } + make_prediction(predictions, form, morpho, cfw, fv, dico_features, fm); + } + + if(ctx->features_filename) + dico_print(ctx->features_filename, dico_features); + + fclose(fplm_test); + fclose(predictions); +} + +void make_prediction(FILE* predictions, char* form, char* morpho, feature_table *cfw, feat_vec *fv, dico *dico_features, feat_model *fm) +{ + int class; + float max; + + fprintf(predictions, "form = %s\n", form); + form2fv(form, fv, fm, dico_features, LOOKUP_MODE); + class = feature_table_argmax(fv, cfw, &max); + feat_vec_print(predictions, fv); + fprintf(predictions, "class predicted = %d\n", class); +} + + + + + + + + + +