/// <summary> /// Sentence Parser interface routine /// </summary> /// <param name="input_sentence"></param> public Sentence parse_string_into_words(string input_sentence) { char[] delimiterChars = { ' ', ',', '.', ':', '\t' }; //are there any other delimiters we need to be using? Looks like you got them all string[] words = input_sentence.Split(delimiterChars); // create the sentence Sentence temp_sentence = new Sentence(); // add the word list to the sentence temp_sentence.wordlist = words; string[] nouns = m_nounList.RetrieveWords(); string[] verbs = m_verbList.RetrieveWords(); string[] dictionary = m_dictionary.RetrieveWords(); foreach (string s in words) { //TODO we need to identify each word in this array of words, // as it's sentence component type (right now either noun or verb) // and create a Sentence object (Define this class) that contains the entire list of // words stored as word objects (define this class) bool result = false; // verbs first // compare this particular s value to every t in the verbs list foreach (string t in verbs) { result = s.Equals(t); if (result) { Verb temp = new Verb(); temp.m_value = s; temp_sentence.m_action.m_valueList.Add(temp); result = false; } }// end verbs // compare this particular s value to every t in the verbs list foreach (string n in nouns) { result = false; result = s.Equals(n); if (result) { Noun temp = new Noun(); temp.m_value = s; temp_sentence.m_subj.m_objects.Add(temp); result = false; } }// end nouns }//end foreach word return temp_sentence; }
public InOut() { // the Greetings Class is about outdated and needs to be removed and its functionality placed in a more // logical location such as the sentence class as a type of interjection sentence that functions as a greeting // and access of its word list should go through listener just like nouns and verbs. //yes I probably could have used the xmlDataAccess Class instead of setting up the functionality of the Dictionary class currentSentence = new Sentence(); xmlDataAccess = new XmlDataAccess("XMLGreetinglist.xml"); listener = new Listener(); InitializeComponent(); greetings = new Greetings(xmlDataAccess); currentDictionary = new Dictionary("XMLGreetingList.xml","xmlNounList.xml","xmlVerbList.xml"); }
private void inputWindow_KeyPress(object sender, KeyPressEventArgs e) { string statementS; string statementP; if (e.KeyChar == 13) // 13 is the enter key { foreach (string dictionary in currentDictionary.RetrieveWords()) { bool resultant; resultant = this.inputWindow.Text.Contains(dictionary); bool result; string WordType; WordType = currentDictionary.RetrieveType(this.inputWindow.Text); result = WordType.Contains("interjection"); if (resultant == true && result == true) { Random rnd = new Random(); int index = rnd.Next(1, xmlDataAccess.getNodelistSize()); // creates a number between 1 and the node list size OutputLabel.Text = greetings.Greet[index].ToString(); nounButton.Visible = false; verbButton.Visible = false; greetingButton.Visible = false; return; } else if (resultant == true) { string sentence = inputWindow.Text; currentSentence = listener.parse_string_into_words(sentence); foreach (Noun n in currentSentence.m_subj.m_objects) { statementS = "there is a Subject"; lv_nouns.Items.Add(n.m_value); subjectLabel.Text = n.m_value; Console.WriteLine(statementS); } foreach (Verb v in currentSentence.m_action.m_valueList) { statementP = "there is a predicate"; lv_verbs.Items.Add(v.m_value); predicateLabel.Text = v.m_value; Console.WriteLine( statementP); } OutputLabel.Text = "this could be a sentence"; return; } else { statementS = "there is no subject"; statementP = "there is no predicate"; Console.WriteLine( statementS + " " + statementP); nounButton.Visible = true; verbButton.Visible = true; greetingButton.Visible = true; } } } }
private void parse_Click(object sender, EventArgs e) { string sentence = inputWindow.Text; currentSentence = listener.parse_string_into_words(sentence); try { foreach (string s in currentSentence.wordlist) { lv_words.Items.Add(s); } foreach (Noun n in currentSentence.m_subj.m_objects) { lv_nouns.Items.Add(n.m_value); } foreach (Verb v in currentSentence.m_action.m_valueList) { lv_verbs.Items.Add(v.m_value); } } catch (Exception z) { //need to check all words in sentence before we load them into the catch statement so we can give the user the // opportunity to add new words to the lists. MessageBox.Show("This is a sentence fragment, either nouns or verbs were null." + z.Message); } }