diff --git a/maca_morpho/src/fplm_fct.c b/maca_morpho/src/fplm_fct.c new file mode 100644 index 0000000000000000000000000000000000000000..9b5b050907fdec4453bdad4918a688eb132c91dc --- /dev/null +++ b/maca_morpho/src/fplm_fct.c @@ -0,0 +1,101 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include "fplm.h" + +/* Read a line from the fplm file and extract the form/pos/lemma/morpho. + * Return -1 if there's no more line to read, else the number of string read*/ +int read_line_fplm(FILE* fplm, char* form, char* pos, char* lemma, char* morpho) +{ + int fields_nb; + char buffer[10000]; + if(fgets(buffer, 10000, fplm)==NULL) + return -1; + fields_nb = sscanf(buffer, "%[^\t]\t%s\t%[^\t]\t%s\n", form, pos, lemma, morpho); + return fields_nb; +} + +/* Return the class' position in morpho + * (the class could be the tense, the person, the gender or the number of a word)*/ +int extract_class_position(CLASS class) +{ + switch(class) + { + case TENSE: + return 0; + case PERSON: + return 1; + case GENDER: + return 2; + case NUMBER: + return 3; + default: + fprintf(stderr,"Error morpho\n"); + exit(EXIT_FAILURE); + } + return -1; +} + +/* Return the class choosen by the user if their class exists*/ +int choose_class(char* class) +{ + if(!strcmp(class,"tense")) + return TENSE; + else if(!strcmp(class,"person")) + return PERSON; + else if(!strcmp(class,"gender")) + return GENDER; + else if(!strcmp(class,"number")) + return NUMBER; + else + { + fprintf(stderr,"-c argument must be \"tense\", \"person\", \"gender\" or \"number\"\n"); + exit(EXIT_FAILURE); + } + return -1; +} + +void extract_morpho_feature(CLASS class, char* morpho_feature, char* morpho) +{ + int cpt_diese = 0; + int i = 0; + int j; + int position = extract_class_position(class); + if(class==TENSE) + { + while(morpho[i]!='#') + { + morpho_feature[i] = morpho[i]; + i++; + } + morpho_feature[i] = '\0'; + } + else + { + while(i<(int)strlen(morpho) && cpt_diese!=position) + { + if(morpho[i]=='#') + cpt_diese++; + if(cpt_diese==position) + { + i++; + for(j=0; morpho[i]!='#'; j++, i++) + morpho_feature[j] = morpho[i]; + } + i++; + } + morpho_feature[j] = '\0'; + } +} + +int associate_number_to_classes(char* classes_array, char class) +{ + int i; + int size = (int)strlen(classes_array); + for(i=1; i<size; i++) + if(classes_array[i] == class) + return i; + classes_array[size] = class; + classes_array[size+1] = '\0'; + return size; +}