// hashStringFile() // Requires: std::string reference, FLLengthMap **, FLStringSet ** // Returns: bool // The function takes a string reference to a file name and attempts to open // the file. Failure causes an immediate exit. // On success, it initializes the provided double pointers with a new empty // string set and length map (hash). For each line in the file, it "cleans" // the word in the line and then measures its length. It adds a non-empty // word to the string set and adds the pointer to the inserted word into // a vector in the length map, keyed by the length of the word. // A set insertion failure will terminate the function early and return false. bool hashStringFile(std::string &fileName, FLLengthMap **sizeHash, FLStringSet **stringSet) { std::ifstream fileStream(fileName); if(!fileStream.good()) { printf("ERROR: Couldn't open file %s for input.\n", fileName.c_str()); exit(1); } *stringSet = new FLStringSet; *sizeHash = new FLLengthMap; size_t lineLen; for(std::string line; std::getline(fileStream, line);) { cleanWord(line); lineLen = line.length(); if(lineLen > 0) { // if(kDoDebug) printf("Adding word %s of length %lu\n", line.c_str(), lineLen); std::pair<FLSetIterator, bool> insertResult = (*stringSet)->insert(line); if(insertResult.second) { // NOTE: STL hash creates new vectors automatically when using [] operator with an unknown key. (**sizeHash)[lineLen].push_back((std::string *)&(*(insertResult.first))); } else { printf("ERROR: A string was not inserted into the string set.\n"); fileStream.close(); return false; } } } fileStream.close(); return true; }
/* * Reads file of specified fileName and stores word frequency into * wordData linked list. int story indicates which story count to increment. */ void readFile(wordData **firstWord, char* fileName, int story) { FILE *infile = fopen(fileName, "r"); char tempWord[WORD_LENGTH]; while(fscanf(infile, "%s", tempWord) == 1) { if (searchWord(*firstWord, cleanWord(tempWord), story) == 0) insertWord(firstWord, tempWord, story); } }
wordsImporter::wordsImporter(bool backTrans, QString src, QString dst, QObject * parent) : QObject(parent) , backTranslation(backTrans) { words = new wordsBuilder (QString("%1-%2-%2").arg(src).arg(dst)); cleanWords = new wordsBuilder (QString("%1-%2-%2").arg(src).arg(dst)); backtransl = new wordsBuilder (QString("%1-%2-%2").arg(src).arg(dst)); pica = new picturesDownloader(); sndUrl = new soundUrlExtractor(QString("%1-%2").arg(src).arg(dst)); sndDownloader = new urlDownloader (); connect (this, SIGNAL(wowNewWord(QString)), words, SLOT(add(QString)), Qt::QueuedConnection); connect (words, SIGNAL(cleanWord(QString)), cleanWords, SLOT(add(QString)), Qt::QueuedConnection); connect (cleanWords, SIGNAL(cleanWord(QString, QByteArray)), this, SLOT(returnWord(QString, QByteArray)), Qt::QueuedConnection); connect (this, SIGNAL(translateItBack(QString)), backtransl, SLOT(add(QString)), Qt::QueuedConnection); connect (this, SIGNAL(picturize(QString)), pica, SLOT(add(QString)), Qt::QueuedConnection); connect (this, SIGNAL(soundize(QString)), sndUrl, SLOT(add(QString)), Qt::QueuedConnection); connect (sndUrl, SIGNAL(downloadUrl(QString, QUrl)), sndDownloader, SLOT(add(QString, QUrl)), Qt::QueuedConnection); connect (sndDownloader, SIGNAL(downloadDone(QString, QByteArray)), this, SLOT(saveSnd(QString, QByteArray)), Qt::QueuedConnection); connect (backtransl, SIGNAL(cleanWord(QString, QByteArray)), this, SLOT(saveCard(QString, QByteArray)), Qt::QueuedConnection); }
InstrumentData::InstrumentData(const QString& dataIn) { rawInput = dataIn; qDebug()<< dataIn; QTextStream textin(&rawInput); QString word; while( textin.status() == QTextStream::Ok) { textin >> word; word = cleanWord(word); if(word != "" && word != "Stone") Words.push_back(word); //special case stuff } TestDate = toQDate(); TestTime = toQTime(); TestDateTime = toQDateTime(); TestMaterial = toMaterial(); TestReading = readingToDouble(); TestPercentage = percentageToDouble(); }