// 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);
}
Beispiel #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);
}
Beispiel #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);
	}
}
Beispiel #5
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);
	}
}