def test_get_annotation(self): x = classes.SentenceStructure("The blood pressure was 150/86 ; pulse 82 ; respirations 16 .") x.original_sentence_array[0][1] = 'test' x.original_sentence_array[1][1] = 'test' x.original_sentence_array[2][1] = 'test' x.original_sentence_array[6][1] = 'test' x.original_sentence_array[9][1] = 'test' x1, x2, x3 = agent.get_annotation(x.original_sentence_array, 0) self.assertEqual(x1, 0) self.assertEqual(x2, 2) self.assertEqual(x3, 'test') x1, x2, x3 = agent.get_annotation(x.original_sentence_array, x2+1) self.assertEqual(x1, 6) self.assertEqual(x2, 6) self.assertEqual(x3, 'test') x1, x2, x3 = agent.get_annotation(x.original_sentence_array, x2+1) self.assertEqual(x1, 9) self.assertEqual(x2, 9) self.assertEqual(x3, 'test') x1, x2, x3 = agent.get_annotation(x.original_sentence_array, x2+1) self.assertEqual(x1, None) self.assertEqual(x2, None) self.assertEqual(x3, None)
def test_SentenceStructure_init_test(self): x = classes.SentenceStructure("I am a test string") self.assertEqual(x.original_sentence, "I am a test string") self.assertEqual(len(x.original_sentence_array), 5) self.assertEqual(x.original_sentence_array[0][0], "I") self.assertEqual(x.original_sentence_array[1][0], "am") self.assertEqual(x.original_sentence_array[2][0], "a") self.assertEqual(x.original_sentence_array[3][0], "test") self.assertEqual(x.original_sentence_array[4][0], "string")
def test_annotate_sentence_structure(self): ss = classes.SentenceStructure("Pt took his medicine") an = classes.Annotation('c="his medicine" 1:2 1:3||t="treatment"') annotations = [an] modified_ss = run.annotate_sentence_structure(ss, annotations) self.assertEqual(modified_ss.original_sentence_array[0], ['Pt', '']) self.assertEqual(modified_ss.original_sentence_array[1], ['took', '']) self.assertEqual(modified_ss.original_sentence_array[2], ['his', 'treatment']) self.assertEqual(modified_ss.original_sentence_array[3], ['medicine', 'treatment'])
def test_SentenceStructureInitTest(self): x = classes.SentenceStructure("I am a test string") self.assertEqual(x.originalSentence, "I am a test string") self.assertEqual(len(x.originalSentenceArray), 6) self.assertEqual(x.originalSentenceArray[0][0], "I") self.assertEqual(x.originalSentenceArray[1][0], "am") self.assertEqual(x.originalSentenceArray[2][0], "a") self.assertEqual(x.originalSentenceArray[3][0], "test") self.assertEqual(x.originalSentenceArray[4][0], "string") self.assertEqual(x.originalSentenceArray[5][0], "END")
def test_preprocessing(self): test_dict = {} test_list = [] test_list.append(classes.SentenceStructure("3/13/2006 12:00:00 AM")) test_list.append(classes.SentenceStructure("03/19/06 AT 01:00 PM")) test_list.append(classes.SentenceStructure("Take with 8 oz of plain water SPIRIVA ( TIOTROPIUM ) 18")) test_list.append(classes.SentenceStructure("Dr. Pump 3/25/05 1:30 ,")) test_list.append(classes.SentenceStructure("1. TIKWELD , WILLAIDE V. , M.D. ( QT296 ) 03/19/06 10:53 AM")) test_list[0].modified_sentence = preprocess(test_list[0].original_sentence).lower() test_list[0].generate_modified_sentence_array() test_list[1].modified_sentence = preprocess(test_list[1].original_sentence).lower() test_list[1].generate_modified_sentence_array() test_list[2].modified_sentence = preprocess(test_list[2].original_sentence).lower() test_list[2].generate_modified_sentence_array() test_list[3].modified_sentence = preprocess(test_list[3].original_sentence).lower() test_list[3].generate_modified_sentence_array() test_list[4].modified_sentence = preprocess(test_list[4].original_sentence).lower() test_list[4].generate_modified_sentence_array() test_dict["0"] = test_list #Tests self.assertEqual(len(test_dict["0"][0].original_sentence_array), len(test_dict["0"][0].modified_sentence_array)) self.assertEqual(len(test_dict["0"][1].original_sentence_array), len(test_dict["0"][1].modified_sentence_array)) self.assertEqual(len(test_dict["0"][2].original_sentence_array), len(test_dict["0"][2].modified_sentence_array)) self.assertEqual(len(test_dict["0"][3].original_sentence_array), len(test_dict["0"][3].modified_sentence_array)) self.assertEqual(len(test_dict["0"][4].original_sentence_array), len(test_dict["0"][4].modified_sentence_array)) self.assertEqual(test_dict["0"][0].modified_sentence_array[0][0], 'date') self.assertEqual(test_dict["0"][0].modified_sentence_array[1][0], "date") self.assertEqual(test_dict["0"][0].modified_sentence_array[2][0], "am") self.assertEqual(test_dict["0"][1].modified_sentence_array[0][0], "date") self.assertEqual(test_dict["0"][1].modified_sentence_array[1][0], "at") self.assertEqual(test_dict["0"][1].modified_sentence_array[2][0], "date") self.assertEqual(test_dict["0"][1].modified_sentence_array[3][0], "pm") self.assertEqual(test_dict["0"][2].modified_sentence_array[0][0], "take") self.assertEqual(test_dict["0"][2].modified_sentence_array[1][0], "with") self.assertEqual(test_dict["0"][2].modified_sentence_array[2][0], "num") self.assertEqual(test_dict["0"][2].modified_sentence_array[3][0], "oz") self.assertEqual(test_dict["0"][2].modified_sentence_array[4][0], "of") self.assertEqual(test_dict["0"][2].modified_sentence_array[5][0], "plain") self.assertEqual(test_dict["0"][2].modified_sentence_array[6][0], "water") self.assertEqual(test_dict["0"][2].modified_sentence_array[7][0], "spiriva") self.assertEqual(test_dict["0"][2].modified_sentence_array[8][0], "(") self.assertEqual(test_dict["0"][2].modified_sentence_array[9][0], "tiotropium") self.assertEqual(test_dict["0"][2].modified_sentence_array[10][0], ")") self.assertEqual(test_dict["0"][2].modified_sentence_array[11][0], "num") self.assertEqual(test_dict["0"][3].modified_sentence_array[0][0], "dr.") self.assertEqual(test_dict["0"][3].modified_sentence_array[1][0], "pump") self.assertEqual(test_dict["0"][3].modified_sentence_array[2][0], "date") self.assertEqual(test_dict["0"][3].modified_sentence_array[3][0], "date") self.assertEqual(test_dict["0"][3].modified_sentence_array[4][0], ",") self.assertEqual(test_dict["0"][4].modified_sentence_array[0][0], "1.") self.assertEqual(test_dict["0"][4].modified_sentence_array[1][0], "tikweld") self.assertEqual(test_dict["0"][4].modified_sentence_array[2][0], ",") self.assertEqual(test_dict["0"][4].modified_sentence_array[3][0], "willaide") self.assertEqual(test_dict["0"][4].modified_sentence_array[4][0], "v.") self.assertEqual(test_dict["0"][4].modified_sentence_array[5][0], "m.d.") self.assertEqual(test_dict["0"][4].modified_sentence_array[6][0], "(") self.assertEqual(test_dict["0"][4].modified_sentence_array[7][0], "qt296") self.assertEqual(test_dict["0"][4].modified_sentence_array[8][0], ")") self.assertEqual(test_dict["0"][4].modified_sentence_array[9][0], "date") self.assertEqual(test_dict["0"][4].modified_sentence_array[10][0], "date") self.assertEqual(test_dict["0"][4].modified_sentence_array[11][0], "am")