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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
| /* Code de Cyrine */
#include "appli.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <assert.h>
#include "snprintf.h"
void GenNseq(Liste const *seqx, Liste const *seq2x, Liste *pNouvelleListe)
{
int n = 0;
char buff1[C_TAILLE_MOT];/* pas besoin de malloc car 50 est une petite taille et ca s'ajuste avec Chainon::mot */
char buff2[C_TAILLE_MOT];/* deux buffer temporaire: un pour chaque liste!*/
Chainon const *seq = GetPremierC(seqx);
//assert(seq!=NULL);
/*for (; seq2!=NULL; seq2=seq2->suivant)*/
while(seq!=NULL)
{
/*Pour garder une indentation cohérente, même si on vire le if, on laisse les accolades*/
/* if (seq2->mot)*/
{
Chainon const *seq2;
GetLastWord(GetMot(seq), buff1, C_TAILLE_MOT);
/*printf("Test <%s>", buff1);*/
for (seq2=GetPremierC(seq2x) ; seq2!=NULL ; seq2=GetNextC(seq2)) /* seq[i] - element(liste) de seq*/
{
/*Pour garder une indentation cohérente, même si on vire le if, on laisse les accolades*/
/*if (seq->mot)*/
{
/* printf(".");*/
GetFirstWord(GetMot(seq2), buff2, C_TAILLE_MOT);
/* printf("Test <%s>", buff2);*/
if (strcmp(buff1, buff2)==0)
{
char buffCourant[C_TAILLE_MOT];
int freqCourant;
n++;
/*printf("%s", seq->mot);*/
snprintf(buffCourant, C_TAILLE_MOT, "%s%s", GetMot(seq), strpbrk(GetMot(seq2), " ,.-;"));
freqCourant = frequence(buffCourant);
printf("%s", buffCourant);
/*printf("%d", freqCourant);*/
InsertionEnTete(pNouvelleListe, freqCourant, buffCourant);
}
}
}
printf("\n");
}
seq=GetNextC(seq);
}
}
void elagage(Liste const *listeN, Liste *listeNmoins1) {
Chainon const *pcN;
Chainon **ppNmoins1 = NULL;
for(pcN=GetPremierC(listeN) ; pcN!=NULL ; pcN=GetNextC(pcN)) {
/*printf("%s\n", GetMot(pc1));*/
ppNmoins1=GetPtrPremier(listeNmoins1);
while( ppNmoins1!=NULL && (*ppNmoins1)!=NULL ) {
/*printf("%s\n", (*ppNmoins1)->mot);*/
if ( ( (strstr(GetMot(pcN), GetMot(*ppNmoins1))!=NULL) ) && (GetFreq(pcN) == GetFreq(*ppNmoins1))
/*&& s1==s2 && p1->freq == p2->freq && p1->c->nl == p2->c->nl && p1->c->pos == p2->c->pos)*/
)
{
/* Supprime l'élément courant sans modifier ppNmoins1 */
Chainon *pDel = DetacherChainon(ppNmoins1);
DetruireChainon(pDel);
}
else
{
/* Passe au suivant, modifie ppNmoins1 */
ppNmoins1 = GetNextPtr(ppNmoins1);
}
}
}
}
void AfficherOrigineListe(char const mot [150], Liste const *L, int res)
{
char s3[150];
double const resf = res;
double support;
double confiance;
Chainon const *pc = GetPremierC(L);
FILE *f =NULL;
f=fopen(FNAME1, "w");
while (pc!=NULL)
{
//printf("les mots");
/* printf("%s\n", p->mot);*/
//printf("%s\n",mot);
if(strcmp(GetMot(pc), mot)!=0)
{
// printf("%s", GetMot(pc));
// printf("->");
// printf("%s\n", mot);
sprintf(s3, "%s %s", GetMot(pc), mot);
// printf("%s\n",s3);
//printf("%d\n", res);
//printf("%d", frequence(s3));
support=frequence(s3)/resf;
if(support>=Seuil)
{
if (f!= NULL)
{
fprintf( f, "%s", GetMot(pc));
fprintf(f, "->");
fprintf(f, "%s\n", mot);
confiance = support/(GetFreq(pc)/resf);
/*printf(" / %i ",p->freq);*/
fprintf(f, "\tsupport : %f\n", support);
fprintf(f, "\tConfiance : %f\n", confiance );
}
else
{
printf("Impossible d'ouvrir le fichier resultat.txt");
}
}
}
pc=GetNextC(pc);
fclose(f);
}
}
#if 0
//void AfficherOrigineListe(char const mot [150], Chainon const *p, int res)
//{
// while (p!=NULL){
// printf("%s -> %s\n", p->mot,mot);
// p=p->suivant;
// }
//}
void GenRA(Chainon *l, int res)
{
int i;
Chainon **seq;
seq = malloc (NBRSEQ * sizeof(Chainon *)); /* les tableau des toutes les Nseq*/
Chainon *p=seq;
for (i=0;i<NBRSEQ; i++)
{
while (p!=NULL)
{
AfficherOrigineListe(p->mot, seq[i]);
p=p->suivant;
}
}
}
Chainon *q, *p;
float support;
float confiance;
char s3[150];
for(q=l;q!=NULL;q=q->suivant)
{
for(p=l; p!=NULL; p=p->suivant)
{
printf("%s",q->mot);
printf("->");
printf("%s\n", p->mot);
sprintf(s3, "%s %s", q->mot, p->mot);
printf("%s",s3);
printf("\n\tfrequence %i\n", q->freq);
printf("%d", frequence(s3));
support=frequence(s3)/(float)(res); /*ça serait pas n+1 le nbre ligne*/
confiance =(float)(support)/(float)((float)(q->freq)/(float)(res));
printf(" / %i ",q->freq);
printf("\tsupport : %f\n", support);
printf("\tConfiance : %f\n", confiance );
}
}
p"%i", n+1);
#endif
int main(/*int argc, char *argv[]*/)
{
Liste seq2= { NULL };
Liste *seq=NULL;
int j;
int res=0;
float minsupp;
FILE *fdesc=fopen(FNAME,"r");
printf ("debut du programme \n----------------------------------\n");
printf ("Veuillez saisir le support minimal\n", minsupp);
scanf("%lf",&minsupp);
Liste TableHash[TAILLEHASH];
int i;
int supp=0;
for (i = 0; i < TAILLEHASH; ++i)
InitListe(&TableHash[i]);
if ( fdesc )
{
char buff[BUFFSIZE];
char prec[BUFFSIZE];
printf("Parsing file");
while ( get_word(fdesc,prec,BUFFSIZE) )
{
printf(".");
while ( get_word(fdesc, buff, BUFFSIZE) )
{
/*printf("b2");*/
/*printf("%s %s\n",prec,buff);*/
char s3[BUFFSIZE * 2];
sprintf(s3, "%s %s", prec, buff);
//puts(s3);
strncpy( prec,buff,BUFFSIZE);
insere_th(TableHash,s3);
}
fseek(fdesc, 1, SEEK_CUR);
}
}
printf("la table de hachage avant le filtrage");
dump_table(TableHash);
res = numligne(FNAME);
printf("%d\n", res);
/*printf("%d\n", res);*/
/*printf("aaaaaaaaaaaaaaaaaaaaaaaa");*/
supp=res*minsupp;
clean_table(TableHash, supp);
printf("la table de hachage filtrée\n");
dump_table(TableHash);
for (i=0;i<TAILLEHASH;++i)
{
if (GetPremierC(&TableHash[i])!=NULL)
{
Chainon const *pc;
for (pc=GetPremierC(&TableHash[i]) ; pc!=NULL ; pc=GetNextC(pc))
{
InsertionEnTete(&seq2, GetFreq(pc), GetMot(pc));
}
}
}
//
seq = malloc (NBRSEQ * sizeof(Liste)); /* les tableau des toutes les Nseq*/
for(i =0 ; i<NBRSEQ ; i++)
InitListe(&seq[i]);
seq[0]=seq2;
//AfficherListe(&seq[0]);
for(i=1 ; i<NBRSEQ ; i++)
{
GenNseq(&seq[i-1], &seq2, &seq[i]);
AfficherListe(&seq[i]);
clean_liste(&seq[i], &supp);
// AfficherListe(&seq[i]);
if (TailleListe(&seq[i]) == 0) /* si on arrive plus a generer on sort de boucle*/
break;
}
//AfficherListe(&seq[0]);
//
for (j=1; j <= i; j++){
printf("\nla liste des %d seq elagues:\n----------------------------------\n",(j+1));
/*AfficherListe(seq[j]); */
elagage(&seq[j], &seq[j-1]);
AfficherListe(&seq[j-1]);
}
//
// AfficherListe(&seq[i]);
printf("la liste des regles d'association\n");
for(i=0 ; i<NBRSEQ ; i++){
/*GenRA(seq[i], res);*/
Chainon const *pc=GetPremierC(&seq[i]);
while (pc!=NULL){
//printf("%s", GetMot(pc));
for(j=0; j<NBRSEQ - 1; j++)
AfficherOrigineListe(GetMot(pc), &seq[j], res);
pc=GetNextC(pc);
}
}
free(seq);
return 0;
} |
Partager