bool Classifier::addVocab( const vector<Document>& docs, map<string, unsigned int>& vocab ) { // Construct list of tokens to ignore. vector<string> tokensToIgnore; try { if ( useIgnoreList == true ) { string tokenFileLoc = ignoreFileLoc; #ifdef WINDOWS tokenFileLoc = str_replace_all( tokenFileLoc, "/", "\\", ':' ); #endif string line; ifstream tokenFile( tokenFileLoc.c_str() ); while ( tokenFile.good() ) { getline( tokenFile, line ); if ( line != "" ) { tokensToIgnore.push_back( line ); } } tokenFile.close(); } if ( useStopWordsList == true ) { string tokenFileLoc = stopFileLoc; #ifdef WINDOWS tokenFileLoc = str_replace_all( tokenFileLoc, "/", "\\", ':' ); #endif string line; ifstream tokenFile( tokenFileLoc.c_str() ); while ( tokenFile.good() ) { getline( tokenFile, line ); if ( line != "" ) { tokensToIgnore.push_back( line ); } } tokenFile.close(); } } catch ( exception& e ) { cout << e.what() << endl; return false; } for ( unsigned int i = 0; i < docs.size(); i++ ) { vector<string> tokens; tokenizeDocument( docs[i], vocabDelimiters, tokensToIgnore, minTokenSize, tokens ); for ( unsigned int j = 0; j < tokens.size(); j++ ) { vocab[tokens[j]]++; } } return true; }
/** * Reads the token form the USB drive inserted and calls the GPII FlowManager, * notifying it that a user with the specified token has logged in. */ int ReadToken(char driveLetter) { tokenFilepath[0]=driveLetter; std::ifstream tokenFile(tokenFilepath); if (tokenFile.is_open()) { std::string token; std::getline(tokenFile, token); tokenMap.insert(std::pair<char, std::string>(driveLetter, token)); CallFlowManager(token, actionLogin); } // TODO Handle errors when opening the file. return 0; }
int DropBoxOperations::authorization(){ QFile tokenFile(tokens); if(!dropbox->requestAccessTokenAndWait()) { int i = 0; for(;i<3; ++i) // we try three times { if(dropbox->error() != QDropbox::TokenExpired) break; } if(i>3) { //qDebug() << "too many tries for authentication"; currentFile = "" ; emit currentdownloadChanged(); return -2; } if(dropbox->error() != QDropbox::NoError) { //qDebug() << "Error: " << dropbox.error() << " - " << dropbox.errorString() << endl; currentFile = "" ; emit currentdownloadChanged(); return -3; } } if(!tokenFile.open(QIODevice::WriteOnly|QIODevice::Truncate|QIODevice::Text)) { currentFile = "" ; emit currentdownloadChanged(); return -5; } QTextStream outstream(&tokenFile); outstream << dropbox->token() << endl; outstream << dropbox->tokenSecret() << endl; tokenFile.close(); currentFile = "" ; emit currentdownloadChanged(); return 0; }
int DropBoxOperations::connect(){ QFile tokenFile(tokens); currentFile = "" ; emit currentdownloadChanged(); currentFile = tr("Connecting DopBox ...") ; emit currentdownloadChanged(); if(tokenFile.exists()) // reuse old tokens { if(tokenFile.open(QIODevice::ReadOnly|QIODevice::Text)) { QTextStream instream(&tokenFile); QString token = instream.readLine().trimmed(); QString secret = instream.readLine().trimmed(); if(!token.isEmpty() && !secret.isEmpty()) { dropbox->setToken(token); dropbox->setTokenSecret(secret); tokenFile.close(); currentFile = "" ; emit currentdownloadChanged(); return 0; } } tokenFile.close(); return -7; } // acquire new token if(!dropbox->requestTokenAndWait()) { //qDebug() << "error on token request"; currentFile = "" ; emit currentdownloadChanged(); return -1; } dropbox->setAuthMethod(QDropbox::Plaintext); if(!dropbox->requestAccessTokenAndWait()) { int i = 0; for(;i<3; ++i) // we try three times { if(dropbox->error() != QDropbox::TokenExpired) break; urlValidation=dropbox->authorizeLink().toString() ; //qDebug()<< "Authoriser application\n"; currentFile = "" ; emit currentdownloadChanged(); return -4; } if(i>3) { //qDebug() << "too many tries for authentication"; currentFile = "" ; emit currentdownloadChanged(); return -2; } if(dropbox->error() != QDropbox::NoError) { //qDebug() << "Error: " << dropbox.error() << " - " << dropbox.errorString() << endl; currentFile = "" ; emit currentdownloadChanged(); return -3; } } // if(!tokenFile.open(QIODevice::WriteOnly|QIODevice::Truncate|QIODevice::Text)) { // currentFile = "" ; // emit currentdownloadChanged(); // return -5; // } // QTextStream outstream(&tokenFile); // outstream << dropbox->token() << endl; // outstream << dropbox->tokenSecret() << endl; // tokenFile.close(); // currentFile = "" ; // emit currentdownloadChanged(); return 0; }