Esempio n. 1
0
    def test_match_labels_and_changes_candidate(self):
        labels_amended = [
            Amendment('POST', '200-2'),
            Amendment('PUT', '200-2-a-1-i')
        ]

        n1 = Node('n2', label=['200', '2'])
        n2 = Node('n2a', label=['200', '2', 'i'])

        n1.children = [n2]
        root = Node('root', label=['200'], children=[n1])

        amend_map = changes.match_labels_and_changes(labels_amended, root)

        self.assertTrue(amend_map['200-2-a-1-i'][0]['candidate'])
        self.assertTrue(amend_map['200-2-a-1-i'][0]['node'].label_id(),
                        '200-2-a-1-i')
def build_supplement_tree(reg_part, node):
    """ Build the tree for the supplement section. """
    title = get_app_title(node)
    root = Node(node_type=Node.INTERP,
                label=[reg_part, Node.INTERP_MARK],
                title=title)

    return parse_from_xml(root, node.getchildren())
Esempio n. 3
0
 def test_sub_comment(self):
     text = "refer to comment 36(a)(2)-3 of thing"
     result = self.parser.process(Node(text, label=['222', '87']))
     self.assertEqual(1, len(result))
     self.assertEqual(['222', '36', 'a', '2', Node.INTERP_MARK, '3'],
                      result[0]['citation'])
     offsets = result[0]['offsets'][0]
     self.assertEqual('36(a)(2)-3', text[offsets[0]:offsets[1]])
Esempio n. 4
0
    def test_resolve_candidates_double_delete(self):
        """In the unfortunate case where *two* candidates are wrong make
        sure we don't blow up"""
        amend_map = {}

        n1 = Node('n1', label=['200', '1', 'i'])
        n2 = Node('n2', label=['200', '1', 'i'])
        amend_map['200-1-a-i'] = [{
            'node': n1,
            'candidate': True
        }, {
            'node': n2,
            'candidate': True
        }]
        amend_map['200-1-i'] = []
        changes.resolve_candidates(amend_map, warn=False)
        self.assertEqual(1, len(amend_map.keys()))
Esempio n. 5
0
 def test_single_section_citation(self):
     """ Ensure that offsets work correctly in a simple single section
     citation case. """
     text = u"date in § 1005.20(h)(1) must disclose"
     citations = self.parser.process(Node(text, label=['1005', '6']))
     c = citations[0]
     self.assertEquals(text[c['offsets'][0][0]:c['offsets'][0][1]],
                       u'1005.20(h)(1)')
Esempio n. 6
0
 def test_comment_header(self):
     text = "See comment 32(b)(3) blah blah"
     result = self.parser.process(Node(text, label=['222', '87']))
     self.assertEqual(1, len(result))
     self.assertEqual(['222', '32', 'b', '3', Node.INTERP_MARK],
                      result[0]['citation'])
     offsets = result[0]['offsets'][0]
     self.assertEqual('32(b)(3)', text[offsets[0]:offsets[1]])
Esempio n. 7
0
 def hed(self, part, text):
     """HD with an HED source indicates the root of the appendix"""
     n = Node(node_type=Node.APPENDIX,
              label=[part, self.appendix_letter],
              title=text)
     self.m_stack.push_last((0, n))
     self.paragraph_counter = 0
     self.depth = 0
Esempio n. 8
0
 def test_process_cfr(self):
     m = Meta(None, cfr_title=3)
     result = m.process(Node(label=['a']))
     self.assertEqual(1, len(result))
     self.assertTrue('cfr_title_number' in result[0])
     self.assertEqual(3, result[0]['cfr_title_number'])
     self.assertTrue('cfr_title_text' in result[0])
     self.assertEqual('The President', result[0]['cfr_title_text'])
