Pb de compilation code C table hachage

stroumpf -  
stroumpf Messages postés 292 Statut Membre -
Bonjour,
j'ai un probleme
mon programme: creer une table de hachage afiin de stocker des liste d'information




typedef struct L {
char mot[100];
char donnee[100];
struct L *next;
}Liste;



struct HashTable {
int mod; // Nombre d'éléments de la table
Liste *table; // Pointeur sur la table allouée
};




// déclaration des fonctions


unsigned hash_cle(char *chaine);
int fonctHachage(liste_mot* );
void hashTableInit(HashTable ht, int mod);

void hashTableInit(HashTable& ht, int mod)
{
// Nombre d'éléments de la table
ht.mod = mod;

// Allocation de la table
if ((ht.table = (Liste*) malloc(mod * sizeof(Liste))) == 0) {
fprintf(stderr, "Plus de mémoire\n");
exit(1);
}

// Initialisation de la table
// Au début toutes les listes sont vides
for (int i = 0; i < mod; i++)
ht.table[i] = 0; // Liste vide là il ya l'erreur 1
}

// Affichage complet d'une table de hachage
void hashTablePrint(HashTable& ht)
{
for (int i = 0; i < ht.mod; i++)
//if (ht.table[i] != 0) {
// printf("Entrée %d\n", i);
listePrint(ht.table[i]);
}


void listePrint(Liste l)
{
while (l != NULL) {
printf("%d : %s", l->mot, l->donnee);
l = l->next;
}
}





Bon il ya 8 erreure ;):
1- no match for 'operator=' in '*(ht->HashTable::table + (+(((unsigned int)i) * 204u))) = 0'


aidez moi svp
merci
A voir également:

29 réponses

stroumpf
 
help pliiiiiiiiiiiz
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
Salut,

Liste *table; // Pointeur sur la table allouée

Pour déclarer ta table de hachage tu dois la declarer comme pointeur de pointeurs

Pourquoi?
Puisque en fait la table de hachage chaînée est un tableau de listes chaînées
Donc chaque élément de tableau doit être un pointeur sera la tête de la chaîné.

Je suis un peu occupé pour le moment, mais je vais t'écrire un p'tit exemple jusqu'à demain matin pour que tu comprennes mieux ;-)

Dans mon exemple je lirai un fichier et je vais insérer tout les mots de ce fichier dans une table de hachage.

A plus tard ;-)
0
stroumpf
 
ok merci beaucoup LAMI
a+
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
Je te laisse comprendre tout seul ;-)
Je n'ai pas gérer les doublons, donc il sont accepté
Je n'ai pas écrit non plus une gestion des erreurs
Fin bref, ce n'est qu'un exemple banal pour te faire comprendre, mais loin d'être une implémentation efficace ;-)

1. Le fichier qu'on va importer dans la table de hash
lami20j@debian:~/trash$ cat stroumpf.txt
Bonjour
j'ai un probleme
mon programme creer une table de hachage afiin de stocker des liste d'information
2 Le fichier .h
/* table_hash.h */

#ifndef TABLE_HASH
#define TABLE_HASH

typedef struct E{
        char mot[100];
        struct E *suivant;
}Liste;

Liste *InsertionEnTete(Liste *L,char *mot);
void AfficherListe(Liste *L);
void AfficheMot(char *mot);
unsigned int hash_cle(char *mot);
void AfficherTableHash(Liste **TableHash);
unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot);

#endif
3 Le fichier .c
/* table_hash.c */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#include "table_hash.h"
#define TAILLEHASH 307
int main()
{
  FILE *F;
  char mot[100];
  int i;
  unsigned int cle;

  Liste **TableHash;
  TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *));
  for(i=0;i<TAILLEHASH;++i)
    TableHash[i] = NULL;

  F=fopen("stroumpf.txt","r");

  while(fscanf(F,"%s",mot)==1){
    cle = hash_cle(mot);
    TableHash[cle] = InsertionEnTete(TableHash[cle],mot);
  }
  AfficherTableHash(TableHash);

  printf("Chercher mot : ");
  scanf("%s",mot);
  if(cle = ChercherMotDansTableHash(TableHash,mot))
    printf("%s existant dans le conteneur %u\n",mot,hash_cle(mot));
  else
    printf("%s inexistant dans la table de hash\n");
  return 0;
}

Liste *InsertionEnTete(Liste *L,char *mot){
  Liste *nouveau;
  nouveau = (Liste *) malloc (sizeof(Liste));
  strcpy(nouveau->mot,mot);
  nouveau->suivant = L;
  return nouveau;
}

void AfficherListe(Liste *L){
  Liste *p;
  for(p=L;p!=NULL;p=p->suivant)
    AfficheMot(p->mot);
  printf("\n");
}

void AfficheMot(char *mot){
  printf("%s ",mot);
}

unsigned int hash_cle(char *mot){
  unsigned int val = 0;
  for(;*mot!='\0';++mot)
    val = *mot + 31 * val;
  return val % TAILLEHASH;
}

void AfficherTableHash(Liste **TableHash){
  int i;
  for(i=0;i<TAILLEHASH;++i)
    if(TableHash[i] != NULL){
      printf("Conteneur %d : ",i);
      AfficherListe(TableHash[i]);
      printf("-------------------------------------------------\n");
    }
}

unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot){
  
  Liste *p;
  unsigned int cle;
  
  cle = hash_cle(mot);
  for(p=TableHash[cle];p!=NULL;p=p->suivant)
    if(strcmp(p->mot,mot)==0)
      return 1;
  return 0;
}

4. Compilation est exécution
lami20j@debian:~/trash$ gcc -o table_hash table_hash.c
lami20j@debian:~/trash$ ./table_hash
Conteneur 45 : creer
-------------------------------------------------
Conteneur 49 : hachage
-------------------------------------------------
Conteneur 51 : afiin
-------------------------------------------------
Conteneur 53 : un
-------------------------------------------------
Conteneur 99 : d'information
-------------------------------------------------
Conteneur 109 : table
-------------------------------------------------
Conteneur 111 : j'ai
-------------------------------------------------
Conteneur 126 : probleme
-------------------------------------------------
Conteneur 131 : de de
-------------------------------------------------
Conteneur 167 : stocker
-------------------------------------------------
Conteneur 185 : des
-------------------------------------------------
Conteneur 193 : programme
-------------------------------------------------
Conteneur 209 : une
-------------------------------------------------
Conteneur 236 : mon
-------------------------------------------------
Conteneur 244 : Bonjour
-------------------------------------------------
Conteneur 306 : liste
-------------------------------------------------
Chercher mot : stocker
stocker existant dans le conteneur 167
lami20j@debian:~/trash$ ./table_hash
Conteneur 45 : creer
-------------------------------------------------
Conteneur 49 : hachage
-------------------------------------------------
Conteneur 51 : afiin
-------------------------------------------------
Conteneur 53 : un
-------------------------------------------------
Conteneur 99 : d'information
-------------------------------------------------
Conteneur 109 : table
-------------------------------------------------
Conteneur 111 : j'ai
-------------------------------------------------
Conteneur 126 : probleme
-------------------------------------------------
Conteneur 131 : de de
-------------------------------------------------
Conteneur 167 : stocker
-------------------------------------------------
Conteneur 185 : des
-------------------------------------------------
Conteneur 193 : programme
-------------------------------------------------
Conteneur 209 : une
-------------------------------------------------
Conteneur 236 : mon
-------------------------------------------------
Conteneur 244 : Bonjour
-------------------------------------------------
Conteneur 306 : liste
-------------------------------------------------
Chercher mot : ccm
ccm inexistant dans la table de hash

