// add: add word to suffix list, update prefix
void add(Prefix& prefix, const string& s)
{
	if (prefix.size() == NPREF) {
		statetab[prefix].push_back(s);
		prefix.pop_front();
	}
	prefix.push_back(s);
}
Exemplo n.º 2
0
void AddEntry(Prefix& prefix, const string& suffix)
{
	if (prefix.size() == PREFIX_LENGTH) {
		dictionary[prefix].push_back(suffix);
		prefix.pop_front();
	}
	prefix.push_back(suffix);
}
Exemplo n.º 3
0
 void add(Prefix& prefix, string& new_word)
 {
      if(prefix.size() == prefix_len_)
      {
          state_list[prefix].push_back(new_word);
          prefix.pop_front();
      } 
      prefix.push_back(new_word);
 }
// generate: produce output, one word per line
void generate(int nwords)
{
	Prefix prefix;
	int i;

	for (i = 0; i < NPREF; i++)
		add(prefix, NONWORD);
	for (i = 0; i < nwords; i++) {
		vector<string>& suf = statetab[prefix];
		const string& w = suf[rand() % suf.size()];
		if (w == NONWORD)
			break;
		cout << w << "\n";
		prefix.pop_front();	// advance
		prefix.push_back(w);
	}
}
Exemplo n.º 5
0
   void generate(int ows, size_t pl)
   {
      outwords_ = ows;
      prefix_len_ = pl;
      string buff;
      Prefix prefix;
      for(size_t j=0; j < prefix_len_; ++j)
         {
            prefix.push_back("\n");
         }

      ifstream infile (filename_);

      while(!getline(infile,buff).eof())
      {
         parse_words(prefix, buff);
      }

      gen_output();
   }
Exemplo n.º 6
0
void GenerateText(int wordCount, ofstream& outFile)
{
	Prefix prefix;
	int i;
	for (i = 0; i < PREFIX_LENGTH; i++){
		AddEntry(prefix, NONWORD);
	}
		
	for (i = 0; i < wordCount; i++) {
		vector<string>& suffix = dictionary[prefix]; 
		const string& word = suffix[rand() % suffix.size()];
		if (word == NONWORD){
			break;
		}
			
		outFile << word << " ";
		//shift the prefix by a word, to keep generating.
		prefix.pop_front();
		prefix.push_back(word);
	}
}