Select Git revision
fplm_fct.c 2.10 KiB
#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++;
}