0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
Salut,

Pour éviter les doublons il suffit de faire une p'tite modification

Au lieu de
while(fscanf(F,"%s",mot)==1){
cle = hash_cle(mot);
TableHash[cle] = InsertionEnTete(TableHash[cle],mot);
}


mets
  while(fscanf(F,"%s",mot)==1){
    cle = hash_cle(mot);
    if(! ChercherMotDansTableHash(TableHash,mot))
      TableHash[cle] = InsertionEnTete(TableHash[cle],mot);
  }

0
stroumpf
 
merci Lami, je v esayer et je v te dire le resultat. merci lé gentilllll ;)
0
stroumpf Messages postés 292 Statut Membre 2
 
Merci Lami;
en fait moi je dispose d'un fichier texte,
1- jai reuusii a extraire tous le mots du texte avec leurs informations (position dans la ligne, num ligne) et les mettre dans des listes chaines.
2- jai elliminéé de cette liste tous les mots qui sonr des bruits(probleme de frequence) : là c bon
3- là je veux stocker tous les mots de la listes chaines ainsi que leurs infos danns une table de hachage et afficher la table de hachage; Donc a cette étape il maffiche seulement le dernier mot( je sais pas pourqui si c un pb de stockage dans la liste ou un pb d'affichage)Ben c tt


#include <stdio.h> 
#include <stdlib.h> 
#include<string.h> 
#include "table_hash.h"
#define TAILLEMAX 1000 //tableau de taille 1000 
#define TAILLEHASH 307






typedef struct position
{
   struct position *next;
   int ligne;
   int pos;
} coordonne;


typedef struct queue
{
   struct queue *next;
   char *mot;
    coordonne *cord;
} liste_mot;














// déclaration des fonctions 
void Affiche_mot (char*); // fonction à supprimer
void Affiche_mots (liste_mot* );
void Trouver_mots (liste_mot** ,char* );
void Placer_mots (liste_mot** , char* , int , int );
coordonne *new_cord (int,int);
liste_mot *new_mot (char*, int , int p);
void ajout_cord (coordonne * , int l, int p);
void ajout_mot (liste_mot* , char* , int , int p);
void frequent( liste_mot **s , int mc);
unsigned hash_cle(char *chaine);
int fonctHachage(liste_mot* );
int nbr_mot(liste_mot* );
Liste *InsertionEnTete(Liste *L,liste_mot*);




//////////////////////////////////
////fonction principale: main ////
//////////////////////////////////
int main(int argc, char *argv[]) 
{ char c;
int A;
int val;
 Liste **TableHash;
 char* mot;
    liste_mot* s =NULL;
 
    
    Trouver_mots (&s,"C:\\Users\\document\\Documents\\text.txt" );
    Affiche_mots(s);
    printf("\n\n la liste filtree \n\n");
    frequent( &s , 1);
    Affiche_mots(s);
    val=fonctHachage(s);
    //calcul_nbre_mot(s);
   // printf("%d",A); 
  // allocation de hash table
  mot=s->mot;
  TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *));
 // initialisation de hash table
  for(int i=0;i<TAILLEHASH;++i)
    TableHash[i] = NULL;
//while (s!=NULL)
//{  
  //fonction de hachage
  
  
  //inserer dans la table de hachage
   TableHash[val]=InsertionEnTete(TableHash[val],s); 
 
   printf("%s", TableHash[val],"\n");

//printf("%d", val,"\n");

//s=s->next;
//}

   A=nbr_mot(s);

  
    scanf("%c",c);
    return 0; 
} 
//////////////////////////////////////
////l'implémentation des fonctions////
//////////////////////////////////////

 
Liste *InsertionEnTete(Liste *L,liste_mot* s){
  
  Liste *nouveau;
 
  nouveau = (Liste *) malloc (sizeof(Liste));
  while (s!=NULL)
  {
  strcpy(nouveau->mot,s->mot);
  
  nouveau->suivant = L;

  s=s->next;
  }
   
  return nouveau;
}




/**fonction d'allocation de la table de hachage: retour d'une structure de type table_hachage ****/


int fonctHachage(liste_mot* s)
{   int val;
    liste_mot* m=s;
    char *mot;
 
    while(m!=NULL)
    {
       mot=m->mot;
       val = hash_cle(mot);
       m=m->next;
      printf("\n%d\n", val);
    }
   
        return(val);
}




int nbr_mot(liste_mot* s)
{
    int n=0;
    liste_mot* m=s;
     while(m!=NULL)
    {
                   n++;
         m=m->next;
       
    }       
     printf("\n%d\n", n);    
   
}



unsigned hash_cle(char *chaine){
        unsigned i;
        for(i=0;*chaine != '\0';++chaine)
                i = *chaine + 31 * i;
        return i%TAILLEMAX;
}




////// fonction pour l'affichage de la liste des mots //////
void Affiche_mots (liste_mot* s) 
{ 
  liste_mot* m=s;
  coordonne* c=NULL; 
  int i =0,j;
  int N=0;
  while(m!=NULL) 
  { 
    
    printf("%s: ",m->mot); 
    c=m->cord;
    while(c!=NULL) 
    { 
      printf("(%d,%d)", c->ligne, c->pos);  
      c=c->next;
    }
    m=m->next;
    printf("\n");  
  } 
  
}
//////// fonction qui retourne le nombre de mots///////////////


void frequent( liste_mot **s , int mc)
{
     liste_mot* m=*s;
     liste_mot* prev=*s;
     coordonne* c=NULL;
     int sup, lig=0;
     while(m!=NULL) 
     {
         c=m->cord;
         sup=0;
         lig=0;
         while (c!=NULL)     
         {
               if (c->ligne > lig)
               {
                   sup++;
                   lig= c->ligne;                                   
               }
               c=c->next;
         } 
         if (sup>mc) 
         {
            prev=m;         
            m=m->next;
            // c bon          
         }else
         {
              if (prev==m) // cas du première mot
                 {
                    *s=m->next;
                    prev=m->next;
                 }
              else
                 prev->next=m->next;
            m=m->next;
          // on supprime le mot    
         }                 
     }
}

     




