def setUp(self): self.empty_sa = StandoffAnnotation( os.path.join(FIXTURES_PATH, "valid_sa_file1.xml")) self.has_overlap_sa = StandoffAnnotation( os.path.join(FIXTURES_PATH, "has_overlap1.xml")) self.no_overlap_sa = StandoffAnnotation( os.path.join(FIXTURES_PATH, "no_overlap1.xml"))
class TestPhiWithinRange(unittest.TestCase): def setUp(self): self.has_overlap_sa = StandoffAnnotation( os.path.join(FIXTURES_PATH, "has_overlap1.xml")) def test_returns_all_phi_for_entire_document_range(self): all_phi_maybe = phi_within_range(self.has_overlap_sa, 0, len(self.has_overlap_sa.text)) self.assertEqual(all_phi_maybe, self.has_overlap_sa.get_phi())
class TestSaFilterByPhiAttrs(unittest.TestCase): def setUp(self): self.sa1 = StandoffAnnotation( os.path.join(FIXTURES_PATH, "has_overlap1.xml")) def test_filtering(self): # No PHI will have an attribute of foo self.assertEqual(sa_filter_by_phi_attrs(self.sa1, {"foo": "bar"}), []) # No filters should be the same as all the PHI self.assertEqual(sa_filter_by_phi_attrs(self.sa1, {}), self.sa1.get_phi()) # There should only be one PHI with the id P1. assert (len(sa_filter_by_phi_attrs(self.sa1, {"id": "P1"})) == 1)
def get_sa_from_dir(dirname): """Returns a dictionary in the format of: {"id": <StandoffAnnotation>} This is determined by finding all filenames within dirname that pass is_valid_sa_file. """ sas = [] for filename in os.listdir(dirname): filename = os.path.join(dirname, filename) if is_valid_sa_file(filename): sas.append(StandoffAnnotation(filename)) return dict(zip([sa.id for sa in sas], sas))
def setUp(self): self.has_overlap_sa = StandoffAnnotation( os.path.join(FIXTURES_PATH, "has_overlap1.xml"))
def setUp(self): self.has_overlap_sa = StandoffAnnotation( os.path.join(FIXTURES_PATH, "has_overlap1.xml")) self.document = Document(self.has_overlap_sa.file_name)