Glossygloss  0.2
Glossygloss is set of classes to use several data structure as Tree or hash table.
 All Classes Files Functions Variables Macros Pages
dictionnaire_arbre.hpp
Go to the documentation of this file.
1 
37 #ifndef DICTIONNAIRE_HPP
38 #define DICTIONNAIRE_HPP
39 
40 #include "treestring.hpp"
41 #include <utility>
42 
51 bool triPair(const pair<string, int> &first, const pair<string, int> &second){
52  return first.second > second.second;
53 }
54 
56 
57  private :
59 
60  public :
61 
66 
71 
77  bool contientMot(string mot){
78  bool trouve=false;
79  forward_list<string> list;
80  dico.getWords(list);
81  auto it = list.begin();
82  while(it!=list.end() and !trouve){
83  trouve = (it->compare(mot)==0);
84  ++it;
85  }
86  return trouve;
87 
88  }
89 
94  void ajouterMot(string mot){
95  dico.put(mot);
96  }
97 
103  void associerMot(string mot){
104  dico.put(mot);
105  }
106 
113  int valeurAssociee(string mot){
114  bool trouve=false;
115  forward_list<pair<string,int>> words;
116  dico.getWordsFrequencies(words);
117  auto it = words.begin();
118  while(it!=words.end() and !trouve){
119  trouve = ((it->first).compare(mot)==0);
120  ++it;
121  }
122  return it->second;
123  }
124 
129  void plusFrequentes(pair<string,int> *frequences){
130  forward_list<pair<string, int>> pairs;
131  // on récupère les mots avec leurs fréquences
132  dico.getWordsFrequencies(pairs);
133  // on tri la liste
134  pairs.sort(&triPair); // complexité : n(log(n))
135  auto it_pairs = pairs.begin();
136  int i = 0;
137  // on met les dix premières pairs dans le tableau
138  while(i<10 and pairs.end() != it_pairs){
139  frequences[i++] = *it_pairs;
140  ++it_pairs;
141  }
142  }
143 };
144 
145 #endif // DICTIONNAIRE_HPP
void getWordsFrequencies(forward_list< pair< string, int >> &words)
Definition: treestring.hpp:373
void ajouterMot(string mot)
Definition: dictionnaire_arbre.hpp:94
void getWords(forward_list< string > &list)
Definition: treestring.hpp:364
Tree is a recursive structure using nodes.
Definition: treestring.hpp:304
void plusFrequentes(pair< string, int > *frequences)
Definition: dictionnaire_arbre.hpp:129
bool triPair(const pair< string, int > &first, const pair< string, int > &second)
Definition: dictionnaire_arbre.hpp:51
void associerMot(string mot)
Definition: dictionnaire_arbre.hpp:103
Dictionnaire()
Definition: dictionnaire_arbre.hpp:65
void put(const string &word)
Definition: treestring.hpp:338
~Dictionnaire()
Definition: dictionnaire_arbre.hpp:70
bool contientMot(string mot)
Definition: dictionnaire_arbre.hpp:77
TreeString dico
Definition: dictionnaire_arbre.hpp:58
int valeurAssociee(string mot)
Definition: dictionnaire_arbre.hpp:113
Definition: dictionnaire_arbre.hpp:55