////// fonction pour rechercher des mot dans le fichier //////
void Trouver_mots (liste_mot** s,char* path) 
{
  FILE* fichier =NULL; 
  char chaine [TAILLEMAX ]=" "; // chaine vide de taille TAILLEMAX 
  fichier =fopen(path,"r"); 
  int p,l=0;
  
  if (fichier !=NULL) 
  { 
    printf("ouverture de fichier !!\n");
    while(fgets(chaine, TAILLEMAX, fichier)!=NULL)//on lit maximum TAILLEMAX caractere du fichier , on stoke le tout dans "chaine"
    { 
      if(s!=NULL) 
      { 
        l++; p=0; // la ligne et la position
        int length=strlen(chaine); 
        int i=0,j, x=0, len=0; 
        while(i<length) 
          { 
              if((chaine[i]!= ' ') && (chaine[i]!='\n')&& (chaine[i]!='.'))  // si c'est une caractère
              { 
                 len++;
              }        
              else 
              {
                   if (len>1) // on a un mots
                   {     p++; //position dans la ligne
                        char* m = (char*)malloc(len+1);  //un nouveau mot
                        for (j=0; j<len ; j++)
                         {
                            *(m+j) = chaine[x+j];
                         }
                         *(m+len)='\0';
                          
                        //  printf("%s\n", m); //on affiche le mot
                         Placer_mots(s,m,l,p); // on place le mot dans la liste
                   }
                   x=i+1; // debut de mot suivant
                   len=0; // langeur initial de mot suivant
              }         
              i++; 
          } 
      }  
     }
    fclose (fichier); 
  }
  else
       printf("erreur d'ouverture de fichier !!\n");      
}

////// fonction pour inserer le mot trouvé dans la liste //////
void Placer_mots (liste_mot** s, char* m, int l, int p) 
{
  if (*s==NULL) // si la liste est vide
  {  
     *s=new_mot(m,l,p);
  }
  else // si la liste n'est pas vide on cherche à inserer le mot
  {  
     liste_mot* lm=*s;
     liste_mot* prev=NULL;
     char ok='n';
     while((lm!=NULL) && (ok=='n'))
     { 
        if (strcmp(lm->mot,m)==0) //si le mot existe, on ajoute juste les nouveaux coordonnées
        { 
          ajout_cord(lm->cord,l,p);
          ok='y';
        }
        prev=lm;
        lm=lm->next;
    } 
    if (ok=='n') // si on a pas trouver le mot, on l'ajoute à la fin
     { 
       ajout_mot(prev,m,l,p);
     }
  }
}

////// fonction pour initialiser les coordonnees //////
coordonne * new_cord (int l,int p) 
{
  coordonne * tmp = (coordonne *)malloc (sizeof (coordonne));
   tmp->ligne=l;
   tmp->pos=p;
   tmp->next=NULL;
   return tmp;
}

//////fonction pour initialiser un mot avec ces coordonnées initials //////
liste_mot * new_mot (char* m, int l, int p) 
{
  liste_mot * tmp = (liste_mot *)malloc (sizeof (liste_mot));
  tmp->mot=m;
  tmp->cord=new_cord(l,p);
  tmp->next=NULL;
  return tmp;
}

////// fonction pour inserer des nouveaux coordonnées //////
void ajout_cord (coordonne * cord, int l, int p) 
{
  coordonne *c=cord;
  while (c->next!=NULL) // on boucle jusqu'à la fin de la liste
  {
    c=c->next;   
  }
  coordonne * tmp = (coordonne *)malloc (sizeof (coordonne)); // on ajoute un nouveau coordonnée
  tmp->ligne=l;
  tmp->pos=p;
  tmp->next=NULL;
  c->next=tmp;
}

////// fonction pour ajouter une nouvelle mot apres le mot indéxé par 'lm' //////
void ajout_mot (liste_mot* lm, char* m, int l, int p) 
{
  liste_mot * tmp = (liste_mot *)malloc (sizeof (liste_mot));
  tmp->mot=m;
  tmp->cord=new_cord(l,p);
  tmp->next=NULL;
  lm->next=tmp;
}     



0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
Salut,

là je veux stocker tous les mots de la listes chaines ainsi que leurs infos danns une table de hachage et afficher la table de hachage;


En fait si je comprends bien tu veux quelque chose de genre :

Si le fichier par exemple a cette structure

Nom Prénom Age Adresse etc.

tu veux que le nom soit inclus dans la table et quand on cherche un nom, tu voudras par exemple afficher les infos (Prénom, Age, etc.)

C'est bien ça?

0
stroumpf Messages postés 292 Statut Membre 2
 
Pas exactement LAmi, là je veux stocket le mots + sa position +num ligne dans la table ( toute la liste en fait)
car apres jai besons de ces inofs.
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
Pas exactement LAmi, là je veux stocket le mots + sa position +num ligne dans la table ( toute la liste en fait)

Ca n'a pas de sens.

Tous les données seront éparpilles dans la table de hachage.

Par exemple le Nom pourra se trouver dans le conteneur 100, le Prénom dans 53, etc., vu que chaque terme sera haché par la fonction hash_cle

Donc il faut garder une liaison entre le Nom et les autres infos

En revanche tu peux faire en sorte que chaque Nom (qui fera partie de la table) soit la tête d'une liste qui contiendra les autres infos.

Tu vois ce que je veux dire?
0
stroumpf Messages postés 292 Statut Membre 2
 
:)
Oui LAmi c'est ce que je voulais dire.
peut etre je m'exprime mal ;)
Bon c ca l'idée . merci
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570 > stroumpf Messages postés 292 Statut Membre
 
Ben, donne moi ton fichier texte et dit comment tu veux le parser.
0
stroumpf Messages postés 292 Statut Membre 2 > lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité
 
Lami, jai dejà extrait tous les mots, et les mits dans liste: caque element de la liste contient le mots, liste des position et liste des num ligne.
reste que les ramener a la table de hachage.
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570 > stroumpf Messages postés 292 Statut Membre
 
Si je ne connais pas la structure de ton fichier alors je ne peux rien faire.
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570 > stroumpf Messages postés 292 Statut Membre
 
Et pour te dire la vérité, comme je suis paresseux, je préfère de continuer mon exemple et ensuite à toi de l'adapter ;-) que de déchiffrer ton code ;-))

0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
affiché depuis la table de hachage car moi je lai deja affiché a partir de la liste chaine


En fait tu as une liste chaînée et tu veux la convertir dans une table de hachage, en utilisant comme la variable mot pour obtenir la clé de hachage.

Dans ton code je ne vois pas la déclaration de type Liste

0
stroumpf Messages postés 292 Statut Membre 2
 
ah oui je lai mis dans le fichier table dehachage.h




#ifndef TABLE_HASH
#define TABLE_HASH

