#include "text.hh" #define DEBUG 0 namespace LibCryptAffinity { bool TextCounter::operator< (TextCounter b){ fflush(stdout); if (this->_text.size() < b.getText().size()){ return true; } else if (this->_text.size() == b.getText().size()) { // cas de l'egalité des tailles if (this->_count < b.getCount()){ return true; } else { return false; } } else { // cas du suppérieur return false; } } void TextCounter::setText(Text t){ this->_text = t; } int Text::getCountOf(int c){ int counter =0; int i; for (i=0; isize(); i++){ if ((*this)[i] == c) { counter++; } } return counter; } Text TextCounter::getText(){ return this->_text; } void TextCounter::setCount(int i){ this->_count = i; } int TextCounter::getCount(){ return this->_count; } void TextCounter::setParam(std::list param){ this->_param = param; } std::list TextCounter::getParam(){ return this->_param; } Text::Text(Alphabet alphabet) : std::vector() , _alphabet(alphabet) { // vide au début } Text::Text() : std::vector() { // vide au début } void Text::setAlphabet(Alphabet alpha) { this->_alphabet = alpha; } Alphabet Text::getAlphabet() { return this->_alphabet; } void Text::append(std::string str){ } std::list Text::getRepeatedPatterns(){ // on découpe en patterns de 2 à texte / 3 std::list result; int patternsize; int txt_idx; int pat_idx; bool pattern_active; bool * active = new bool[this->size()]; for (txt_idx=0; txt_idx < this->size(); txt_idx++){ active[txt_idx] = true; } pDEBUG("Text::getRepeatedPatterns","getRepeatedPatterns\n"); int max_patternsize = (this->size() / 3); for (patternsize=max_patternsize; patternsize>1; patternsize--){ std::map counter; std::map > referencer; for (txt_idx = 0; txt_idx < this->size()-patternsize; txt_idx++){ pattern_active = true; Text currentword; for (pat_idx = 0; pat_idx refs = referencer[currentword]; std::list::iterator refsIt; for(refsIt=refs.begin(); refsIt!=refs.end(); refsIt++){ for (pat_idx=0; pat_idx::iterator counterIt; for (counterIt=counter.begin(); counterIt!=counter.end(); counterIt++){ // si la freq est > 1; on l'ajoute a la liste des // mots doublons, avec la freq... if (counterIt->second > 1) { TextCounter tc; tc.setText(counterIt->first); tc.setCount(counterIt->second); tc.setParam(referencer[counterIt->first]); result.push_back(tc); } } } printf("out\n"); result.sort(); result.reverse(); return result; } Text Text::substr(int index, int len){ Text result; int i; for (i=index; isize(); i++){ s+=this->_alphabet[(*this)[i]]; } free(c); s+=">>"; return s; } std::string Text::toString(){ int i; std::string s; s+="[ "; char * c = new char[1024]; for (i=0; isize(); i++){ sprintf(c, "%d ", (*this)[i]); s+=c; } free(c); s+="]"; return s; } } #undef DEBUG