Esempio n. 9
0
 def graphic(self, xml_node):
     self.paragraph_counter += 1
     gid = xml_node.xpath('./GID')[0].text
     text = '![](' + gid + ')'
     n = Node(text,
              node_type=Node.APPENDIX,
              label=['p' + str(self.paragraph_counter)])
     self.nodes.append(n)
 def test_build_tree_exclude(self):
     """Paragraph tree should not split on exclude areas."""
     ref = "Ref (b)(2)"
     text = "This (a) is a good (1) %s test (2) no?" % ref
     ref_pos = text.find(ref)
     self.assertEqual(
         self.regParser.build_tree(text,
                                   exclude=[(ref_pos, ref_pos + len(ref))]),
         Node("This ",
              children=[
                  Node("(a) is a good ",
                       label=['a'],
                       children=[
                           Node("(1) %s test " % ref, label=['a', '1']),
                           Node("(2) no?", label=['a', '2'])
                       ])
              ]))
 def test_cfr(self):
     """Ensure that we successfully parse CFR references."""
     node = Node("Ref 1: 12 CFR part 1026. " + "Ref 2: 12 CFR 1026.13.")
     parser = external_citations.ExternalCitationParser(None)
     citations = parser.process(node)
     self.assertEqual(2, len(citations))
     self.assertEqual("CFR", citations[0]['citation_type'])
     self.assertEqual("CFR", citations[1]['citation_type'])
Esempio n. 12
0
def test_process_subparagraph_of_referenced_text():
    root = Node(
        label=['100'],
        children=[
            Node("\n\n\n",
                 node_type=Node.INTERP,
                 label=['100', '11', 'a', Node.INTERP_MARK],
                 children=[
                     Node("Interp11a1",
                          node_type=Node.INTERP,
                          label=['100', '11', 'a', '1', Node.INTERP_MARK])
                 ])
        ])
    interp = Interpretations(root)
    interp.pre_process()
    assert interp.process(Node(label=['100', '11', 'a'])) is None
    assert interp.process(Node(label=['100', '11', 'a', '1'])) is not None
    def test_build_hierarchy(self):
        """Nodes should be returned at the provided depths"""
        root = Node(label=['root'])
        nodes = [Node(label=['a']), Node(label=['1']), Node(label=['2']),
                 Node(label=['i']), Node(label=['b']), Node(label=['c'])]
        depths = [ParAssignment(mtypes.lower, 0, 0),
                  ParAssignment(mtypes.ints, 0, 1),
                  ParAssignment(mtypes.ints, 1, 1),
                  ParAssignment(mtypes.roman, 0, 2),
                  ParAssignment(mtypes.lower, 1, 0),
                  ParAssignment(mtypes.lower, 2, 0)]
        result = _ExampleProcessor().build_hierarchy(root, nodes, depths)
        self.assertEqual(result.label, ['root'])
        self.assertEqual(len(result.children), 3)

        a, b, c = result.children
        self.assertEqual(a.label, ['root', 'a'])
        self.assertEqual(len(a.children), 2)
        self.assertEqual(b.label, ['root', 'b'])
        self.assertEqual(len(b.children), 0)
        self.assertEqual(c.label, ['root', 'c'])
        self.assertEqual(len(c.children), 0)

        a1, a2 = a.children
        self.assertEqual(a1.label, ['root', 'a', '1'])
        self.assertEqual(len(a1.children), 0)
        self.assertEqual(a2.label, ['root', 'a', '2'])
        self.assertEqual(len(a2.children), 1)

        self.assertEqual(a2.children[0].label, ['root', 'a', '2', 'i'])
    def test_toc_with_subparts(self):
        c1 = Node(label=['205', '2'], title='Authority and Purpose')
        c2 = Node(label=['205', '3'], title='Definitions')
        c3 = Node(label=['205', '4'], title='Coverage')

        s1 = Node(children=[c1, c2, c3],
                  label=['205', 'Subpart', 'A'],
                  title='First Subpart',
                  node_type=Node.SUBPART)

        c4 = Node(label=['205', '5'], title='Fifth Title')
        s2 = Node(children=[c4],
                  label=['205', 'Subpart', 'B'],
                  title='Second Subpart',
                  node_type=Node.SUBPART)

        n = Node(children=[s1, s2], label=['205'])
        parser = table_of_contents.TableOfContentsLayer(None)
        toc = parser.process(n)
        self.assertEqual(len(toc), 2)
        self.assertEqual(toc[0]['index'], ['205', 'Subpart', 'A'])
        self.assertEqual(toc[1]['index'], ['205', 'Subpart', 'B'])

        toc = parser.process(s1)
        self.assertEqual(len(toc), 3)
        self.assertEqual(toc[0]['index'], ['205', '2'])
        self.assertEqual(toc[1]['index'], ['205', '3'])
        self.assertEqual(toc[2]['index'], ['205', '4'])

        toc = parser.process(s2)
        self.assertEqual(len(toc), 1)
        self.assertEqual(toc[0]['index'], ['205', '5'])