typedef struct E{
        char mot[100];
        char pos[100];
        struct E *suivant;
}Liste;

Liste *InsertionEnTete(Liste *L,Liste *mot);
void AfficherListe(Liste *L);
void AfficheMot(char *mot);
unsigned int hash_cle(char *mot);
void AfficherTableHash(Liste **TableHash);
unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot);

#endif
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
Vite fait, teste comme ça

dans le fichier table_hash.h mais en commentaire la ligne
Liste *InsertionEnTete(Liste *L,Liste *mot);

Dans main

déclare i
donc au debut de main mets int i;
et écrit for(int i=0;i<TAILLEHASH;++i) comme ça
for(i=0;i<TAILLEHASH;++i)
0
stroumpf Messages postés 292 Statut Membre 2
 
ou est ce que je met for(i=0;i<TAILLEHASH;++i) ?


int main(int argc, char *argv[])
{ char c;
int A;
int val;
int i ;
Liste **TableHash;
char* mot;
liste_mot* s =NULL;


Trouver_mots (&s,"C:\\Users\\cyrine\\Documents\\text.txt" );
Affiche_mots(s);
printf("\n\n la liste filtree \n\n");
frequent( &s , 1);
Affiche_mots(s);
val=fonctHachage(s);
//calcul_nbre_mot(s);
// printf("%d",A);
// allocation de hash table
mot=s->mot;
TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *));
// initialisation de hash table
for(int i=0;i<TAILLEHASH;++i)
TableHash[i] = NULL;
//while (s!=NULL)
//{
//fonction de hachage


//inserer dans la table de hachage
TableHash[val]=InsertionEnTete(TableHash[val],s);

printf("%s", TableHash[val],"\n");

//printf("%d", val,"\n");

//s=s->next;
//}

A=nbr_mot(s);


scanf("%c",c);
return 0;
}
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
ici
TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *));
// initialisation de hash table
for(int i=0;i<TAILLEHASH;++i)
TableHash[i] = NULL; 
0
stroumpf Messages postés 292 Statut Membre 2
 
Oui Lami, c'est ce que jai deja fait :)
regarde: il maffiche selement le denier mot
0
stroumpf Messages postés 292 Statut Membre 2
 
ta pas une idée LAMI?
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570 > stroumpf Messages postés 292 Statut Membre
 
Patience ;-)
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
Il reste juste l passage avec frequent à traiter
table_hash.h
/* table_hash.h */

#ifndef TABLE_HASH
#define TABLE_HASH

typedef struct c{
	int pos;
	int nl;
	struct c *suivant;
}Coordonnees;

typedef struct L{
	char mot[50];
	Coordonnees *c;
	struct L *suivant;
}Liste;


Liste *InsertionEnTete(Liste *L,char *mot);
Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl,int pos);
void AfficherListe(Liste *L);
void AfficherCoordonnees(Coordonnees *C);
void AfficheMot(char *mot);
unsigned int hash_cle(char *mot);
void AfficherTableHash(Liste **TableHash);
unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot);
void PosLigne(FILE *F,Liste **TableHash);

#endif

posmot.c
/* posmot.c */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include "table_hash.h"
#define TAILLEHASH 307

int main()
{
  FILE *F;
  char mot[100];
  int i;
  unsigned int cle;
  int nl, pos;
  nl=pos=1;

  Liste **TableHash;
  TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *));
  for(i=0;i<TAILLEHASH;++i)
    TableHash[i] = NULL;

  F=fopen("stroumpf.txt","r");

  while(fscanf(F,"%s",mot)==1){
    cle = hash_cle(mot);
    if(! ChercherMotDansTableHash(TableHash,mot))
      TableHash[cle] = InsertionEnTete(TableHash[cle],mot);
  }
  fclose(F);
  F=fopen("stroumpf.txt","r");
  PosLigne(F,TableHash);
  AfficherTableHash(TableHash);

  //printf("Chercher mot : ");
  //scanf("%s",mot);
  //if(cle = ChercherMotDansTableHash(TableHash,mot))
  //  printf("%s existant dans le conteneur %u\n",mot,hash_cle(mot));
  //else
  //  printf("%s inexistant dans la table de hash\n");
  return 0;
}



Liste *InsertionEnTete(Liste *L,char *mot){
  Liste *nouveau;
  nouveau = (Liste *) malloc (sizeof(Liste));
  strcpy(nouveau->mot,mot);
  nouveau->suivant = L;
  nouveau->c = NULL;
  return nouveau;
}

Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl ,int pos){
  Coordonnees *nouveau;
  nouveau = (Coordonnees *) malloc (sizeof(Coordonnees));
  nouveau->pos = pos;
  nouveau->nl = nl;
  nouveau->suivant = C;
  return nouveau;
}

void AfficherListe(Liste *L){
  Liste *p;
  for(p=L;p!=NULL;p=p->suivant){
    AfficheMot(p->mot);
    AfficherCoordonnees(p->c);
    printf("\n");
  }
}

void AfficherCoordonnees(Coordonnees *C){
  Coordonnees *p;
  for(p=C;p!=NULL;p=p->suivant)
	  printf(" (%d,%d) ",p->nl,p->pos);
  printf("\n");
}

void AfficheMot(char *mot){
  printf("%s ",mot);
}

unsigned int hash_cle(char *mot){
  unsigned int val = 0;
  for(;*mot!='\0';++mot)
    val = *mot + 31 * val;
  return val % TAILLEHASH;
}

void AfficherTableHash(Liste **TableHash){
  int i;
  for(i=0;i<TAILLEHASH;++i)
    if(TableHash[i] != NULL){
      printf("Conteneur %d : ",i);
      AfficherListe(TableHash[i]);
      printf("-------------------------------------------------\n");
    }
}

unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot){
  
  Liste *p;
  unsigned int cle;
  
  cle = hash_cle(mot);
  for(p=TableHash[cle];p!=NULL;p=p->suivant)
    if(strcmp(p->mot,mot)==0)
      return 1;
  return 0;
}



void PosLigne(FILE *F,Liste **TableHash){
  char s[50];
  int nl,pos,i;
  Liste *p;
  nl=pos=1;

  while(fscanf(F,"%s",s)==1){
    for(i=0;i<TAILLEHASH;++i)
      if(TableHash[i]!=NULL)
        for(p=TableHash[i];p!=NULL;p=p->suivant)
          if(strcmp(p->mot,s)==0)
            p->c=InsertionEnTeteCoordonnee(p->c,nl ,pos);
    if(fgetc(F)=='\n'){
      ++nl;
      pos=0;
    }
    ++pos;
  }
  printf("\n");
}




