void CopyWordCounts( WordCount& targetWordCount, WordCount& sourceWordCount, int weight ) { for( wciter iwc=sourceWordCount.begin(); iwc!=sourceWordCount.end(); iwc++ ) { if( targetWordCount.find( iwc->first ) == targetWordCount.end() ) targetWordCount[ iwc->first ] = 0; targetWordCount[ iwc->first ] += weight * iwc->second; } }
int main(int argc, char* argv[]) { timeval start,end; double difference,t1,t2; char *str1; string str2; int cnt=1; int i=0; if(argc!=2) { cout<<"Please enter an input file :-"; return 0; } str1=argv[1]; FileReader reader; //Instantiate class FileReadermas std::string s=reader.readFile(str1); //Call to function read WordCount word; //Instantiate class word gettimeofday(&start, NULL); t1 = start.tv_sec + start.tv_usec/1000000.0; word.count(s); //call to function count t2 = end.tv_sec + end.tv_usec/1000000.0; difference=t2 - t1; //cout<<"Map time:"<<difference*1000000<<" microseconds"<<endl; Node* n; Tree* t = new Tree(); stringstream str(s); gettimeofday(&start, NULL); t1 = start.tv_sec + start.tv_usec/1000000.0; while(str>>str2) { t->insert(pair<string,int>(str2,cnt)); } t2 = end.tv_sec + end.tv_usec/1000000.0; difference=t2 - t1; //cout<<"Red Black Tree time:"<<difference*1000000<<" microseconds"<<endl; t->inorder(t->getRoot()); //t->height(t->getRoot()); return 0; }
void DumpPositionTable( PositionText& ptext ) { for( ptiter ip=ptext.begin(); ip!=ptext.end(); ip++ ) { cout << "DumpPositionTable for key value ='" << ip->first << "'" << endl; WordCount* wc = ip->second; for( wciter iwc=wc->begin(); iwc!=wc->end(); iwc++ ) { cout << iwc->first << ": " << iwc->second << endl; } } }
int main(int argc, const char *argv[]) { WordCount count; string infile; cout << "Input a filename to read:" << endl; cin >> infile; count.readfile(infile); string outfile; cout << "Input a filename to write:" << endl; cin >> outfile; count.writefile(outfile); return 0; }
string GetMaxWord( WordCount& wordCount ) { string word; int maxCount = 0; for( wciter iwc=wordCount.begin(); iwc!=wordCount.end(); iwc++ ) { // cout << iwc->first << ": " << iwc->second << endl; if( iwc->second > maxCount ) { word = iwc->first; maxCount = iwc->second; } } return word; }
// impl by chenshuo void sort_words_by_frequencies(const WordCount& counts) { typedef std::vector<std::pair<int, WordCount::const_iterator> > FreqList; FreqList freq; freq.reserve(counts.size()); for (WordCount::const_iterator it = counts.begin(); it != counts.end(); ++it) { freq.push_back(make_pair(it->second, it)); } std::sort(freq.begin(), freq.end(), Greater()); for (FreqList::iterator itr = freq.begin(); itr!=freq.end(); ++itr) { std::cout << itr->first << '\t' << itr->second->first << '\n'; } }
void TranslateNumber::Translate(char buffer) { extern vector <DataBase> m_NumLib; WordCount Wc; ToSTL stl; stl.GetData(NumPrefix); Wc.AddWordNumber(); for (int i = 0;i < m_NumLib.size();i++) { if (buffer == m_NumLib[i].Ch[0]) { stl.GetData(m_NumLib[i].Value); Wc.AddWordNumber(); break; } } }
int show(int ac, const char ** av, std::vector<Summary> * sum) { int level = 1; if ( ac > 1 ) level = std::atoi(av[1]); cout << "\nFluency Bad Need New Old When Name\n"; cout << "=====================================================\n"; Show data; WordCount wc; showr(".", data, level, sum, &wc); cout << "-----------------------------------------------------\n"; output_les_stat(data.st, data.flue); cout << '\n'; cout << '\n' << wc.str() << '\n'; return 0; }
int main(int argc, char* argv[]) { char *str1; if(argc!=2) { cout<<"Please enter an input file :-"; return 0; } str1=argv[1]; FileReader reader; //Instantiate class FileReader std::string s=reader.readFile(str1);//Call to function read WordCount word; //Instantiate class word word.count(s); //call to function count return 0; }
int wordc(int ac, const char ** av) { if (ac < 2) { cout << "Use: -wc {srt or txt file}\n"; cout << "word count statistics\n"; return 1; } string fi = av[1]; bool srt = false; try { int sz = fi.size(); if ( sz < 5 ) throw 1; if ( fi.substr(sz - 4) == ".srt" ) srt = true; } catch (int) { throw "Input file must be .srt or .txt"; } cout << "Input : " << fi << '\n'; WordCount wc; if (srt) { Lesson si(fi, true, true); wc = si.wordcount(); } else { wc = wordcount(gl::file2str(fi)); } cout << wc.str() << '\n'; return 0; }
string GetRandWord( WordCount& wordCount, int accumulation ) { WordCount wordTable; int totalCount = 0; // cout << "-----[ RANDOM TABLE ]-----" << endl; int terminalWeight = 0; if( accumulation > 5 ) { int distance = accumulation - 5; terminalWeight = distance * distance * distance; } for( wciter iwc=wordCount.begin(); iwc!=wordCount.end(); iwc++ ) { totalCount += iwc->second * iwc->second; if( iwc->first == BEGIN_KEY || iwc->first == END_KEY ) { totalCount += terminalWeight; } wordTable[ iwc->first ] = totalCount; // cout << totalCount << " " << iwc->first << endl; } int roll = rand() % totalCount; // cout << " --> roll: " << roll << endl; totalCount = 0; string word; // cout << "-----[ SAME TABLE? ]-----" << endl; for( wciter iwc=wordTable.begin(); iwc!=wordTable.end(); iwc++ ) { // cout << iwc->second << " " << iwc->first << endl; if( roll <= iwc->second ) { word = iwc->first; break; } } // cout << " --> word: " << word << endl; return word; }
void ExtractLex::Process(WordCount &wcIn, const std::string *out) { std::map<const std::string*, WordCount> &collOut = wcIn.GetColl(); WordCount &wcOut = collOut[out]; wcOut.AddCount(COUNT_INCR); }
int main( int argc, char* argv[] ) { bool isEnd; string triplet, pair, token, word; string peripenultimate = WORD_KEY; string penultimate = WORD_KEY; string previous = BEGIN_KEY; WordCount mainWordCount; while( true ) { cin >> token; if( token == END_KEY ) break; word = Convert( token, isEnd ); cout << "READ WORD FROM INPUT: " << word << endl; if( mainWordCount.find( word ) == mainWordCount.end() ) { mainWordCount[ word ] = 0; } ++mainWordCount[ word ]; AddCount( PreText, word, previous ); AddCount( PostText, previous, word ); if( penultimate != WORD_KEY ) { pair = previous + " " + word; AddCount( PrePairText, pair, penultimate ); pair = penultimate + " " + previous; AddCount( PostPairText, pair, word ); if( penultimate != WORD_KEY ) { triplet = penultimate + " " + previous + " " + word; AddCount( PreTripletText, triplet, peripenultimate ); triplet = peripenultimate + " " + penultimate + " " + previous; AddCount( PostTripletText, triplet, word ); } } if( isEnd ) { AddCount( PostText, word, END_KEY ); if( previous != WORD_KEY ) { pair = previous + " " + word; AddCount( PostPairText, pair, END_KEY ); if( penultimate != WORD_KEY ) { triplet = penultimate + " " + previous + " " + word; AddCount( PostTripletText, triplet, END_KEY ); } } previous = BEGIN_KEY; peripenultimate = WORD_KEY; penultimate = WORD_KEY; } else { peripenultimate = penultimate; penultimate = previous; previous = word; } } // cout << endl; cout << "PreText" << endl; DumpPositionTable( PreText ); cout << "PostText" << endl; DumpPositionTable( PostText ); cout << "PrePairText" << endl; DumpPositionTable( PrePairText ); cout << "PostPairText" << endl; DumpPositionTable( PostPairText ); cout << "PreTripletText" << endl; DumpPositionTable( PreTripletText ); cout << "PostTripletText" << endl; DumpPositionTable( PostTripletText ); while(1) { cin >> word; if( word == END_KEY ) break; word = Convert( word, isEnd ); // cout << endl << "create utterance for word: " << word << endl; penultimate = WORD_KEY; previous = WORD_KEY; BackTrack( penultimate, previous, word ); int accumulation = 0; while( word != END_KEY ) { cout << word; pair = previous + " " + word; triplet = penultimate + " " + previous + " " + word; // cout << endl << "pair='" << pair << "'" << endl; // cout << "triplet='" << triplet << "'" << endl; peripenultimate = penultimate; penultimate = previous; previous = word; WordCount wordCount; if( PostTripletText.find(triplet) != PostTripletText.end() ) { // cout << " -> call GetRandWord( PostTripletText[" << triplet << "] )" << endl; // word = GetRandWord( *PostTripletText[triplet], accumulation++ ); CopyWordCounts( wordCount, *PostTripletText[triplet], 9 ); } else if( PostPairText.find(pair) != PostPairText.end() ) { // cout << " -> call GetRandWord( PostPairText[" << pair << "] )" << endl; // word = GetRandWord( *PostPairText[pair], accumulation++ ); CopyWordCounts( wordCount, *PostPairText[pair], 3 ); } else { // cout << " -> call GetRandWord( PostText[" << word << "] )" << endl; // word = GetRandWord( *PostText[word], accumulation++ ); CopyWordCounts( wordCount, *PostText[word], 1 ); } word = GetRandWord( wordCount, accumulation++ ); if( word == END_KEY ) cout << "." << endl << endl; else cout << " "; } } }