/*
 * University of Utah
 * 2003 High School Programming Contest
 * Question Answering
 *
 * Filename: sentence.cpp
 * 
 * Description: 
 * Implementation of sentence object.  See sentence.h for
 * complete description of class.
 *
 * Modification History:
 * 2/18/2003 - Initial Release
 */

#include <iostream>
#include "sentence.h"

using namespace std;

sentence::sentence(string s) {
  // Store the original version of the sentence so that we can be sure
  // to output the sentence as it was original read in if it is the 
  // answer.
  origSentence = s;
  
  // Parse the sentence into individual words.  
  // Strip out all punctuation
  string temp = s;
  for (int i = 0; i < temp.length(); i++) {
    if (!isalnum(temp[i]))
      temp[i] = ' ';
    temp[i] = tolower(temp[i]);
  }
  
  // Divide sentence into individual words.  This makes it easier
  // to do key word matching.
  int lastPos = temp.find_first_not_of(' ', 0);
  int pos = temp.find_first_not_of(' ', lastPos);
  while (string::npos != pos || string::npos != lastPos) {
    push_back(temp.substr(lastPos, pos - lastPos));
    lastPos = temp.find_first_not_of(' ', pos);
    pos = temp.find_first_of(' ', lastPos);
  }
}

string sentence::originalSentence() {
  return origSentence;
}