Test sur
Lasciatemi cantare .
con la chitarra in mano.
lasciatemi cantare .
sono un italiano .
Buongiorno Italia gli spaghetti al dente .
e un partigiano come Presidente.
con l'autoradio sempre nella mano destra .
e un canarino sopra la finestra .
Buongiorno Italia con i tuoi artisti.
con troppa America sui manifesti.
con le canzoni con amore .
con il cuore .
con piu' donne sempre meno suore .
Buongiorno Italia .
buongiorno Maria .
con gli occhi pieni di malinconia .
buongiorno Dio .
lo sai che ci sono anch'io .


lami20j@debian:~/trash$ ./a.out

Conteneur 0 : piu'  (13,2)

-------------------------------------------------
Conteneur 19 : troppa  (10,2)

-------------------------------------------------
Conteneur 22 : buongiorno  (17,1)  (15,1)

-------------------------------------------------
Conteneur 31 : amore  (11,5)

-------------------------------------------------
Conteneur 33 : sopra  (8,4)

-------------------------------------------------
Conteneur 35 : occhi  (16,3)

-------------------------------------------------
Conteneur 37 : sai  (18,2)

-------------------------------------------------
Conteneur 40 : chitarra  (2,3)

-------------------------------------------------
Conteneur 43 : sui  (10,4)

-------------------------------------------------
Conteneur 45 : al  (5,5)

-------------------------------------------------
Conteneur 46 : .  (18,7)  (17,3)  (16,7)  (15,3)  (14,3)  (13,7)  (12,4)  (11,6)  (8,7)  (7,7)  (5,7)  (4,4)  (3,3)  (1,3)

-------------------------------------------------
Conteneur 53 : destra  (7,6)

un  (8,2)  (6,2)  (4,2)

-------------------------------------------------
Conteneur 58 : partigiano  (6,3)

-------------------------------------------------
Conteneur 64 : cantare  (3,2)  (1,2)

-------------------------------------------------
Conteneur 68 : la  (8,5)  (2,2)

-------------------------------------------------
Conteneur 69 : suore  (13,6)

-------------------------------------------------
Conteneur 72 : le  (11,2)

-------------------------------------------------
Conteneur 82 : lo  (18,1)

-------------------------------------------------
Conteneur 86 : donne  (13,3)

-------------------------------------------------
Conteneur 92 : Lasciatemi  (1,1)

-------------------------------------------------
Conteneur 101 : tuoi  (9,5)

e  (8,1)  (6,1)

-------------------------------------------------
Conteneur 104 : ci  (18,4)

-------------------------------------------------
Conteneur 105 : i  (9,4)

-------------------------------------------------
Conteneur 113 : mano  (7,5)

-------------------------------------------------
Conteneur 122 : Presidente.  (6,5)

-------------------------------------------------
Conteneur 125 : lasciatemi  (3,1)

-------------------------------------------------
Conteneur 131 : pieni  (16,4)

sono  (18,5)  (4,1)

-------------------------------------------------
Conteneur 135 : di  (16,5)

spaghetti  (5,4)

-------------------------------------------------
Conteneur 136 : malinconia  (16,6)

-------------------------------------------------
Conteneur 143 : con  (16,1)  (13,1)  (12,1)  (11,4)  (11,1)  (10,1)  (9,3)  (7,1)  (2,1)

-------------------------------------------------
Conteneur 147 : Italia  (14,2)  (9,2)  (5,2)

Buongiorno  (14,1)  (9,1)  (5,1)

-------------------------------------------------
Conteneur 152 : dente  (5,6)

-------------------------------------------------
Conteneur 163 : nella  (7,4)

-------------------------------------------------
Conteneur 172 : mano.  (2,5)

-------------------------------------------------
Conteneur 186 : finestra  (8,6)

-------------------------------------------------
Conteneur 193 : l'autoradio  (7,2)

-------------------------------------------------
Conteneur 197 : italiano  (4,3)

-------------------------------------------------
Conteneur 205 : come  (6,4)

gli  (16,2)  (5,3)

-------------------------------------------------
Conteneur 224 : che  (18,3)

-------------------------------------------------
Conteneur 229 : canarino  (8,3)

-------------------------------------------------
Conteneur 253 : Dio  (17,2)

-------------------------------------------------
Conteneur 257 : cuore  (12,3)

artisti.  (9,6)

-------------------------------------------------
Conteneur 261 : anch'io  (18,6)

-------------------------------------------------
Conteneur 266 : Maria  (15,2)

-------------------------------------------------
Conteneur 269 : canzoni  (11,3)

-------------------------------------------------
Conteneur 271 : sempre  (13,4)  (7,3)

-------------------------------------------------
Conteneur 273 : meno  (13,5)

-------------------------------------------------
Conteneur 277 : manifesti.  (10,5)

-------------------------------------------------
Conteneur 292 : America  (10,3)

-------------------------------------------------
Conteneur 293 : il  (12,2)

-------------------------------------------------
Conteneur 295 : in  (2,4)

-------------------------------------------------
lami20j@debian:~/trash$
0
stroumpf Messages postés 292 Statut Membre 2
 
Merci Lami, mais le probleme ici reste qu'il ya des conteneurs quii contiennent plus qu'un mot, et ce ci est grave car il va y avoir un probleme de collision , non?
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
Salut,

et ce ci est grave car il va y avoir un probleme de collision , non?
Exactement.
Ce n'est pas grave ça ;-)

Tu as plusieurs solutions solutions :
1. tu augmentes la taille de table de hachage

2. tu crées une fonctions de hachage meilleure

De toute façon les colissions ce n'est pas si grave puisqu'en fait au lieu d'avoir unel iste chaînée de n éléments tu auras plusieurs listes avec le nombre d'éléments égal avec le facteur de charge.

Une fonction de recherche d'un mot te permettra de trouver ce que tu as besoin.

Sinon, dans la fonction
void AfficherTableHash(Liste **TableHash){
int i;
for(i=0;i<TAILLEHASH;++i)
if(TableHash[i] != NULL){
printf("Conteneur %d : ",i);
AfficherListe(TableHash[i]);
printf("-------------------------------------------------\n");
}
}
tu la écris comme ça
void AfficherTableHash(Liste **TableHash){
  int i;
  for(i=0;i<TAILLEHASH;++i)
    if(TableHash[i] != NULL){
      AfficherListe(TableHash[i]);
      printf("-------------------------------------------------\n");
    }
}
et tu ne te rendra même pas compte qu'il y a des collisions ;-))
De toute façon, avoir une table de hachage sans collision c'est l'idéal (donc une utopie ;-)

0
stroumpf Messages postés 292 Statut Membre 2
 
Ok merci Lami,
Ben moi je traite un gros gros corpus texte ( contenant plus 100 000) phrase: ;)
comme ca il va pas yavoir des collision.
?
0
stroumpf Messages postés 292 Statut Membre 2
 
Rebonsoir LAmi, bon voila la fonction fréquent: ba normallement elle fonction pour elliminer les bruits, sauf elle n'ellimine pas les element de la table de hachage
ta une idee svp?




