Guest User

Untitled

a guest
Jul 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. void createDataStructures(vector<string> &originalWords, vector< vector<string> > &chains,
  2.  
  3. vector< vector<string> > &endings, const int CHAIN_SIZE)
  4.  
  5. {
  6. for (int i = 0; i<(int)(originalWords.size())-CHAIN_SIZE; i++)
  7. {
  8. //create vectors to insert into chains and endings
  9. vector<string> lhs;
  10. vector<string> rhs;
  11. int n;
  12. for (n=0; n<CHAIN_SIZE; n++)
  13. {
  14. string temp = originalWords[i+n];
  15. lhs.push_back(temp);
  16. }
  17.  
  18. string rhString = ((i+n) < (int)(originalWords.size())) ? originalWords[i+n] : END;
  19. bool inserted = false;
  20.  
  21. //now that we have the lhs and rhs variables, add them to the parrallel vectors.
  22. for (int i = 0; i<(int)(chains.size()); i++) //scan chains for vector to insert
  23. {
  24. if (chains[i] == lhs) //lhs vector already exists in chains
  25. {
  26. endings.at(i).push_back(rhString);
  27. inserted = true;
  28. }
  29. }
  30. //lhs vector does not exist in chains
  31. if (!inserted)
  32. {
  33. chains.push_back(lhs);
  34. endings.push_back(rhs);
  35. }
  36. }
  37.  
  38.  
  39.  
  40. }
Add Comment
Please, Sign In to add comment