Esempio n. 15
0
 def test_process_extra(self):
     settings.META = {'some': 'setting', 'then': 42}
     m = Meta(None, cfr_title=19, version=None)
     result = m.process(Node(label=['a']))
     self.assertEqual(1, len(result))
     self.assertTrue('some' in result[0])
     self.assertEqual('setting', result[0]['some'])
     self.assertTrue('then' in result[0])
     self.assertEqual(42, result[0]['then'])
    def test_overwrite_marker(self):
        n = Node(
            '3. Interpretation paragraph text.',
            label=['205', '2', 'a', 'Interp', '3'],
            node_type=Node.INTERP)

        changed = compiler.overwrite_marker(n, '2')
        self.assertTrue('2.' in changed.text)
        self.assertFalse('3.' in changed.text)
    def test_keyterm_definition(self):
        node = Node("(a) Terminator means I'll be back",
                    label=['101', '22', 'a'])
        node.tagged_text = """(a) <E T="03">Terminator</E> means I'll be """
        node.tagged_text += 'back'
        kt = KeyTerms(None)
        results = kt.process(node)
        self.assertEqual(results, None)

        node = Node("(1) Act means pretend", label=['101', '22', 'a', '1'])
        node.tagged_text = """(1) <E T="03">Act</E> means pretend"""
        node = Node(
            "(1) Act means the Truth in Lending Act (15 U.S.C. 1601 et seq.).",
            label=['1026', '2', 'a', '1'])
        node.tagged_text = """(1) <E T="03">Act</E> means the Truth in Lending Act (15 U.S.C. 1601 <E T="03">et seq.</E>)."""
        kt = KeyTerms(None)
        results = kt.process(node)
        self.assertEqual(results, None)
    def test_reserve_add_new(self):
        root = self.tree_with_paragraphs()
        reg_tree = compiler.RegulationTree(root)

        n2ai = Node('[Reserved]', label=['205', '2', 'a', '1'])
        reg_tree.reserve('205-2-a-1', n2ai)
        self.assertNotEqual(reg_tree.tree, root)
        reserved_node = find(reg_tree.tree, '205-2-a-1')
        self.assertEqual(reserved_node.text, '[Reserved]')
    def test_get_section_parent(self):
        root = self.tree_with_subparts()
        section = Node('section', label=['205', '3'], node_type=Node.REGTEXT)
        subpart = find(root, '205-Subpart-B')
        subpart.children = [section]

        reg_tree = compiler.RegulationTree(root)
        parent = reg_tree.get_section_parent(section)
        self.assertEqual(parent.label_id(), '205-Subpart-B')
Esempio n. 20
0
 def test_sub_comment2(self):
     text = "See comment 3(b)(1)-1.v."
     result = self.parser.process(Node(text, label=['222', '87']))
     self.assertEqual(1, len(result))
     self.assertEqual(['222', '3', 'b', '1', Node.INTERP_MARK, '1', 'v'],
                      result[0]['citation'])
     offsets = result[0]['offsets'][0]
     #   Note the final period is not included
     self.assertEqual('3(b)(1)-1.v', text[offsets[0]:offsets[1]])
Esempio n. 21
0
 def test_single_paragraph(self):
     """ Ensure that offsets work correctly in a simple single paragraph
     citation. """
     text = 'The requirements in paragraph (a)(4)(iii) of'
     citations = self.parser.process(Node(text, label=['1005', '6']))
     c = citations[0]
     self.assertEquals(text[c['offsets'][0][0]:c['offsets'][0][1]],
                       u'(a)(4)(iii)')
     self.assertEquals(['1005', '6', 'a', '4', 'iii'], c['citation'])
def test_match_labels_and_changes_reserve():
    labels_amended = [Amendment('RESERVE', '200-?-2-a')]
    amend_map = changes.match_labels_and_changes(
        labels_amended, _section_node())
    assert set(amend_map.keys()) == {'200-2-a'}

    amendments = amend_map['200-2-a']
    assert amendments[0]['action'] == 'RESERVE'
    assert amendments[0]['node'] == Node('n2a', label=['200', '2', 'a'])