void frequent( Liste **L , int mc)
{
     Liste *m=*L;
     Liste* prev=*L;
     Coordonnees* C=NULL;
     int sup, lig=0;
     while(m!=NULL) 
     {
         C=m->c;
         sup=0;
         lig=0;
         while (C!=NULL)     
         {
               if (C->nl > lig)
               {
                   sup++;
                   lig= C->nl;                                   
               }
               C=C->suivant;
         } 
         if (sup>mc) 
         {
            prev=m;         
            m=m->suivant;
            // c bon          
         }else
         {
              if (prev==m) // cas du première mot
                 {
                    *L=m->suivant;
                    prev=m->suivant;
                 }
              else
                 prev->suivant=m->suivant;
            m=m->suivant;
          // on supprime le mot    
         }                 
     }
}
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
Salut,

table_hash.h
/* table_hash.h */

#ifndef TABLE_HASH
#define TABLE_HASH

typedef struct c{
	int pos;
	int nl;
	struct c *suivant;
}Coordonnees;

typedef struct L{
	char mot[50];
	Coordonnees *c;
	struct L *suivant;
}Liste;


Liste *InsertionEnTete(Liste *L,char *mot);
Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl,int pos);
void AfficherListe(Liste *L);
void AfficherCoordonnees(Coordonnees *C);
void AfficheMot(char *mot);
void ParcourirElementTableHash(Liste **TableHash,char *mot);
unsigned int hash_cle(char *mot);
void AfficherTableHash(Liste **TableHash);
unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot);
void PosLigne(FILE *F,Liste **TableHash);

#endif
posmot.c
/* posmot.c */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include "table_hash.h"
#define TAILLEHASH 307

int main()
{
  FILE *F;
  char mot[100];
  int i;
  unsigned int cle;
  int nl, pos;
  nl=pos=1;

  Liste **TableHash;
  TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *));
  for(i=0;i<TAILLEHASH;++i)
    TableHash[i] = NULL;

  F=fopen("stroumpf.txt","r");

  while(fscanf(F,"%s",mot)==1){
    cle = hash_cle(mot);
    if(! ChercherMotDansTableHash(TableHash,mot))
      TableHash[cle] = InsertionEnTete(TableHash[cle],mot);
  }
  fclose(F);
  F=fopen("stroumpf.txt","r");
  PosLigne(F,TableHash);
  AfficherTableHash(TableHash);

  printf("Chercher mot : ");
  scanf("%s",mot);
  if(cle = ChercherMotDansTableHash(TableHash,mot))
    ParcourirElementTableHash(TableHash,mot);
  else
    printf("%s inexistant dans la table de hash\n");
  return 0;
}



Liste *InsertionEnTete(Liste *L,char *mot){
  Liste *nouveau;
  nouveau = (Liste *) malloc (sizeof(Liste));
  strcpy(nouveau->mot,mot);
  nouveau->suivant = L;
  nouveau->c = NULL;
  return nouveau;
}

Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl ,int pos){
  Coordonnees *nouveau;
  nouveau = (Coordonnees *) malloc (sizeof(Coordonnees));
  nouveau->pos = pos;
  nouveau->nl = nl;
  nouveau->suivant = C;
  return nouveau;
}

void AfficherListe(Liste *L){
  Liste *p;
  for(p=L;p!=NULL;p=p->suivant){
    AfficheMot(p->mot);
    AfficherCoordonnees(p->c);
  //  printf("\n");
  }
}

void AfficherCoordonnees(Coordonnees *C){
  Coordonnees *p;
  for(p=C;p!=NULL;p=p->suivant)
	  printf(" (%d,%d) ",p->nl,p->pos);
  printf("\n");
}

void AfficheMot(char *mot){
  printf("%s ",mot);
}

unsigned int hash_cle(char *mot){
  unsigned int val = 0;
  for(;*mot!='\0';++mot)
    val = *mot + 31 * val;
  return val % TAILLEHASH;
}

void AfficherTableHash(Liste **TableHash){
  int i;
  for(i=0;i<TAILLEHASH;++i)
    if(TableHash[i] != NULL){
  //    printf("Conteneur %d : ",i);
      AfficherListe(TableHash[i]);
  //    printf("-------------------------------------------------\n");
    }
}

unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot){
  
  Liste *p;
  unsigned int cle;
  
  cle = hash_cle(mot);
  for(p=TableHash[cle];p!=NULL;p=p->suivant)
    if(strcmp(p->mot,mot)==0)
      return 1;
  return 0;
}



void PosLigne(FILE *F,Liste **TableHash){
  char s[50];
  int nl,pos,i;
  Liste *p;
  nl=pos=1;

  while(fscanf(F,"%s",s)==1){
    for(i=0;i<TAILLEHASH;++i)
      if(TableHash[i]!=NULL)
        for(p=TableHash[i];p!=NULL;p=p->suivant)
          if(strcmp(p->mot,s)==0)
            p->c=InsertionEnTeteCoordonnee(p->c,nl ,pos);
    if(fgetc(F)=='\n'){
      ++nl;
      pos=0;
    }
    ++pos;
  }
  printf("\n");
}

void ParcourirElementTableHash(Liste **TableHash,char *mot){
  int cle;
  Liste *p;
  cle = hash_cle(mot);

  for(p=TableHash[cle];p!=NULL;p=p->suivant)
    if(strcmp(mot,p->mot) == 0){
      printf("%s : ",mot);
      AfficherCoordonnees(p->c);
    }
}
Exécution
lami20j@debian:~/trash$ ./posmot

piu'  (13,2)
troppa  (10,2)
buongiorno  (17,1)  (15,1)
amore  (11,5)
sopra  (8,4)
occhi  (16,3)
sai  (18,2)
chitarra  (2,3)
sui  (10,4)
al  (5,5)
.  (18,7)  (17,3)  (16,7)  (15,3)  (14,3)  (13,7)  (12,4)  (11,6)  (8,7)  (7,7)  (5,7)  (4,4)  (3,3)  (1,3)
destra  (7,6)
un  (8,2)  (6,2)  (4,2)
partigiano  (6,3)
cantare  (3,2)  (1,2)
la  (8,5)  (2,2)
suore  (13,6)
le  (11,2)
lo  (18,1)
donne  (13,3)
Lasciatemi  (1,1)
tuoi  (9,5)
e  (8,1)  (6,1)
ci  (18,4)
i  (9,4)
mano  (7,5)
Presidente.  (6,5)
lasciatemi  (3,1)
pieni  (16,4)
sono  (18,5)  (4,1)
di  (16,5)
spaghetti  (5,4)
malinconia  (16,6)
con  (16,1)  (13,1)  (12,1)  (11,4)  (11,1)  (10,1)  (9,3)  (7,1)  (2,1)
Italia  (14,2)  (9,2)  (5,2)
Buongiorno  (14,1)  (9,1)  (5,1)
dente  (5,6)
nella  (7,4)
mano.  (2,5)
finestra  (8,6)
l'autoradio  (7,2)
italiano  (4,3)
come  (6,4)
gli  (16,2)  (5,3)
che  (18,3)
canarino  (8,3)
Dio  (17,2)
cuore  (12,3)
artisti.  (9,6)
anch'io  (18,6)
Maria  (15,2)
canzoni  (11,3)
sempre  (13,4)  (7,3)
meno  (13,5)
manifesti.  (10,5)
America  (10,3)
il  (12,2)
in  (2,4)
Chercher mot : con
con :  (16,1)  (13,1)  (12,1)  (11,4)  (11,1)  (10,1)  (9,3)  (7,1)  (2,1)
lami20j@debian:~/trash$  
Donc à la demande le mot de la table de hash est affiché ainsi que la liste chaînée qui lui correspond.
0
stroumpf Messages postés 292 Statut Membre 2
 
