report_OOV.c
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* Print a report about OOV on a corpus according
* to a lexicon given as parameter */
/* FRED 0703 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <lia_tree_avl.h>
/*................................................................*/
#define TailleLigne 40000
#define True 1
#define False 0
void ERREUR(char *ch1,char *ch2)
{
fprintf(stderr,"ERREUR : %s %s\n",ch1,ch2);
exit(0);
}
/*................................................................*/
/* reading lexicon */
lia_avl_t read_lexicon(char *filename)
{
FILE *file;
static char ch[TailleLigne],*pt;
lia_avl_t resu;
if (!(file=fopen(filename,"rt"))) ERREUR("can't open:",filename);
for (resu=NULL;fgets(ch,TailleLigne,file);)
for(pt=strtok(ch," \t\n");pt;pt=strtok(NULL," \t\n"))
resu=lia_ajoute_element_avl(resu,pt,True,NULL);
fclose(file);
return resu;
}
/*................................................................*/
/* checking each word of the corpus */
lia_avl_t checking_corpus(FILE *file, lia_avl_t lexicon, int *nboov)
{
static char ch[TailleLigne],*pt;
lia_avl_t t_oov,resu;
int nb;
for (*nboov=0,t_oov=NULL;fgets(ch,TailleLigne,file);)
for(pt=strtok(ch," \t\n");pt;pt=strtok(NULL," \t\n"))
if (resu=lia_recherche_avl(lexicon,pt,&nb)) resu->nb++;
else { t_oov=lia_ajoute_element_avl(t_oov,pt,True,NULL); (*nboov)++; }
return t_oov;
}
/*................................................................*/
int main(int argc, char **argv)
{
char ch[TailleLigne];
int nb,i,nboov;
lia_avl_t t_lexique, t_unknown,*table;
if (argc<2)
{
fprintf(stderr,"Syntaxe : %s <lexicon>\n",argv[0]);
exit(0);
}
t_lexique=read_lexicon(argv[1]);
t_unknown=checking_corpus(stdin,t_lexique,&nboov);
table=lia_avl_tree2table_freq(t_unknown,&nb);
printf("%d entree inconnues dans le corpus (%d occurrences)\n",nb,nboov);
for(i=0;i<nb;i++)
printf("\t%5d \t %s\n",table[i]->nb,table[i]->info);
exit(0);
}