def test_appendix_sections(self): head = "More\n" a5 = "A-5--Some Title\nContent\ncontent\n" a8 = "A-8--A Title\nBody body\nbody body text\ntext text\n" a20 = "A-20--More content\nBody body" text = head + a5 + a8 + a20 offsets = carving.appendix_sections(text, 'A') self.assertEqual(3, len(offsets)) self.assertEqual(a5, text[offsets[0][0]:offsets[0][1]]) self.assertEqual(a8, text[offsets[1][0]:offsets[1][1]]) self.assertEqual(a20, text[offsets[2][0]:offsets[2][1]])
def test_appendix_sections(self): head = "More\n" a5 = "A-5--Some Title\nContent\ncontent\n" a8 = "A-8--A Title\nBody body\nbody body text\ntext text\n" a20 = "A-20--More content\nBody body" text = head + a5 + a8 + a20 offsets = carving.appendix_sections(text, 'A') self.assertEqual(3, len(offsets)) self.assertEqual(a5, text[offsets[0][0]:offsets[0][1]]) self.assertEqual(a8, text[offsets[1][0]:offsets[1][1]]) self.assertEqual(a20, text[offsets[2][0]:offsets[2][1]])
def trees_from(text, part, parent_label): """Build a tree for the appendix section. It will have children for each appendix. Text is the text of the entire regulation, while part is the regulation's part (e.g. 1520.)""" children = [] for begin, end in carving.appendices(text): title, appendix = utils.title_body(text[begin:end]) appendix_letter = carving.get_appendix_letter(title, part) label = parent_label + [appendix_letter] sections = carving.appendix_sections(appendix, appendix_letter) if sections: child = paragraph_tree(appendix_letter, sections, appendix, label, title) else: child = generic_tree(appendix, label, title) children.append(child) return children
def trees_from(text, part, parent_label): """Build a tree for the appendix section. It will have children for each appendix. Text is the text of the entire regulation, while part is the regulation's part (e.g. 1520.)""" children = [] for begin, end in carving.appendices(text): title, appendix = utils.title_body(text[begin:end]) appendix_letter = carving.get_appendix_letter(title, part) label = parent_label + [appendix_letter] sections = carving.appendix_sections(appendix, appendix_letter) if sections: child = paragraph_tree( appendix_letter, sections, appendix, label, title) else: child = generic_tree(appendix, label, title) children.append(child) return children