Esempio n. 23
0
 def test_process_subscript(self):
     node = Node("This is a_{subscript}. And then a_{subscript} again")
     result = formatting.Formatting(None).process(node)
     self.assertEqual(1, len(result))
     result = result[0]
     self.assertEqual(result['text'], "a_{subscript}")
     self.assertEqual(result['locations'], [0, 1])
     self.assertEqual(result['subscript_data'],
                      {'variable': 'a', 'subscript': 'subscript'})
Esempio n. 24
0
def generic_tree(text, label, title=None):
    """Use the "generic" parser to build a tree. The "generic" parser simply
    splits on Title Case and treats body text as the node content."""
    segments = generic.segments(text)
    if not segments:
        return Node(text, label=label, title=title, node_type=Node.APPENDIX)

    children = []
    for index, seg in enumerate(segments):
        start, end = seg
        seg_title, body = utils.title_body(text[start:end])
        label_character = letter_for(index)
        children.append(
            Node(body, label=(
                label + [label_character]),
                title=seg_title, node_type=Node.APPENDIX))

    return Node(text[:segments[0][0]], children, label, title, Node.APPENDIX)
 def test_determine_scope_this_part(self):
     """Definitions scoped to a part also cover the interpretations for
     that part"""
     self.add_nodes(1)
     self.stack.add(
         1,
         Node('For the purposes of this part, blah blah',
              label=['1001', '3']))
     self.assert_scope(('1001', ), ('1001', Node.INTERP_MARK))
    def test_process_format(self):
        node = Node("![A88 Something](ER22MY13.257-1)")
        g = Graphics(None)
        self.expect_http(uri='http://example.com/ER22MY13.257-1.gif',
                         method='HEAD')
        self.expect_http(uri='http://example.com/ER22MY13.257-1.thumb.gif',
                         method='HEAD')

        self.assertEqual(1, len(g.process(node)))
Esempio n. 27
0
    def test_determine_scope_this_paragraph(self):
        """Paragraph scope is tied to the paragraph that determined it.
        Previous paragraph scopes won't apply to adjacent children"""
        self.add_nodes(2)
        self.stack.add(2, Node('For the purposes of this section, blah blah',
                               label=['1000', '3', 'd']))
        self.stack.add(3, Node('For the purposes of this paragraph, blah blah',
                               label=['1000', '3', 'd', '5']))
        self.assert_scope(('1000', '3', 'd', '5'),
                          ('1000', '3', 'd', '5', Node.INTERP_MARK))

        self.stack.add(3, Node(label=['1002', '3', 'd', '6']))
        self.assert_scope(('1000', '3'), ('1000', '3', Node.INTERP_MARK))

        self.stack.add(3, Node('Blah as used in this paragraph, blah blah',
                               label=['1000', '3', 'd', '7']))
        self.assert_scope(('1000', '3', 'd', '7'),
                          ('1000', '3', 'd', '7', Node.INTERP_MARK))
def build_supplement_tree(reg_part, node):
    """ Build the tree for the supplement section. """
    title = get_app_title(node)
    node = spaces_then_remove(deepcopy(node), 'PRTPAGE')
    root = Node(node_type=Node.INTERP,
                label=[reg_part, Node.INTERP_MARK],
                title=title)

    return parse_from_xml(root, node.getchildren())
    def derive_nodes(self, xml, processor=None):
        texts = ["```" + xml.get('LANGUAGE', 'code')]
        for child in xml:
            text = tree_utils.get_node_text(child).strip()
            if text:
                texts.append(text)
        texts.append("```")

        return [Node("\n".join(texts), label=[mtypes.MARKERLESS])]
Esempio n. 30
0
    def test_pre_process_defined_twice(self):
        tree = Node(u"The term “lol” means laugh out loud. " +
                    u"How do you pronounce “lol”, though?",
                    label=['1212', '5'])
        t = Terms(tree)
        t.pre_process()

        self.assertEqual(t.layer['referenced']['lol:1212-5']['position'],
                         (10, 13))