public void GetDay() { PluginTellBirthday _Tell = new PluginTellBirthday(); List<Word> wlist = new List<Word>(); Word w1 = new Word("Welcher"); Word w2 = new Word("Tag"); w2.Type = 'N'; Word w3 = new Word("Geburtstag"); w3.Type = 'N'; Word w4 = new Word("am"); Word w5 = new Word("31/12/2000"); w5.Type = 'N'; Word w6 = new Word("?"); wlist.Add(w1); wlist.Add(w2); wlist.Add(w3); wlist.Add(w4); wlist.Add(w5); wlist.Add(w6); string answ = _Tell.CalculateSentence(wlist); Console.WriteLine(answ); Assert.That(answ == "Der 31/12/2000 war ein Sunday!" || answ == "Der 31/12/2000 war ein Sunday! \nOh, du hast heute Geburtstag. Ich wünsche dir alles Gute!"); }
public void GetLastPriorityTest() { Word w1 = new Word("Straßen"); w1.Type = 'S'; wordlist.Add(w1); Word w2 = new Word("sind"); w2.Type = 'V'; wordlist.Add(w2); Word w3 = new Word("Straßen"); w3.Type = 'N'; wordlist.Add(w3); Word w4 = new Word("Kind"); w4.Type = 'N'; wordlist.Add(w4); Word w5 = new Word("!"); w5.Type = 'M'; wordlist.Add(w5); int prior = navi.GetPriority(wordlist); Assert.AreEqual(2, prior); }
public void GetAPriorityTest() { Word w1 = new Word("Wo"); w1.Type = 'Q'; wordlist.Add(w1); Word w2 = new Word("ist"); w2.Type = 'V'; wordlist.Add(w2); Word w3 = new Word("die"); w3.Type = 'R'; wordlist.Add(w3); Word w4 = new Word("Alserstrasse"); w4.Type = 'N'; wordlist.Add(w4); Word w5 = new Word("?"); w5.Type = 'M'; wordlist.Add(w5); int prior = navi.GetPriority(wordlist); Assert.AreEqual(10, prior); }
public void GetAnotherPriorityTest() { Word w1 = new Word("Ich"); w1.Type = 'S'; wordlist.Add(w1); Word w2 = new Word("habe"); w2.Type = 'V'; wordlist.Add(w2); Word w3 = new Word("eine"); w3.Type = 'X'; wordlist.Add(w3); Word w4 = new Word("Straße"); w4.Type = 'N'; wordlist.Add(w4); Word w5 = new Word("!"); w5.Type = 'M'; wordlist.Add(w5); int prior = navi.GetPriority(wordlist); Assert.AreEqual(2, prior); }
public void GetPriorityTest() { List<Word> _wlist = new List<Word>(); Word w1 = new Word("Meine"); Word w2 = new Word("Familie"); w2.Type = 'N'; Word w3 = new Word("ist"); Word w4 = new Word("mir"); Word w5 = new Word("wichtig"); Word w6 = new Word("."); _wlist.Add(w1); _wlist.Add(w2); _wlist.Add(w3); _wlist.Add(w4); _wlist.Add(w5); _wlist.Add(w6); int prior = _Psych.GetPriority(_wlist); Assert.AreEqual(5, prior); }
public void GetAnotherPriorityTest() { List<Word> _wlist = new List<Word>(); Word w1 = new Word("Mein"); Word w2 = new Word("Hund"); w2.Type = 'N'; Word w3 = new Word("gehört"); Word w4 = new Word("zur"); Word w5 = new Word("Familie"); w5.Type = 'N'; Word w6 = new Word("."); _wlist.Add(w1); _wlist.Add(w2); _wlist.Add(w3); _wlist.Add(w4); _wlist.Add(w5); _wlist.Add(w6); int prior = _Psych.GetPriority(_wlist); Assert.AreEqual(10, prior); }
/* Split sentence and add it to List<Word> AnalysedWords */ public void SplitSentence(string sentence) { //pass and split sentence char mark; //punctuation mark int len = 0; len = sentence.Length; //save punctuation mark if (sentence.LastIndexOf('.') == len - 1) { mark = '.'; } else if (sentence.LastIndexOf('?') == len - 1) { mark = '?'; } else if (sentence.LastIndexOf('!') == len - 1) { mark = '!'; } else { string errmsg = "Der Satz endet nicht mit einem '.', '!' oder '?' - woher soll ich wissen, was du meinst?"; throw new InvalidSentenceException(errmsg); } char[] seps = { ' ', '.', '?', '!' }; string[] words = sentence.Split(seps); //create word-instance for each word and save it into list AnalysedWords = new List<Word>(); int pos = 0; foreach(string w in words) { Word nword = new Word(w); nword.Position = pos++; nword.Type = this.GetType(nword, mark); AnalysedWords.Add(nword); } //remove newline - add punctuation mark instead Word punct = new Word(mark.ToString()); punct.Type = 'M'; punct.Position = pos-1; AnalysedWords.RemoveAt(AnalysedWords.Count-1); AnalysedWords.Add(punct); }
/* Try to guess type of word and save it in variable "Type" */ /* S...subject, N...noun, V...Verb, A...adjective, R...article, P...preposition, M...Punctuation Mark, Q...Question word, C...Math(Calc) */ /* Not found - 'X' */ private char GetType(Word w, char mark) { // will be the case at the last word (is deleted later) if (w.Value.Length == 0) { return 'X'; } // save first character and then make everything lowercase char firstletter = w.Value[0]; // add mathematical symbols if (firstletter == '+' || firstletter == '-' || firstletter == '*' || firstletter == '/') { return 'C'; } else if (_Subject.Contains(w.Value.ToLower())) { return 'S'; } // if first letter is uppercase and word is at position 1 -> Subject! else if (w.Value[0] == char.ToUpper(firstletter) && w.Position == 1) { return 'S'; } // if first letter is uppercase -> noun else if (w.Value[0] == char.ToUpper(firstletter) && w.Position != 0) { return 'N'; } else if (_QuestionWords.Contains(w.Value.ToLower()) && mark == '?') { return 'Q'; } else if (_Articles.Contains(w.Value.ToLower()) && mark == '.') { return 'R'; } else if (_Articles.Contains(w.Value.ToLower()) && mark == '?' && w.Position != 0) { return 'R'; } else { return 'X'; } }
public void SearchTest() { List<Word> wordlist = new List<Word>(); Word w1 = new Word("Wo"); w1.Type = 'Q'; Word w2 = new Word("ist"); w2.Type = 'X'; Word w3 = new Word("Merzenstein"); w3.Type = 'N'; Word w4 = new Word("?"); w4.Type = 'M'; wordlist.Add(w1); wordlist.Add(w2); wordlist.Add(w3); wordlist.Add(w4); _Navi.LoadMap(); string answer = _Navi.CalculateSentence(wordlist); Assert.That(answer.Contains("Zwettl")); Console.WriteLine(answer); }