Bien, c fonctionnaant ;)
mais c mieux de faire un seul parcours du fichier pour diminuer le coût CPU.
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
Je suis d'accord avec toi pour les 2 parcours.

Une solution sera d'ajouter de champs dans la structure du mot 2 champs pour pos et ligne
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
Salut,

mais c mieux de faire un seul parcours du fichier
J'ai créé une fonction (voir en gras) qui parcours le fichier, insère les mots dans la table de hash et traite aussi les position et le numéro de ligne ;-)

Voilà, l'exemple complet

table_hash.h
/* table_hash.h */

#ifndef TABLE_HASH
#define TABLE_HASH

typedef struct c{
        int pos;
        int nl;
        struct c *suivant;
}Coordonnees;

typedef struct L{
        char mot[50];
        Coordonnees *c;
        struct L *suivant;
}Liste;


Liste *InsertionEnTete(Liste *L,char *mot);
void InsertionTableHash(FILE *F, Liste **TableHash);
Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl,int pos);
void AfficherListe(Liste *L);
void AfficherCoordonnees(Coordonnees *C);
void AfficheMot(char *mot);
void ParcourirElementTableHash(Liste **TableHash,char *mot);
unsigned int hash_cle(char *mot);
void AfficherTableHash(Liste **TableHash);
unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot);
void PosLigne(FILE *F,Liste **TableHash);

#endif
posmot2.c
/* posmot2.c */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include "table_hash.h"
#define TAILLEHASH 307

int main()
{
  FILE *F;
  Liste **TableHash;
  char mot[100];
  int i;

  TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *));
  for(i=0;i<TAILLEHASH;++i)
    TableHash[i] = NULL;

  F=fopen("stroumpf.txt","r");
  InsertionTableHash(F,TableHash);
  fclose(F);
  AfficherTableHash(TableHash);

  printf("Chercher mot : ");
  scanf("%s",mot);
  if(ChercherMotDansTableHash(TableHash,mot))
    ParcourirElementTableHash(TableHash,mot);
  else
    printf("%s inexistant dans la table de hash\n");
  return 0;
}

Liste *InsertionEnTete(Liste *L,char *mot){
  Liste *nouveau;
  nouveau = (Liste *) malloc (sizeof(Liste));
  strcpy(nouveau->mot,mot);
  nouveau->suivant = L;
  nouveau->c = NULL;
  return nouveau;
}

Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl ,int pos){
  Coordonnees *nouveau;
  nouveau = (Coordonnees *) malloc (sizeof(Coordonnees));
  nouveau->pos = pos;
  nouveau->nl = nl;
  nouveau->suivant = C;
  return nouveau;
}

void AfficherListe(Liste *L){
  Liste *p;
  for(p=L;p!=NULL;p=p->suivant){
    AfficheMot(p->mot);
    AfficherCoordonnees(p->c);
  }
}

void AfficherCoordonnees(Coordonnees *C){
  Coordonnees *p;
  for(p=C;p!=NULL;p=p->suivant)
	  printf(" (%d,%d) ",p->nl,p->pos);
  printf("\n");
}

void AfficheMot(char *mot){
  printf("%s ",mot);
}

unsigned int hash_cle(char *mot){
  unsigned int val = 0;
  for(;*mot!='\0';++mot)
    val = *mot + 31 * val;
  return val % TAILLEHASH;
}

void AfficherTableHash(Liste **TableHash){
  int i;
  for(i=0;i<TAILLEHASH;++i)
    if(TableHash[i] != NULL){
      AfficherListe(TableHash[i]);
    }
}

unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot){
  
  Liste *p;
  unsigned int cle;
  
  cle = hash_cle(mot);
  for(p=TableHash[cle];p!=NULL;p=p->suivant)
    if(strcmp(p->mot,mot)==0)
      return 1;
  return 0;
}

void InsertionTableHash(FILE *F, Liste **TableHash){
  int nl,pos,i;
  unsigned int cle;
  char mot[100];
  Liste *p;
  nl=pos=1;
  
  while(fscanf(F,"%s",mot)==1){
    cle = hash_cle(mot);

    if(! ChercherMotDansTableHash(TableHash,mot))
      TableHash[cle] = InsertionEnTete(TableHash[cle],mot);
    for(p=TableHash[cle];p!=NULL;p=p->suivant){
          if(strcmp(p->mot,mot)==0)
            p->c=InsertionEnTeteCoordonnee(p->c,nl ,pos);
    }
    if(fgetc(F)=='\n'){
      ++nl;
      pos=0;
    }
    ++pos;
  }
}

void ParcourirElementTableHash(Liste **TableHash,char *mot){
  int cle;
  Liste *p;
  cle = hash_cle(mot);

  for(p=TableHash[cle];p!=NULL;p=p->suivant)
    if(strcmp(mot,p->mot) == 0){
      printf("%s : ",mot);
      AfficherCoordonnees(p->c);
    }
}
Exécution
lami20j@debian:~/trash$ gcc posmot2.c -o posmot2
lami20j@debian:~/trash$ ./posmot2
piu'  (13,2)
troppa  (10,2)
buongiorno  (17,1)  (15,1)
amore  (11,5)
sopra  (8,4)
occhi  (16,3)
sai  (18,2)
chitarra  (2,3)
sui  (10,4)
al  (5,5)
.  (18,7)  (17,3)  (16,7)  (15,3)  (14,3)  (13,7)  (12,4)  (11,6)  (8,7)  (7,7)  (5,7)  (4,4)  (3,3)  (1,3)
destra  (7,6)
un  (8,2)  (6,2)  (4,2)
partigiano  (6,3)
cantare  (3,2)  (1,2)
la  (8,5)  (2,2)
suore  (13,6)
le  (11,2)
lo  (18,1)
donne  (13,3)
Lasciatemi  (1,1)
tuoi  (9,5)
e  (8,1)  (6,1)
ci  (18,4)
i  (9,4)
mano  (7,5)
Presidente.  (6,5)
lasciatemi  (3,1)
pieni  (16,4)
sono  (18,5)  (4,1)
di  (16,5)
spaghetti  (5,4)
malinconia  (16,6)
con  (16,1)  (13,1)  (12,1)  (11,4)  (11,1)  (10,1)  (9,3)  (7,1)  (2,1)
Italia  (14,2)  (9,2)  (5,2)
Buongiorno  (14,1)  (9,1)  (5,1)
dente  (5,6)
nella  (7,4)
mano.  (2,5)
finestra  (8,6)
l'autoradio  (7,2)
italiano  (4,3)
come  (6,4)
gli  (16,2)  (5,3)
che  (18,3)
canarino  (8,3)
Dio  (17,2)
cuore  (12,3)
artisti.  (9,6)
anch'io  (18,6)
Maria  (15,2)
canzoni  (11,3)
sempre  (13,4)  (7,3)
meno  (13,5)
manifesti.  (10,5)
America  (10,3)
il  (12,2)
in  (2,4)
Chercher mot : con
con :  (16,1)  (13,1)  (12,1)  (11,4)  (11,1)  (10,1)  (9,3)  (7,1)  (2,1)
lami20j@debian:~/trash$ 



