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 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363
| /* Code de Cyrine */
#include "appli.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
#ifdef _MSC_VER
#include <crtdbg.h>
#endif
#include <time.h>
#include <assert.h>
#include "snprintf.h"
#ifdef _MSC_VER
_CRTIMP void __cdecl _wassert(__in_z const wchar_t * _Message, __in_z const wchar_t *_File, __in unsigned _Line);
#define AssertAlways(_Expression) (void)( (!!(_Expression)) || (_wassert(_CRT_WIDE(#_Expression), _CRT_WIDE(__FILE__), __LINE__), 0) )
#endif
double log2(double x) { return log(x)/log(2.0); }
/*
==============================================================================
Fonctions pour afficher la progression.*/
double info_mut_cond(ChainonMot const *pc, ChainonMot const *pc2,int nblignes,TableHachageMot * t1,TableHachageMot * t2);
FILE *fblue;
double info_mut(ChainonMot const *pc, ChainonMot const *pc2,int nblignes);
int nbrLignesCommunes(ChainonMot const * pc,ChainonMot const * pc2);
void AfficherCarac(FILE *pfOut, size_t n, int c)
{
size_t i;
for(i=0 ; i<n ; i++)
fputc(c, pfOut);
}
/*--------------------------------------------------------------------------*/
void AfficherEspaces(size_t n)
{
AfficherCarac(stdout, n, ' ');
}
/*
==============================================================================
Fonctions pour la lecture des 2seq du fichier d'entrée,
utilisant un double buffer pour les mots.*/
/*----------------------------------------------------------------------------
Fonction pour inverser le double buffer*/
void SwapPtrChar(char **pa, char **pb)
{
char * tmp = *pa;
*pa = *pb;
*pb = tmp;
}
/*----------------------------------------------------------------------------
Fonction de lecture principale, remplit la table de hachage de 2seq.*/
int LireFichierEntree(char const *langue, TableHachageMot DblTableHash[],TableHachageMot DblTableHash2[],int *pNbLignes)
{
int retour = -1;
FILE *fdesc = NULL;
if(pNbLignes != NULL)
*pNbLignes = 0;
fdesc = ouvrir_fichier_entree(langue);
if ( fdesc==NULL )
{
perror("fopen");
}
else
{
char* buff = NULL;
char* prec = NULL;
char* concat = NULL;
size_t tailleBuff = 0;
size_t taillePrec = 0;
size_t tailleConcat = 0;
int ancienneLigne =-1 ;
int ancienneColonne = -1;
int ligne = 0;
int colonne = -1;
ssize_t res;
printf("Lecture du fichier texte (prog: 1 point pour %d lignes)...\n", PROG_NBLIGNES);
while ( (res=get_word(fdesc, &buff, &tailleBuff, &ligne, &colonne))>0 )
{
InsertionDoubleHashEx(DblTableHash, buff, ligne, ancienneColonne);
if(ancienneLigne == ligne)
{
static char const separ[] = {SEPARATEUR, '\0'};
/* Mot sur la même ligne: Ajouter 2seq */
if(tailleConcat < 2*tailleBuff)
{
tailleConcat = 2*tailleBuff;
ReallocCharExit(&concat, tailleConcat);
}
assert(concat != NULL);
strcpyN(concat, tailleConcat, prec);
strcatN(concat, tailleConcat, separ);
strcatN(concat, tailleConcat, buff);
#if 0
AfficherEspaces(ancienneColonne);
puts(concat);
#endif
//InsertionDoubleHashEx(DblTableHash, buff, ancienneLigne, ancienneColonne);
InsertionDoubleHashEx(DblTableHash2, concat, ancienneLigne, ancienneColonne);
}
else
{
if(ligne%PROG_NBLIGNES==0)
putchar('.');
}
/* Mémorise l'ancien mot et son n° de ligne */
ancienneLigne = ligne;
ancienneColonne = colonne;
/* Pour de meilleures performances,
on bosse en double buffer plutot que recopier à chaque fois.*/
if(taillePrec != tailleBuff)
{
taillePrec = tailleBuff;
ReallocCharExit(&prec, taillePrec);
} assert(prec != NULL);
assert(taillePrec == tailleBuff);
SwapPtrChar(&prec, &buff);
}/*while*/
if(res < 0)
perror("get_word");
else
{
retour = 0; /* OK */
putchar('\n');
printf("Lu %d lignes.\n", ligne);
if(pNbLignes != NULL)
*pNbLignes = ligne;
}
/* Nettoyage */
free(concat), concat=NULL, tailleConcat=0;
free(prec), prec=NULL, taillePrec=0;
free(buff), buff=NULL, tailleBuff=0;
fclose(fdesc), fdesc=NULL;
}/*if fdesc*/
return retour;
}
/*
==============================================================================
Fonctions pour la génération des Nseq à partir des N-1seq.*/
/*----------------------------------------------------------------------------
Fonction de comparaison simple de coordonnées, non-utilisée.*/
int CompareCoord(ChainonCoord const *pcCoordLeft, ChainonCoord const *pcCoordRight)
{
/* Ordre de comparaison : D'abord ligne, puis colonne */
const int ligneLeft = GetLigne(pcCoordLeft);
const int ligneRight = GetLigne(pcCoordRight);
if(ligneLeft!=ligneRight)
return ligneLeft-ligneRight;
{
const int colonneLeft = GetColonne(pcCoordLeft);
const int colonneRight = GetColonne(pcCoordRight);
return colonneLeft-colonneRight;
}
}
/*----------------------------------------------------------------------------
Fonction de comparaison simple de coordonnées, spécialisée pour la jointure.
Attention, cette fonction-si n'est pas commutative (elle est asymétrique).*/
int CompareCoordEx(ChainonCoord const *pcCoordLeft, ChainonCoord const *pcCoordRight)
{
/* Ordre de comparaison : D'abord ligne, puis colonne avec décalage */
const int ligneLeft = GetLigne(pcCoordLeft);
const int ligneRight = GetLigne(pcCoordRight);
if(ligneLeft!=ligneRight)
return ligneLeft-ligneRight;
{
const int colonneLeft = GetColonne(pcCoordLeft) + 1; /*décalage*/
const int colonneRight = GetColonne(pcCoordRight);
return colonneLeft-colonneRight;
}
}
/*----------------------------------------------------------------------------
Fonction jointure des coordonnées.*/
void GenererNSeqPourMots(ChainonMot const *pcLeft, ChainonMot const *pcRight, TableHachageMot nSeq[])
{
/* Nous faisons ici un algorithme de merge-join pour avoir tous les nseq
en un seul parcours des deux listes. Comme tous les merge-join,
cela marche parce que les listes sont triées (ordre décroissant). */
ChainonCoord const * pcCoordLeft = coord_GetPremierC(GetPtrCoordC(pcLeft));
ChainonCoord const * pcCoordRight = coord_GetPremierC(GetPtrCoordC(pcRight));
/*int ligneLeft = GetLigne(pcCoordLeft);
int ligneRight = GetLigne(pcCoordRight);*/
while(pcCoordLeft!=NULL && pcCoordRight!=NULL)
{
while(pcCoordLeft!=NULL && CompareCoordEx(pcCoordLeft, pcCoordRight)>0)
pcCoordLeft = coord_GetNextC(pcCoordLeft);
if(pcCoordLeft==NULL)
break;
while(pcCoordRight!=NULL && CompareCoordEx(pcCoordLeft, pcCoordRight)<0)
pcCoordRight = coord_GetNextC(pcCoordRight);
if(pcCoordRight==NULL)
break;
if(CompareCoordEx(pcCoordLeft, pcCoordRight)==0)
{
/* On a trouvé un nSeq! */
InsertionDoubleHashEx2(nSeq, GetMot(pcLeft), GetMot(pcRight), GetLigne(pcCoordLeft), GetColonne(pcCoordLeft));
pcCoordLeft = coord_GetNextC(pcCoordLeft);
pcCoordRight = coord_GetNextC(pcCoordRight);
}
}
}
/*----------------------------------------------------------------------------
Fonction de génération principale des nseq. Cherche d'abord les séquences
qui se chevauchent parfaitement, puis appelle la fonction qui compare
les coordonnées.*/
void GenererTousNSeq(TableHachageMot const nMinusOneSeq[], TableHachageMot nSeq[], int iSeq)
{
size_t iDblHashLeft;
for(iDblHashLeft=0 ; iDblHashLeft < TAILLEHASH ; iDblHashLeft++)
{
size_t iHashLeft;
for(iHashLeft=0 ; iHashLeft < TAILLEHASH ; iHashLeft++)
{
ChainonMot const *pcLeft;
for(pcLeft=GetPremierC(&nMinusOneSeq[iDblHashLeft][iHashLeft]) ; pcLeft!=NULL ; pcLeft=GetNextC(pcLeft))
{
/* Rechercher tous les n-1seq dont les premiers mots sont les
mêmes que les non-premiers de celui-ci */
char const * pcSepar = strchr(GetMot(pcLeft), SEPARATEUR);
size_t iDblHashRight, iHashRight;
size_t cchLenEndOfLeft;
ChainonMot const *pcRight;
assert(pcSepar!=NULL);
pcSepar++;
iDblHashRight = hash_chaine(pcSepar);
cchLenEndOfLeft = strlen(pcSepar);
for(iHashRight=0 ; iHashRight<TAILLEHASH ; iHashRight++)
{
for(pcRight=GetPremierC(&nMinusOneSeq[iDblHashRight][iHashRight]) ; pcRight!=NULL ; pcRight=GetNextC(pcRight))
{
size_t cchLenRight = strlen(GetMot(pcRight));
if(cchLenRight>cchLenEndOfLeft
&& strncmp(pcSepar, GetMot(pcRight), cchLenEndOfLeft)==0
&& GetMot(pcRight)[cchLenEndOfLeft]==SEPARATEUR)
{
/* Les premiers mots de pcRight sont les non-premiers mots de pcLeft.
Il reste à parcourir les coordonnées maintenant.
Coup de chance, elles sont triées (ordre décroissant) */
assert(!coord_ListeEstVide(GetPtrCoordC(pcLeft)));
assert(!coord_ListeEstVide(GetPtrCoordC(pcRight)));
GenererNSeqPourMots(pcLeft, pcRight, nSeq);
}
}/*for pcRight*/
}/*for iHashRight*/
}/*for pcLeft*/
}/*for iHashLeft*/
if(iSeq==3)
putchar('.');
else if((iDblHashLeft+1)%PROG_NBHASH == 0)
putchar('.');
}/*for iDblHashLeft*/
putchar('\n');
}
/*----------------------------------------------------------------------------
D'inversion des listes de coordonnées,
pour corriger un effet secondaire du merge-join.*/
void InverserListesCoord(TableHachageMot DblTableHash[])
{
size_t i;
for(i = 0 ; i < TAILLEHASH; ++i)
{
size_t j;
for(j = 0 ; j < TAILLEHASH; ++j)
{
ChainonMot *p;
for(p=GetPremier(&DblTableHash[i][j]) ; p!=NULL ; p=GetNext(p))
coord_InverserListe(GetPtrCoord(p));
}
}
}
/*
==============================================================================
Fonctions pour l'élagage.*/
/*----------------------------------------------------------------------------
Crée une table de hachage suffixe pour l'élagage.*/
ListePtrMot * CreerTableHashSuffixe(TableHachageMot const nSeq[])
{
ListePtrMot * ret = ptr_CreerTableHachage();
size_t iDblHash;
for(iDblHash=0 ; iDblHash<TAILLEHASH ; iDblHash++)
{
size_t iHash;
for(iHash=0 ; iHash<TAILLEHASH ; iHash++)
{
ChainonMot const *pcNseq;
for(pcNseq = GetPremierC(&nSeq[iDblHash][iHash]) ; pcNseq!=NULL ; pcNseq=GetNextC(pcNseq))
{
ChainonPtrMot * nouveau = CreerPtrMotEx(pcNseq);
ptr_InsertionHash(ret, nouveau, HachagePtrMot);
}
}
}
return ret;
}
/*----------------------------------------------------------------------------
*/
int DoitElaguerPositionPrefixe(ChainonCoord const *pcMinusOneCoord, ChainonCoord const **ppcNseqCoord)
{
(void)pcMinusOneCoord;
(void)ppcNseqCoord;
/*Pour que ça corresponde en préfixe,
les coordonnées du nseq doivent être exactement égales à celles du n-1seq
Et je rappelle que les coordonnées sont triées par ordre décroissant.*/
/* Tant que Les Nseq sont supérieurs au N-1seq, on passe au Nseq suivant qui est plus petit. */
while(*ppcNseqCoord!=NULL && CompareCoord(pcMinusOneCoord, *ppcNseqCoord)<0)
*ppcNseqCoord = coord_GetNextC(*ppcNseqCoord);
if(*ppcNseqCoord!=NULL && CompareCoordEx(pcMinusOneCoord, *ppcNseqCoord)==0)
return 1;
return 0;
}
int DoitElaguerPositionSuffixe(ChainonCoord const *pcMinusOneCoord, ChainonCoord const **ppcNseqCoord)
{
(void)pcMinusOneCoord;
(void)ppcNseqCoord;
/*Pour que ça corresponde en suffixe,
les coordonnées du nseq doivent être de 1 supérieures à celles du n-1seq
Et je rappelle que les coordonnées sont triées par ordre décroissant.*/
/* Tant que Les Nseq sont supérieurs au N-1seq, on passe au Nseq suivant qui est plus petit. */
while(*ppcNseqCoord!=NULL && CompareCoordEx(*ppcNseqCoord, pcMinusOneCoord) < 0)
*ppcNseqCoord = coord_GetNextC(*ppcNseqCoord);
if(*ppcNseqCoord!=NULL && CompareCoord(*ppcNseqCoord, pcMinusOneCoord)==0)
return 1;
return 0;
}
void ElaguerPositionsPrefixe(ChainonMot *pMinusOne, ChainonMot const *pcNseqLeft)
{
ChainonCoord const *pcNseqCoord = coord_GetPremierC(GetPtrCoordC(pcNseqLeft));
ChainonCoord ** ppMinusOneCoord = NULL;
for(ppMinusOneCoord=coord_GetPtrPremier(GetPtrCoord(pMinusOne)) ; (*ppMinusOneCoord)!=NULL ; )
{
if(DoitElaguerPositionPrefixe(*ppMinusOneCoord, &pcNseqCoord))
{
ChainonCoord *pDel = coord_DetacherChainon(ppMinusOneCoord);
DetruireCoord(pDel);
SetNbLignes(pMinusOne, -1);
}
else
ppMinusOneCoord = coord_GetNextPtr(ppMinusOneCoord);
}
}
void ElaguerPositionsSuffixe(ChainonMot *pMinusOne, ChainonMot const *pcNseqRight)
{
ChainonCoord const *pcNseqCoord = coord_GetPremierC(GetPtrCoordC(pcNseqRight));
ChainonCoord ** ppMinusOneCoord = NULL;
for(ppMinusOneCoord=coord_GetPtrPremier(GetPtrCoord(pMinusOne)) ; (*ppMinusOneCoord)!=NULL ; )
{
if(DoitElaguerPositionSuffixe(*ppMinusOneCoord, &pcNseqCoord))
{
ChainonCoord *pDel = coord_DetacherChainon(ppMinusOneCoord);
DetruireCoord(pDel);
SetNbLignes(pMinusOne, -1);
}
else
ppMinusOneCoord = coord_GetNextPtr(ppMinusOneCoord);
}
}
/*----------------------------------------------------------------------------
À partir d'un n-1seq et des tables de hachage préfixe et suffixe,
nettoie le n-1seq et indique s'il doit être supprimé par l'élagage.*/
int DoitElaguer(ChainonMot *pMinusOne, TableHachageMot const nSeqLeft[], ListePtrMot const nSeqRight[])
{
/* La clé complète d'un n-1seq est la clé partielle des nseq qui commencent par lui */
size_t cchLen = strlen(GetMot(pMinusOne));
unsigned int iDblHash = hash_chaine(GetMot(pMinusOne));
unsigned int iRightHash = iDblHash;
{
unsigned int iHash;
for(iHash=0 ; iHash<TAILLEHASH ; iHash++)
{
ChainonMot const *pcNseq;
for(pcNseq = GetPremierC(&nSeqLeft[iDblHash][iHash]) ; pcNseq!=NULL ; pcNseq=GetNextC(pcNseq))
{
size_t cchNseqLeft = strlen(GetMot(pcNseq));
if(cchNseqLeft>cchLen
&& strncmp(GetMot(pMinusOne), GetMot(pcNseq), cchLen)==0
&& GetMot(pcNseq)[cchLen]==SEPARATEUR)
{
/* pMinusOne est inclus dans pcNseq. On nettoie ses positions... */
ElaguerPositionsPrefixe(pMinusOne, pcNseq);
}
}
}
}
{
ChainonPtrMot const *pcPtr;
for(pcPtr = ptr_GetPremierC(&nSeqRight[iRightHash]) ; pcPtr!=NULL ; pcPtr=ptr_GetNextC(pcPtr))
{
ChainonMot const *pcNseq = GetPtrMot(pcPtr);
if(strcmp(GetMot(pMinusOne), strchr(GetMot(pcNseq), SEPARATEUR)+1)==0)
{
/* pMinusOne est inclus dans pcNseq. On nettoie ses positions... */
ElaguerPositionsSuffixe(pMinusOne, pcNseq);
}
}
}
return coord_ListeEstVide(GetPtrCoordC(pMinusOne));
}
/*----------------------------------------------------------------------------
Fonction d'élagage principale.*/
void Elagage(TableHachageMot nMinusOneSeq[], TableHachageMot const nSeqLeft[], ListePtrMot const nSeqRight[])
{
size_t iDblMinusOne;
for(iDblMinusOne=0 ; iDblMinusOne<TAILLEHASH ; iDblMinusOne++)
{
size_t iMinusOne;
for(iMinusOne=0 ; iMinusOne<TAILLEHASH ; iMinusOne++)
{
ChainonMot ** ppMinusOne;
for(ppMinusOne=GetPtrPremier(&nMinusOneSeq[iDblMinusOne][iMinusOne]) ; (*ppMinusOne)!=NULL ; )
{
if(DoitElaguer(*ppMinusOne, nSeqLeft, nSeqRight))
{
ChainonMot *pDel = DetacherChainon(ppMinusOne);
DetruireChainon(pDel);
}
else
ppMinusOne = GetNextPtr(ppMinusOne);
}
}
}
}
/*
==============================================================================
Fonctions pour les règles.*/
#if 0
ListeMot * ChargerToutesTables(char const *langue, int maxSequence)
{
ListeMot * TableHash = CreerTableHachage();
ListeMot * retour = TableHash;
int iSeq;
for(iSeq=2 ; iSeq<=maxSequence ; iSeq++)
{
int res;
printf("Chargement des %dseq...\n", iSeq);
res = LireTableFichBinaire(TableHash, langue, iSeq);
printf("Resultat lecture : %d (%s).\n", res, (res>=0 ? "Succes" : "Echec"));
if(res < 0)
retour = NULL;
}
printf("%d sequences chargees en tout.\n", taille_table(TableHash));
/*Detruire en cas d'echec*/
if(retour==NULL)
DetruireTableHachage(TableHash, DetruireChainon);
return retour;
}
#endif
int const * ligne_GetPremierC(MotCompact const *pcMot, size_t *piLigne)
{
assert(piLigne!=NULL);
if(GetNbLignesCompact(pcMot)==0)
{
/*La liste est vide, rien à retourner.*/
*piLigne = 0;
return 0;
}
else
{
/*Liste non-vide: On retourne le premier élément
et on fait pointer *piLigne sur le second.*/
*piLigne = 1;
return GetLignesCompact(pcMot);
}
}
int const * ligne_GetNextC(MotCompact const *pcMot, size_t *piLigne)
{
if(*piLigne == (size_t)GetNbLignesCompact(pcMot))
return NULL;
else
{
int const *pcRet = GetLignesCompact(pcMot) + *piLigne;
(*piLigne)++;
return pcRet;
}
}
int NbLignesCommunes(MotCompact const *pcLeft, MotCompact const *pcRight)
{
int ret = 0;
/* Nous faisons ici un algorithme de merge-join pour trouver toutes
les lignes communes. Comme tous les merge-join,
cela marche parce que les listes sont triées (ordre décroissant). */
size_t iLigneLeft = 0;
size_t iLigneRight = 0;
int const * pcCoordLeft = ligne_GetPremierC(pcLeft, &iLigneLeft);
int const * pcCoordRight = ligne_GetPremierC(pcRight, &iLigneRight);
while(pcCoordLeft!=NULL && pcCoordRight!=NULL)
{
{
int ligneRight = *pcCoordRight;
while(pcCoordLeft!=NULL && (*pcCoordLeft)>ligneRight)
pcCoordLeft = ligne_GetNextC(pcLeft, &iLigneLeft);
}
if(pcCoordLeft==NULL)
break;
{
int ligneLeft = *pcCoordLeft;
while(pcCoordRight!=NULL && ligneLeft<(*pcCoordRight))
pcCoordRight = ligne_GetNextC(pcRight, &iLigneRight);
}
if(pcCoordRight==NULL)
break;
if(*pcCoordLeft == *pcCoordRight)
{
/* On a trouvé une ligne commune! */
ret++;
pcCoordLeft = ligne_GetNextC(pcLeft, &iLigneLeft);
pcCoordRight = ligne_GetNextC(pcRight, &iLigneRight);
}
}
return ret;
}
int SupportValide(FILE *pfOut, MotCompact const *pcLeft, MotCompact const *pcRight, int nbLignes, double confianceMin)
{
int lignesCommunes = NbLignesCommunes(pcLeft, pcRight);
int lignesLeft = GetNbLignesCompact(pcLeft);
//int lignesRight = GetNbLignesCompact(pcRight);
double supportLeft=lignesLeft, supportTotal = lignesCommunes;
//double supportRight=lignesRight;
// double supportLeft1= lignesLeft;
// double supportTotal1 = lignesCommunes;
double confiance;
//FILE* fout;
// char nomFich[FILENAME_MAX];
// int retour = -1;
//AssertAlways(lignesCommunes <= lignesLeft);
supportLeft /= nbLignes;
supportTotal /= nbLignes;
confiance = supportTotal / supportLeft;
if(confiance >= confianceMin)
{
return 1;
}
return 0;
}
void CalculerSupport(FILE *pfOut, MotCompact const *pcLeft, MotCompact const *pcRight, int nbLignes, double confianceMin)
{
int lignesCommunes = NbLignesCommunes(pcLeft, pcRight);
int lignesLeft = GetNbLignesCompact(pcLeft);
int lignesRight = GetNbLignesCompact(pcRight);
double supportLeft=lignesLeft, supportTotal = lignesCommunes;
double supportRight=lignesRight;
double supportLeft1= lignesLeft;
double supportTotal1 = lignesCommunes;
double confiance;
//FILE* fout;
// char nomFich[FILENAME_MAX];
// int retour = -1;
//AssertAlways(lignesCommunes <= lignesLeft);
supportLeft /= nbLignes;
supportTotal /= nbLignes;
confiance = supportTotal / supportLeft;
if(confiance >= confianceMin)
{
fprintf(pfOut, "\"%s\" -> \"%s\" : %lf, %lf\n", GetMotCompact(pcLeft), GetMotCompact(pcRight), supportTotal, confiance);
fprintf(fblue, "%s;%s;%.0f;%.0f;%.0f\n",GetMotCompact(pcLeft), GetMotCompact(pcRight), supportLeft1,supportRight, supportTotal1 );
// fclose(fout);
// retour = 0;
//}
}
}
int nbmots(char const lng[])
{
int i;
int nb=0;
int bEspace=0;
for(i=0 ; lng[i]!='\0' ; i++)
{
if (lng[i]!=' ' && !bEspace)
{
nb++;
bEspace=1;
}
if (lng[i]==' ')
bEspace=0;
}
return nb;
}
void DoubleParcoursTable(FILE *pfOut, MotCompact const pcMots1[], size_t nbMots1, MotCompact const pcMots2[], size_t nbMots2, int nbLignes, double confianceMin)
{
size_t const diviseur = (nbMots1/PROG_MAXREGLES)+1;
size_t iMot1;
int lemax=-1;
size_t iMot1_mx;
size_t iMot2_mx;
int ajout=0;
printf("(prog : sur %ld points)\n", (long)(nbMots1/diviseur));
for(iMot1=0 ; iMot1<nbMots1 ; iMot1++)
{
size_t iMot2;
lemax=-1;
ajout=0;
for(iMot2=2 ; iMot2<nbMots2 ; iMot2++)
{
// if (nbmots( GetMotCompact(pcMots2+iMot2) ) >= nbmots (GetMotCompact(pcMots1+iMot1) ))
//printf("%s , %d ------- %d , %s\n" ,GetMotCompact(pcMots1+iMot1),getNbMots( pcMots1+iMot1), getNbMots(pcMots2+iMot2 ),GetMotCompact(pcMots2+iMot2));
if (getNbMots(pcMots2+iMot2) >= getNbMots(pcMots1+iMot1 ))
{
ajout=1;
CalculerSupport(pfOut, pcMots1+iMot1, pcMots2+iMot2, nbLignes, confianceMin);
}
else
{
if ((getNbMots(pcMots2+iMot2)>lemax) & (SupportValide(pfOut, pcMots1+iMot1, pcMots2+iMot2, nbLignes, confianceMin)))
{
lemax=getNbMots(pcMots2+iMot2) ;
iMot1_mx=iMot1;
iMot2_mx=iMot2;
}
}
}
if (ajout==0 && lemax!=-1)
{
CalculerSupport(pfOut, pcMots1+iMot1_mx, pcMots2+iMot2_mx, nbLignes, confianceMin);
// printf("MAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
}
if(iMot1%diviseur == 0)
putchar('.');
}
putchar('\n');
}
int CalculerRegles(
char const *langue1, char const *langue2,
MotCompact const pcMots1[], size_t nbMots1,
MotCompact const pcMots2[], size_t nbMots2,
int nbLignes, double confianceMin
)
{
int retour = -1;
char nomFich[FILENAME_MAX];
// char nomFich1[FILENAME_MAX]="regleBlue.txt";
FILE *pfOut;
// FILE *fout;
if(snprintf(nomFich, ARRAYSIZE(nomFich), ".\\Regles%s%s.txt", langue1, langue2) >= ARRAYSIZE(nomFich))
return -1;
pfOut = fopen(nomFich, "w");
if(pfOut!=NULL)
{
// fout=fopen(nomFich1, "w");
//if(fout!=NULL)
//
//}
//fout=fopen("regleBlue.txt", "w");
printf("Calcul du support pour chaque couple %s->%s...\n", langue1, langue2);
DoubleParcoursTable(pfOut, pcMots1, nbMots1, pcMots2, nbMots2, nbLignes, confianceMin);
printf("Calcul termine.\n");
fclose(pfOut);
retour = 0;
//fclose(fout);
// if(fout!=NULL)
//
// fprintf(fout,"aaaaaaaaaaaa");
// fclose(fout);
}
else
{
perror("Sortie regles");
}
return retour;
}
/*
==============================================================================
Fonctions de haut niveau.*/
/*----------------------------------------------------------------------------
Retour: Comme le main() */
int TraiterFichier(TableHachageMot DblTableHash[], TableHachageMot DblTableHash2[], char const *langue, int *pNbLignes)
{
int bEnregistrementOK = 1;
int nbLignes = 0;
struct Chainon_fbtAllocator *pAlloc2seq = Chainon_CreateFbtAllocator(1000000);
struct Coord_fbtAllocator *pAllocCoord2seq = Coord_CreateFbtAllocator(1000000);
AfficherCarac(stdout, 79, '-');
printf("\nTraitement fichier pour langue : %s\n", langue);
if(pNbLignes != NULL)
*pNbLignes = 0;
SetAllocateurChainon(Chainon_FbtAllocToIface(pAlloc2seq));
SetAllocateurCoord(Coord_FbtAllocToIface(pAllocCoord2seq));
if(LireFichierEntree(langue, DblTableHash,DblTableHash2, &nbLignes)<0)
return EXIT_FAILURE;
/*EnregistrerTableCompleteFichBinaire(TableHash, langue, 2);*/
// {
// size_t *pStats = NULL;
// size_t nStats = 0;
// if(statistiques_double_table(DblTableHash, &pStats, &nStats)>=0)
// {
// #if 0
// size_t iStat;
// #endif
// printf("--- Statistiques de la table de hachage ---\n");
// while(nStats>0 && pStats[nStats-1]==0)
// nStats--;
// printf("Nb. de cases vides : %llu\n", (long long)pStats[0]);
// printf("Nb. maximum de collisions : %llu\n", (long long)nStats);
// #if 0
// for(iStat=0 ; iStat<nStats ; iStat++)
// {
// if(pStats[iStat]!=0)
// printf("%llu : %llu\n", (long long)iStat, (long long)(pStats[iStat]));
// }
// #endif
// putchar('\n');
// }
// free(pStats), pStats=NULL;
// }
if(pNbLignes != NULL)
*pNbLignes = nbLignes;
//
//for(i=0;i<TAILLEHASH;i++)
//{
//
// printf("%s",GetMot(DblTableHash[i]));
//}
printf("Calcul des nombres de lignes...\n");
//CalculerNombreLignesDoubleTable(DblTableHash);
//CalculerNombreLignesDoubleTable(DblTableHash2);
/*printf("La table de hachage avant le filtrage:\n");
dump_table(TableHash);*/
return (bEnregistrementOK ? EXIT_SUCCESS : EXIT_FAILURE);
}
/*----------------------------------------------------------------------------
Retour: Comme le main() */
int TraiterRegles(char const *langue1, char const *langue2, int nbLignes, int maxSequence1, int maxSequence2, double confianceMin, int m)
{
struct char_fbtAllocator *pAllocCaracs1=NULL, *pAllocCaracs2=NULL;
struct int_fbtAllocator *pAllocLignes1=NULL, *pAllocLignes2=NULL;
size_t *pTailles1=NULL, *pTailles2=NULL, nbMots1=0, nbMots2=0;
int retour = EXIT_FAILURE;
putchar('\n');
printf("eeeeeeeeeeee");
/*Initialisation des allocateurs */
{
size_t nbCaracs1=0, nbLignes1=0, nbCaracs2=0, nbLignes2=0;
if(CompterToutesTablesFichBinaire(&pTailles1, &nbCaracs1, &nbLignes1, langue1, maxSequence1)<0)
goto LNettoyage;
if(CompterToutesTablesFichBinaire(&pTailles2, &nbCaracs2, &nbLignes2, langue2, maxSequence2)<0)
goto LNettoyage;
nbMots1 = SommeTailles(pTailles1, maxSequence1);
nbMots2 = SommeTailles(pTailles2, maxSequence2);
pAllocCaracs1 = char_CreateFbtAllocator(nbCaracs1);
pAllocCaracs2 = char_CreateFbtAllocator(nbCaracs2);
if(pAllocCaracs1==NULL || pAllocCaracs2==NULL)
goto LNettoyage;
pAllocLignes1 = int_CreateFbtAllocator(nbLignes1);
pAllocLignes2 = int_CreateFbtAllocator(nbLignes2);
if(pAllocLignes1==NULL || pAllocLignes2==NULL)
goto LNettoyage;
}
{
MotCompact * pMots1 = LireToutesTablesFichBinaire(pTailles1, pAllocCaracs1, pAllocLignes1, langue1, maxSequence1, m);
MotCompact * pMots2 = LireToutesTablesFichBinaire1(pTailles2, pAllocCaracs2, pAllocLignes2, langue2, maxSequence2, m);
if(pMots1==NULL || pMots2==NULL)
{
DetruireTableauMotsCompacts(pMots1), pMots1=NULL;
DetruireTableauMotsCompacts(pMots2), pMots2=NULL;
goto LNettoyage;
}
/*Les tables de hachage complètes sont chargées*/
{
//CalculerRegles(langue1, langue2, pMots1, nbMots1, pMots2, nbMots2, nbLignes, confianceMin);
CalculerRegles(langue2, langue1, pMots2, nbMots2, pMots1, nbMots1, nbLignes, confianceMin);
}
DetruireTableauMotsCompacts(pMots1), pMots1=NULL;
DetruireTableauMotsCompacts(pMots2), pMots2=NULL;
retour = EXIT_SUCCESS;
}
/*Je n'aime pas utiliser des goto, mais là ça devenait indispensable*/
LNettoyage:
free(pTailles1), pTailles1=NULL;
free(pTailles2), pTailles2=NULL;
char_DestroyFbtAllocator(pAllocCaracs1), pAllocCaracs1=NULL;
char_DestroyFbtAllocator(pAllocCaracs2), pAllocCaracs2=NULL;
int_DestroyFbtAllocator(pAllocLignes1), pAllocLignes1=NULL;
int_DestroyFbtAllocator(pAllocLignes2), pAllocLignes2=NULL;
return retour;
}
/*----------------------------------------------------------------------------
Fonction d'analyse de la ligne de commande*/
#ifdef _MSC_VER
/*Contrairement au C++, le standard C ne supporte pas la conversion
type** -> type const*const*
Visual la supporte en tant qu'extension */
void LigneCommande(int argc, char const * const argv[], double *pSMin, double *pCMin)
#else
void LigneCommande(int argc, char *argv[], double *pSMin, double *pCMin)
#endif
{
int iArg;
for(iArg=1 ; iArg<argc ; iArg++) /*Commence à 1 pour sauter l'exe*/
{
char const *Arg = argv[iArg];
if(strcmp(Arg, "-s")==0)
{
/* Support minimal */
char const *Arg2 = NULL;
iArg++;
if(iArg>=argc)
break;
Arg2 = argv[iArg];
*pSMin = strtod(Arg2, NULL);
}
else if(strcmp(Arg, "-c")==0)
{
/* Confiance minimale */
char const *Arg2 = NULL;
iArg++;
if(iArg>=argc)
break;
Arg2 = argv[iArg];
*pCMin = strtod(Arg2, NULL);
}
}
}
//
void TraiterCoupleMots(ChainonMot const *pc, ChainonMot const *pc2,FILE *fout,int nbligne)
{
ChainonCoord const *pcCoord;
ChainonCoord const *pcCoord2;
double im=0;
for(pcCoord = coord_GetPremierC(GetPtrCoordC(pc)) ; pcCoord!=NULL ; pcCoord=coord_GetNextC(pcCoord))
{
for(pcCoord2 = coord_GetPremierC(GetPtrCoordC(pc2)) ; pcCoord2!=NULL ; pcCoord2=coord_GetNextC(pcCoord2))
{
if((GetLigne(pcCoord2)==GetLigne(pcCoord)))
{
//Ŝ fprintf (fout,"anneen");
fprintf(fout, "%s ", GetMot(pc));
fprintf(fout,"->");
fprintf(fout,"%s", GetMot(pc2));
//LC=nbdrLignesCommunes(pc,pc2);
im=info_mut(pc,pc2,nbligne);
fprintf(fout,"%lf \n",im);
// printf("%d",im);
}
break;
}
}
}
void TraiterCoupleMots1(ChainonMot const *pc, ChainonMot const *pc2,FILE *fout,int nbligne,TableHachageMot *T1,TableHachageMot *T2)
{
ChainonCoord const *pcCoord;
ChainonCoord const *pcCoord2;
double imc=0;
for(pcCoord = coord_GetPremierC(GetPtrCoordC(pc)) ; pcCoord!=NULL ; pcCoord=coord_GetNextC(pcCoord))
{
for(pcCoord2 = coord_GetPremierC(GetPtrCoordC(pc2)) ; pcCoord2!=NULL ; pcCoord2=coord_GetNextC(pcCoord2))
{
if((GetLigne(pcCoord2)==GetLigne(pcCoord)))
{
//Ŝ fprintf (fout,"anneen");
fprintf(fout, "%s ", GetMot(pc));
fprintf(fout,"->");
fprintf(fout,"%s", GetMot(pc2));
//LC=nbdrLignesCommunes(pc,pc2);
imc=info_mut_cond(pc,pc2,nbligne,T1,T2);
fprintf(fout,"%lf \n",imc);
}
break;
}
}
}
int nbrLignesCommunes(ChainonMot const * pc,ChainonMot const * pc2)
{
/* Permettra de parcourir les deux liste (FR et AN) */
ChainonCoord const *pcCoord;
ChainonCoord const *pcCoord2;
/* Permet de verifier si le numero de la ligne n'est pas deja compter dans la solution */
size_t k;
/* Tableau dynamique */
struct tableauDynamique_int lignesCommunes;
TableauDynamique_int_ctor0(&lignesCommunes);
for(pcCoord = coord_GetPremierC(GetPtrCoordC(pc)) ; pcCoord!=NULL ; pcCoord=coord_GetNextC(pcCoord))
{
for(pcCoord2 = coord_GetPremierC(GetPtrCoordC(pc2)) ; pcCoord2!=NULL ; pcCoord2=coord_GetNextC(pcCoord2))
{
if (GetLigne(pcCoord) == GetLigne(pcCoord2))
{
/* Se comportera comme un booleen */
int bNouvelleLigne = 1;
//
// /* On va chercher a savoir si la ligne est deja presente */
for (k=0 ; k<lignesCommunes.taille ; k++)
{
if (lignesCommunes.tab[k] == GetLigne(pcCoord))
bNouvelleLigne = 0;
}
//
if (bNouvelleLigne)
{
int retAjout = TableauDynamique_int_ajouter(&lignesCommunes, GetLigne(pcCoord));
if(retAjout < 0)
{
printf ("Probleme lors du realloc !");
exit(1);
}
}
}
}/*for*/
}/*for*/
{
int nombreDeSolutions = (int)lignesCommunes.taille;
TableauDynamique_int_dtor(&lignesCommunes);
return nombreDeSolutions;
}
}
int nombreLigne(ChainonMot const *pc)
{
ChainonCoord const *pcCoord;
int annex=0;
int nbrLigne=-1;
for(pcCoord = coord_GetPremierC(GetPtrCoordC(pc)) ; pcCoord!=NULL ; pcCoord=coord_GetNextC(pcCoord))
{
if ((GetLigne(pcCoord)!=annex))
{
nbrLigne++;
annex=GetLigne(pcCoord);
}
}
return nbrLigne;
}
double probabilit(ChainonMot const *pc, ChainonMot const *pc2,int nblignes)
{
double p=0;
p=nbrLignesCommunes(pc,pc2)/nblignes;
return p;
}
// ChainonMot * permutCharToChainon(char *m,TableHachageMot *t)
// {
// int i,j;
//
// for( i=0;i<TAILLEHASH;i++)
// {
// for(j=0;j<TAILLEHASH;j++)
// {
// ChainonMot const *pc2;
// ChainonMot const *pc;
// for(pc2=GetPremierC(&t[i][j]) ; pc2!=NULL ; pc2=GetNextC(pc2))
// {
// if(GetMot(pc2)==m)
// {
// pc= pc2;
// }
// break;
// }
//
// }
// }
//
//return pc2;
//
//
//
// }
double info_mut_cond(ChainonMot const *pc, ChainonMot const *pc2,int nblignes,TableHachageMot *t1,TableHachageMot *t2)
{
double IM=0;
char const *mot;
char const *mot1 = malloc (sizeof (*mot1) * 256);
char const *mot2 = malloc (sizeof (*mot2) * 256);
ChainonMot const *m1;
mot=GetMot(pc);
sscanf(mot,"%s %s",mot1,mot2);
//printf("%s \n",mot1);
{
ChainonMot const *m;
m= RechercheDoubleHashExC(t1, mot1);
}
IM = (nbrLignesCommunes(pc,pc2)/((double)nblignes))*log2((nombreLigne(pc2)/((double)nblignes))*(nbrLignesCommunes(pc,pc2)/((double)nblignes)));
//printf("%f\n",IM);
//printf("%lf",log2((nbrLignesCommunes(pc,pc2)/((double)nblignes)) / (nombreLigne(pc)*nombreLigne(pc2))));
return IM;
}
double info_mut(ChainonMot const *pc, ChainonMot const *pc2,int nblignes)
{
double IM=0;
IM = (nbrLignesCommunes(pc,pc2)/((double)nblignes))*log2((nbrLignesCommunes(pc,pc2)/((double)nblignes)/ ((nombreLigne(pc)/((double)nblignes))*nombreLigne(pc2)/((double)nblignes))));
// IM = (nbrLignesCommunes(pc,pc2)/((double)nblignes));
// IM= (nombreLigne(pc));
return IM;
}
/*----------------------------------------------------------------------------
Le main()*/
int main(int argc, char *argv[])
{
ChainonMot const *pc;
ChainonMot const *pc2;
ChainonMot const *p;
int i,j,k,l;
int freq=0;
TableHachageMot *DblTableHash1en =CreerDoubleTableHachage();
TableHachageMot *DblTableHash2en =CreerDoubleTableHachage();
TableHachageMot *DblTableHash1fr =CreerDoubleTableHachage();
TableHachageMot *DblTableHash2fr =CreerDoubleTableHachage();
int nbLignes1;
ChainonCoord const *pcCoord;
//, nbLignes2=0;
// int m;
// int maxSequence1=0, maxSequence2=0;
//time_t timeBegin = time(NULL);
// time_t timeEndLecture1, timeEndLecture2, timeEndRegles;
// long diffTime = 0;
// printf("donner longueur maximale de la sequence en anglais\n");
// scanf("%ld", &m);
#ifdef _MSC_VER
{
int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
tmpFlag |= _CRTDBG_CHECK_ALWAYS_DF;
_CrtSetDbgFlag( tmpFlag );
}
#endif
// LigneCommande(argc, argv, &supportMin, &confianceMin);
// printf("Support minimum pour filtrage : %lf\n", supportMin);
// printf("Confiance minimum pour regles : %lf\n", confianceMin);
//#if 1
if(TraiterFichier(DblTableHash1en, DblTableHash2en, "en", &nbLignes1)!=EXIT_SUCCESS)
return EXIT_FAILURE;
for(i=0;i<TAILLEHASH;i++)
{
for(j=0 ; j<TAILLEHASH ; j++)
{
ChainonMot const *pc;
for(pc=GetPremierC(&DblTableHash1en[i][j]) ; pc!=NULL ; pc=GetNextC(pc))
{
printf("%s \n",GetMot(pc));
for(pcCoord = coord_GetPremierC(GetPtrCoordC(pc)) ; pcCoord!=NULL ; pcCoord=coord_GetNextC(pcCoord))
{
printf("%i %i \n",GetLigne(pcCoord), j);
}
}
}/*for j*/
}/*for i*/
{
ChainonMot const * pc = RechercheDoubleHashExC(DblTableHash1en, "bonjour");
if(pc == NULL)
puts("Non trouve!");
else
printf("Mot trouve: %s\n", GetMot(pc));
}
// timeEndLecture1 = time(NULL);
// diffTime = (long)(timeEndLecture1-timeBegitf(n);
// printf("Temps de lecture : %ld'%02ld\"\n", diffTime/60, diffTime%60);
if(TraiterFichier(DblTableHash1fr, DblTableHash2fr, "fr", &nbLignes1)!=EXIT_SUCCESS)
return EXIT_FAILURE;
//
// timeEndLecture2 = time(NULL);
// diffTime = (long)(timeEndLecture2-timeEndLecture1);
// printf("Temps de lecture : %ld'%02ld\"\n", diffTime/60, diffTime%60);
// diffTime = (long)(timeEndLecture2-timeBegin);
// printf("Temps ecoule : %ld'%02ld\"\n", diffTime/60, diffTime%60);
// #else
// nbLignes1 = 596831;
// nbLignes2 = nbLignes1;
// maxSequennce1 = 11;
// maxSequence2 = 13;
// #endif
//
// if(nbLignes1 != nbLignes2)
// {
// fprintf(stderr,
// "Les fichiers n'ont pas le meme nombre de lignes! (%d vs %d)\n",
// nbLignes1, nbLignes2
// );
// return EXIT_FAILURE;
// }
//
printf("génération des triggers inter-langues \n");
printf("ouverture du fichier... \n");
////char nomFich[FILENAME_MAX];
// //FILE *pfOut;
{
FILE *pfOut = fopen("triggers.txt", "w");
//
for(i=0 ; i<TAILLEHASH ; i++)
{
for(j=0 ; j<TAILLEHASH ; j++)
{
ChainonMot const *pc;
for(pc=GetPremierC(&DblTableHash1fr[i][j]) ; pc!=NULL ; pc=GetNextC(pc))
{
for(k=0 ; k<TAILLEHASH ; k++)
{
for(l=0 ; l<TAILLEHASH ; l++)
{
ChainonMot const *pc2;
for(pc2=GetPremierC(&DblTableHash1en[k][l]) ; pc2!=NULL ; pc2=GetNextC(pc2))
{
TraiterCoupleMots(pc, pc2, pfOut, nbLignes1);
}
}/* for l*/
}/*for k*/
}
}/*for j*/
}/*for i*/
fclose(pfOut);
}
////pfOut = fopen("triggers.txt", "a");
////for(i=0 ; i<TAILLEHASH ; i++)
////{
//// for(j=0 ; j<TAILLEHASH ; j++)
//// {
//// //ChainonMot const *pc;
//// for(pc=GetPremierC(&DblTableHash2fr[i][j]) ; pc!=NULL ; pc=GetNextC(pc))
//// {
//// for(k=0 ; k<TAILLEHASH ; k++)
//// {
//// for(l=0 ; l<TAILLEHASH ; l++)
//// {
//// ChainonMot const *pc2;
//// for(pc2=GetPremierC(&DblTableHash1en[k][l]) ; pc2!=NULL ; pc2=GetNextC(pc2))
//// {
////
////
//// TraiterCoupleMots1(pc, pc2,pfOut,nbLignes1,&DblTableHash2fr,&DblTableHash1en);
//// }
//// }
//// }
//// }
////}
////}
////fclose(pfOut);
//
//}
//}
//
//for(pcMot = GetPremierC(pListe) ; pcMot!=NULL ; pcMot =GetNextC(pcMot))
//{
// printf("%s", GetMot(pcMot));
//}
//fblue = fopen("regles.txt", "w");
//
// if(TraiterRegles("en", "fr", nbLignes1, maxSequence1, maxSequence2, confianceMin, m)!=EXIT_SUCCESS)
// return EXIT_FAILURE;
//
// fclose(fblue);
//
// timeEndRegles = time(NULL);
// diffTime = (long)(timeEndRegles-timeEndLecture2);
// printf("Temps de calcul : %ld'%02ld\"\n", diffTime/60, diffTime%60);
// diffTime = (long)(timeEndRegles-timeBegin);
// printf("Temps ecoule : %ld'%02ld\"\n", diffTime/60, diffTime%60);
return EXIT_SUCCESS;
}
/*int maxpos(MotCompact const pcMots2[])
{
int maxpos1;
size_t iMot2;
size_t nbMots2;
size_t max =0 ;
for(iMot2=1 ; iMot2<nbMots2 ; iMot2++)
{
// printf("aa");
// printf("%d", nombreMot(GetMotCompact(pcMots2+iMot2)));
// if(nombreMot(GetMotCompact(pcMots2[i]))>nombreMot(GetMotCompact(max)))
//if((nombreMot(GetMotCompact(pcMots2+iMot2)))> (nombreMot(GetMotCompact(pcMots2+iMot2))))
{
printf("bb");
//maxpos1 = iMot2;
}
}
return maxpos1;
}
*/ |
Partager