public void TestAccuracy() { int correct = 0, total = 0; MostFrequentSentenceAutoSemantic mostFrequentSentenceAutoSemantic = new MostFrequentSentenceAutoSemantic(wordNet, fsm); AnnotatedCorpus corpus1 = new AnnotatedCorpus("../../../new-sentences"); AnnotatedCorpus corpus2 = new AnnotatedCorpus("../../../old-sentences"); for (int i = 0; i < corpus1.SentenceCount(); i++) { var sentence1 = (AnnotatedSentence.AnnotatedSentence)corpus1.GetSentence(i); mostFrequentSentenceAutoSemantic.AutoSemantic(sentence1); var sentence2 = (AnnotatedSentence.AnnotatedSentence)corpus2.GetSentence(i); for (int j = 0; j < sentence1.WordCount(); j++) { total++; AnnotatedWord word1 = (AnnotatedWord)sentence1.GetWord(j); AnnotatedWord word2 = (AnnotatedWord)sentence2.GetWord(j); if (word1.GetSemantic() != null && word1.GetSemantic().Equals(word2.GetSemantic())) { correct++; } } } Assert.AreEqual(549, total); Assert.AreEqual(277, correct); }
private string FindData(string dependent, string head, bool condition1, bool condition2, AnnotatedWord dependentWord, AnnotatedWord headWord) { if (condition1 || condition2) { return("PUNCT"); } switch (dependent) { case "ADVP": if (dependentWord.GetParse().GetRootPos().Equals("VERB")) { return("ADVCL"); } if (dependentWord.GetParse().GetRootPos().Equals("NOUN")) { return("NMOD"); } return("ADVMOD"); case "ADJP": switch (head) { case "NP": if (dependentWord.GetParse().GetRootPos().Equals("VERB")) { return("ACL"); } return("AMOD"); } return("ADVMOD"); case "PP": switch (head) { case "NP": return("CASE"); default: if (dependentWord.GetParse() != null && dependentWord.GetParse().GetRootPos().Equals("NOUN")) { return("NMOD"); } return("ADVMOD"); } case "DP": return("DET"); case "NP": switch (head) { case "NP": if (dependentWord.GetParse().ContainsTag(MorphologicalTag.PROPERNOUN) && headWord.GetParse().ContainsTag(MorphologicalTag.PROPERNOUN)) { return("FLAT"); } if (dependentWord.GetSemantic() != null && headWord.GetSemantic() != null && dependentWord.GetSemantic().Equals(headWord.GetSemantic())) { return("COMPOUND"); } return("NMOD"); case "VP": if (dependentWord.GetSemantic() != null && headWord.GetSemantic() != null && dependentWord.GetSemantic().Equals(headWord.GetSemantic())) { return("COMPOUND"); } if (dependentWord.GetParse().ContainsTag(MorphologicalTag.NOMINATIVE) || dependentWord.GetParse().ContainsTag(MorphologicalTag.ACCUSATIVE)) { return("OBJ"); } return("OBL"); } return("NMOD"); case "S": switch (head) { case "VP": return("CCOMP"); default: return("DEP"); } case "NUM": return("NUMMOD"); case "INTJ": return("DISCOURSE"); case "NEG": return("NEG"); case "CONJP": return("CC"); default: return("DEP"); } }