Пример #1
0
string jdmExiste(string s){
    string url="http://www.jeuxdemots.org/autocompletion/autocompletion.php?completionarg=proposition&proposition=";
    url+=s;
    url = transformer(&url," ","%20");

    int i=0;
    string result;
    if(lireMot(&i, &s, "/"))
        result = ouvrirPageForce(url);
    else
        result = ouvrirPage(url);

    i=0;
    string candidat;
    lireMot(&i, &result, "[\"");
    string maxs="";
    int maxi=10;
    while(lireMot(&i, &result, &candidat, "\"")){
        if( maxi<(poidJDM(candidat)/pow(LevenshteinDistance(s, candidat),3)) ){
            maxi=poidJDM(candidat)/pow(LevenshteinDistance(s, candidat),3);
            maxs=s;
        }
        candidat.clear();
        lireMot(&i, &result, "\"");
    }
    return maxs;
}
Пример #2
0
int poidJDM(string s){
    string adresse = "http://www.jeuxdemots.org/rezo-xml.php?gotermsubmit=Chercher";
    string stub = "&gotermrel=";
    string finAdresse = "&output=onlyxml";
    string page = ouvrirPage(adresse+stub+s+finAdresse);
    int i =0;
    string spoids;
    lireMot(&i, &page, "<mot poids=\"");
    lireMot(&i, &page, &spoids, "\"");
    return atoi(spoids.c_str());

}
int remplir(Information* dico, int taille, FILE* flux)
{
   char buffer[512];
   int index_insertion = -1;

   if(taille >= TAILLE_MAX) {
       fprintf(stderr, "Taille max du tableau atteinte !\n");
       exit(EXIT_FAILURE);
   }

    while (lireMot(flux, &buffer[0])) {
        index_insertion = existe(dico, taille, buffer);
        if(index_insertion == -1) /* le mot n'est pas présent dans le tableau */
        {
            dico[taille].mot = (char *)malloc(strlen(buffer) + 1 * sizeof(char));
            if(dico[taille].mot == NULL){
                fprintf(stderr, "Impossible d'allouer la mémoire nécessaire\n");
                exit(EXIT_FAILURE);
            }
            strcpy(dico[taille].mot, buffer);
            dico[taille].nbOcc = 1;
            ++taille;
            if(taille >= TAILLE_MAX) {
                fprintf(stderr, "Taille max du tableau atteinte !\n");
                exit(EXIT_FAILURE);
            }

        } else {                    /* Le mot est déjà présent dans le tableau */
            ++dico[index_insertion].nbOcc;
        }
    }

    return taille;
}
Пример #4
0
bool jdmEquivalent(string s){ //TRUE uniquement si le premier mot de l('autocomplétion est strictement identique.
    //cout<<" existe ?"<<s<<endl;
    int i=0;
    //CURL *curl;
    //curl = curl_easy_init();
    string adresse = "http://www.jeuxdemots.org/rezo-xml.php?gotermsubmit=Chercher";
    string stub = "&gotermrel=";
    string finAdresse = "&output=onlyxml";
    string result = ouvrirPage(adresse+stub+s+finAdresse);
    string r="n'existe pas";

    /*
    string url="http://www.jeuxdemots.org/autocompletion/autocompletion.php?completionarg=proposition&proposition=";
    url += curl_easy_escape(curl, s.c_str(), s.size());;
    //cout<<url<<endl;
    url = transformer(&url," ","%20");
    url = transformer(&url,"%20","+");
    url = transformer(&url,"%E2%80%99","%27");
//    cout<<"url : "<<url<<endl;
    //pause("url");
    string result=ouvrirPage(url);
//    cout<<result<<endl;
    //cout<<"le mot n'existe pas dans JDM!!!"<<endl;
    string r = "\"";
    r+=s;
    r+="\"";
    r=latin1(r);
    r=transformer(&r,"_", "\'");
    // cout<<"R: "<<r<<endl;
*/
    return !lireMot( &result, r);

}
Пример #5
0
main(int	argc,	char * argv[])	{
	
   information	*dico = NULL, *elm = NULL;
   FILE *fp;
	
   if	(argc	< 2)
      return;
	
   if	((fp = fopen(argv[1], "r")) == NULL) {
      printf("\n Pb d'ouverture du fichier %s \n",	argv[1]);
      return;
   } 
   else {
      char buffer[512];
      int n	= 0;
      int i;
      while	(lireMot(fp, &buffer[0])) {
         //printf("%s ", buffer);
      	//	Trouve l'occurence du mot ou la dernière case du tableau ou initialise dico
         if	(dico	==	NULL){
            dico = malloc(sizeof(information));
            elm =	dico;
         } 
         
         else {
            elm =	find(dico,buffer);
         }
      
         if(elm->mot == NULL){
            //Si mot n'est pas définit on est dans une nouvelle case
            elm->mot	= strdup(buffer);
            elm->occurence=1;
         } else{
            //Sinon on incremente juste le compteur
            elm->occurence++;
         }
         
      
         n++;
      }
      printf("\n\n Il y a %d mots dans %s", n, argv[1]);
   		
         
      elm = dico;
      while(elm != NULL){
         printf("\n %s : %d ",elm->mot,elm->occurence);
         elm = elm->suivant;
      }
      
   }
	
   return 0;
	
}
Пример #6
0
vector <string> jdmRel(string mot1, string mot2){
    //mot1.resize(mot1.size()-1);
    mot1=transformer(&mot1," ","%20");
    mot2=transformer(&mot2," ","%20");

    //http://www.jeuxdemots.org/intern_lexical_signature.php?affichrel_submit=Afficher&term_1=Pulp%20fiction&term_2=film
    vector <string> retour;
    string adresse = "http://www.jeuxdemots.org/intern_lexical_signature.php?affichrel_submit=Afficher&term_1=";
    adresse+=latin1(mot1);
    adresse+="&term_2=";
    adresse+=latin1(mot2);
    //cout<<"adresse : "<<adresse<<endl;
    //pause("adresse");
    string page = ouvrirPage(adresse);
    string relTexte = decouperPage(&page,"div","relations");
    int it=0;
    string rel;
    string score;
    while(lireMot(&it, &relTexte, "<br>")){

        it++;
        lireMot(&it, &relTexte, " -- "); //mot1;
        it++;
        lireMot(&it, &relTexte, "_");
        lireMot(&it, &relTexte, &rel , " : ");
        lireMot(&it, &relTexte, &score , " -->");

        if(atoi(score.c_str())>20){
            retour.push_back(rel);
        }
        //cout<<score<<endl;
        //cout<<atoi(score.c_str())<<endl;
        //cout<<rel<<endl;
        //pause("score");
        score.clear();
        rel.clear();
        //pause("relation");
    }
    return retour;
    //string = decouperPage(&c,"div","relations",&it);
}
Пример #7
0
int main(int argc, char *argv[])
{
    FILE *fichierMot = NULL;
    int nombreMot = 0, positionMot = 0, longeurMot = 0, mot[15];
    int motDeviner[15];
    int entre = 0, positionCaractere = 0, j = 0, i = 0;
    int essaiRestant = 10, nombreEssai = 0;

    fichierMot = fopen("mot", "r");	/* On ouvre le fichier */
    if (fichierMot == NULL) {	/* On teste pour savoir si tou c'est bien passé */
	printf("Le fichier \"mot\" ne peut être ouvert\n");
	return 1;
    }

    nombreMot = compterMot(fichierMot);	/* Compte le nombre de mot */
    /* Ceci est uniquement pour le debugage. */
    printf("Ceci est le nombre de mot dans le fichier 'mot' %d\n",
	   nombreMot);

    /* Position du mot dans la liste de tout les mots. */
    positionMot = nombreAleatoire(nombreMot);

    /* Longeur du mot en caractere. */
    /* On sort la longeur du mot en même temps */
    longeurMot = lireMot(fichierMot, positionMot, mot);
    /* On affiche ensuite la longeur du sus-choisi mot */
    printf("Ceci est la longeur en caractere du mot %d\n", longeurMot);

    /* Initialisation du tableau */
    for (i = 0; i <= longeurMot; i++) {
	motDeviner[i] = '*';
    }
    /* Démarrage du jeu a proprement parler. */
    printf("\nBienvenue dans mon pendu.\n");
    printf("Un mot a été choisi, vous avez 10 chances.\n");
    printf("Bonne chance !\n");

    while (essaiRestant > 0) {	/* Boucle principale */
	int j = 0, k = 0;	/* Afficher le nombre de caractere restant. */
	for (j = 0; j < longeurMot; j++) {
	    printf("%c", motDeviner[j]);
	}

	/* On affiche le prompt. */
	printf("\n> ");
	entre = lireCaractere();

	positionCaractere =
	    comparerCaractere(entre, mot, motDeviner, longeurMot);

	if (positionCaractere != entre) {
	    essaiRestant--;
	    printf
		("Il reste %d essai restant avant une mort certaine...\n",
		 essaiRestant);
	}

	/* Donc on compare les deux tableau de "mot" et
	   on incrémente k a chaque caractere valide */
	for (j = 0; j < longeurMot; j++) {
	    if (mot[j] == motDeviner[j])
		k++;
	}
	/* Si k est égual à longeurMot cela veux dire
	   que les deux chaines sont identiques.
	   Donc, victoire! */
	if (k == longeurMot) {
	    printf("Vous avez gagner! En %d coups!\n", nombreEssai);
	    fclose(fichierMot);
	    return 0;
	}
	nombreEssai++;
    }

    fclose(fichierMot);
    return 0;
}
Пример #8
0
vector<relfind> getNeightboors(string mot, vector<string> relToFind){
    vector<relfind> retour;
    string adresse = "http://www.jeuxdemots.org/rezo-xml.php?gotermsubmit=Chercher";
    string stub = "&gotermrel=";
    string finAdresse = "&output=onlyxml";
    string word = jdmExiste(mot);   //mot orthographié jdm

    if(word != "") {
        string page = ouvrirPage(adresse+stub+latin1(word)+finAdresse);
        string ligne;
        string rel;
        string voisin;
        string poids;
        int i=0;
        int j=0;
        int w = 0;

        bool entrant = false;
        bool sortant = false;

        while(lireMot(&i, &page, &ligne, "<")) {
            j=0;
            if(lireMot(&ligne, "entrant>"))
                entrant = !entrant;

            if(lireMot(&ligne, "sortant>"))
                sortant = !sortant;


            if(lireMot(&j, &ligne, "type=\"")){

                lireMot(&j, &ligne, &rel, "\"");
                lireMot(&j, &ligne, "poids=\"");
                lireMot(&j, &ligne, &poids, "\"");
                w = atoi(poids.c_str());
                lireMot(&j, &ligne, ">");
                lireMot(&j, &ligne, &voisin, "<");


                vector<string>::iterator find_it;
                find_it = find (relToFind.begin(), relToFind.end(), rel);
                if (find_it != relToFind.end() && w > seuil)
                {
                    // on ajoute à la structure
                    relfind r;
                    r.w = w;
                    r.rel = rel;
                    r.cible = voisin;
                    r.sens = !entrant;
                    retour.push_back(r);
                }

                // on rinit les variables
                rel = "";
                voisin = "";
                poids= "";
                w = 0;

            } // fin de la récupération d'une relation

            ligne = "";
        } // fin du parcours des lignes
    }

    return retour;
}