0
stroumpf Messages postés 292 Statut Membre 2
 
Bonjour a tous ;
mon probleme consiste à developper une la fonction "jointure" qui permet de faire la jointure de tt les elements de la table de hachage( on joint les elemnt qui ont le meme num de ligne) pour produire elment joint (exp "BONJOUR TOTO") avec info (1,3)
merci,
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
Salut,

je ne comprends pas
en ce cas (1,3) c'est quoi pour "Bonjour toto"?
si 1 c'est le numéro de ligne, alors 3 c'est quoi?

Si tu donne une exemple concret

par exemple dans la table tu as pour la clé (en supposant que aaa et bbb ont la même clé)

aaa avec (1,2) (3,1)
bbb avec (5,1) (10,1)

Tu veux obtenir "aaa bbb" et ?????

0
stroumpf Messages postés 292 Statut Membre 2
 
merci Lami de m'avoir repondu.
supposons qu'on a le mot "bonjour" (1,3) ligne num 1 et position 3
et le mot "Lami"(1,4) ligne num 1 et position 4
donc la jointure ca sera "Bonjour LAmi"(1,4)

sachant que la jointure se fait sssi entre deux mots qui ont le meme ligne num
tu vois ?
0
stroumpf Messages postés 292 Statut Membre 2
 
la "aaa"" et "bbb"" ne sejoint pas car il n'ont pas le meme num_ligne
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
Ce que tu veux obtenir n'a rien avoir avec la table mais avec le fichier.
Dans la table les mot sont enregistrés suite à leur clé de hachage et pas en fonction de numéro de ligne.

Ce que tu veux maintenant je trouve superflu puisqu'en fait la jointure que tu veux c'est le fichier lui même.

Donc tu veux reconvertir la table hash dans le fichier qui existe déjà.

0
stroumpf Messages postés 292 Statut Membre 2
 
Non Lami :)
ben faut parcourir la table de hachage( 2 compteurs) , tester chaque avec le mot suivantselon la num ligne qui est enregistré dans la liste chaine(tu te souviens) et puis faire la jointure(calculer la clé de hachage pour stocker dans la table de hachage) ctt ;)
tu vois?
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
;-((( je ne vois pas

En revanche on va faciliter un peu les choses.

Sur ton texte je vais exécuter le programme (j'ai diminué la taille de la table")
A toi de me montrer avec des exemple concrets les jointure que tu veuilles obtenir ;-))

Le fichier
lami20j@debian:~/trash$ cat fichier.txt
Non Lami :)
ben faut parcourir la table de hachage( 2 compteurs) , tester chaque avec le mot suivantselon la num ligne qui est enregistré dans la liste chaine(tu te souviens) et puis faire la jointure(calculer la clé de hachage pour stocker dans la table de hachage) ctt ;)
tu vois?
Le résultat
lami20j@debian:~/trash$ ./posmot2
Conteneur 0 :
                ;)  (2,46)
                clé  (2,35)
                et  (2,29)
                est  (2,21)
                num  (2,18)
-------------------------------------------------
Conteneur 1 :
                chaine(tu  (2,26)
-------------------------------------------------
Conteneur 2 :
                stocker  (2,39)
-------------------------------------------------
Conteneur 3 :
                liste  (2,25)
                :)  (1,3)
                Non  (1,1)
-------------------------------------------------
Conteneur 5 :
                puis  (2,30)
                enregistré  (2,22)
                de  (2,43)  (2,36)  (2,6)
-------------------------------------------------
Conteneur 6 :
                faire  (2,31)
                qui  (2,20)
                hachage(  (2,7)
-------------------------------------------------
Conteneur 7 :
                tu  (3,1)
                hachage)  (2,44)
                avec  (2,13)
                table  (2,42)  (2,5)
-------------------------------------------------
Conteneur 8 :
                te  (2,27)
                suivantselon  (2,16)
                chaque  (2,12)
                parcourir  (2,3)
-------------------------------------------------
Conteneur 9 :
                faut  (2,2)
                ben  (2,1)
-------------------------------------------------
Conteneur 10 :
                hachage  (2,37)
                souviens)  (2,28)
                ,  (2,10)
                compteurs)  (2,9)
                Lami  (1,2)
-------------------------------------------------
Conteneur 11 :
                la  (2,41)  (2,34)  (2,32)  (2,24)  (2,17)  (2,4)
-------------------------------------------------
Conteneur 12 :
                jointure(calculer  (2,33)
-------------------------------------------------
Conteneur 13 :
                ctt  (2,45)
                tester  (2,11)
-------------------------------------------------
Conteneur 15 :
                dans  (2,40)  (2,23)
                ligne  (2,19)
                le  (2,14)
-------------------------------------------------
Conteneur 16 :
                vois?  (3,2)
                pour  (2,38)
                mot  (2,15)
                2  (2,8)
-------------------------------------------------
Chercher mot : mot
mot :  (2,15)
0
stroumpf Messages postés 292 Statut Membre 2
 
ok :)
Conteneur 0 :
;) (2,46)
clé (2,35)
et (2,29)
est (2,21)
num (2,18)
exple au niveau de ce conteneur , il va y avoir des vointure pour caque couple de mot afin de produire de couple de mots , mais la jointure se fait entre les mots qui ont le meme num-ligne
repone :
clé;) (2,46)
et;) (2,46)
est;) (2,46)
num;) (2,46)
et clé (2,35)
ets clé (2,35)
num clé (2,35)

.. aisi de suite
il faut num position de second mot soit plus grand que le 1er mot :" est clé " et non pas "clé est"
cbon?
0
lami20j Messages postés 21644 Statut Modérateur, Contributeur sécurité 3 570
 
Re,

ok, je vois maintenant ;-)
0