• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python reg_text.build_from_section函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中regparser.tree.xml_parser.reg_text.build_from_section函数的典型用法代码示例。如果您正苦于以下问题:Python build_from_section函数的具体用法?Python build_from_section怎么用?Python build_from_section使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了build_from_section函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_build_from_section_unnumbered_defs

    def test_build_from_section_unnumbered_defs(self):
        xml = u"""
            <SECTION>
                <SECTNO>§ 8675.309</SECTNO>
                <SUBJECT>Definitions.</SUBJECT>
                <P depth="1">(a) This is what things mean:</P>
                <P depth="1">foo means bar</P>
                <P depth="1">bop means baz</P>
            </SECTION>
        """
        node = reg_text.build_from_section('8675', etree.fromstring(xml))[0]
        self.assertEqual('', node.text.strip())
        self.assertEqual(3, len(node.children))
        self.assertEqual(['8675', '309'], node.label)

        child = node.children[0]
        self.assertEqual('(a) This is what things mean:', child.text.strip())
        self.assertEqual(0, len(child.children))
        self.assertEqual(['8675', '309', 'a'], child.label)

        child = node.children[1]
        self.assertEqual('foo means bar', child.text.strip())
        self.assertEqual(0, len(child.children))
        self.assertEqual(['8675', '309', 'Foo'], child.label)

        child = node.children[2]
        self.assertEqual('bop means baz', child.text.strip())
        self.assertEqual(0, len(child.children))
        self.assertEqual(['8675', '309', 'Bop'], child.label)
开发者ID:cfpb,项目名称:regulations-parser,代码行数:29,代码来源:tree_xml_parser_reg_text_tests.py


示例2: test_build_from_4_section_reserved_range

 def test_build_from_4_section_reserved_range(self):
     with XMLBuilder("SECTION") as ctx:
         ctx.SECTNO(u"§§ 8675.309-8675.312")
         ctx.RESERVED("[Reserved]")
     n309 = reg_text.build_from_section('8675', ctx.xml)[0]
     self.assertEqual(n309.label, ['8675', '309'])
     self.assertEqual(u'§§ 8675.309-312 [Reserved]', n309.title)
开发者ID:tadhg-ohiggins,项目名称:regulations-parser,代码行数:7,代码来源:tree_xml_parser_reg_text_tests.py


示例3: test_build_from_section_reserved

 def test_build_from_section_reserved(self):
     with self.tree.builder("SECTION") as root:
         root.SECTNO(u"§ 8675.309")
         root.RESERVED("[Reserved]")
     node = reg_text.build_from_section('8675', self.tree.render_xml())[0]
     self.assertEqual(node.label, ['8675', '309'])
     self.assertEqual(u'§ 8675.309 [Reserved]', node.title)
     self.assertEqual([], node.children)
开发者ID:vrajmohan,项目名称:regulations-parser,代码行数:8,代码来源:tree_xml_parser_reg_text_tests.py


示例4: test_build_from_section_reserved

 def test_build_from_section_reserved(self):
     with XMLBuilder("SECTION") as ctx:
         ctx.SECTNO(u"§ 8675.309")
         ctx.RESERVED("[Reserved]")
     node = reg_text.build_from_section('8675', ctx.xml)[0]
     self.assertEqual(node.label, ['8675', '309'])
     self.assertEqual(u'§ 8675.309 [Reserved]', node.title)
     self.assertEqual([], node.children)
开发者ID:anthonygarvan,项目名称:regulations-parser,代码行数:8,代码来源:tree_xml_parser_reg_text_tests.py


示例5: process_amendments

def process_amendments(notice, notice_xml):
    """ Process the changes to the regulation that are expressed in the notice.
    """
    amends = []
    notice_changes = changes.NoticeChanges()

    amdpars_by_parent = []
    for par in notice_xml.xpath('//AMDPAR'):
        parent = par.getparent()
        exists = filter(lambda aXp: aXp.parent == parent, amdpars_by_parent)
        if exists:
            exists[0].append(par)
        else:
            amdpars_by_parent.append(AmdparByParent(parent, par))

    for aXp in amdpars_by_parent:
        amended_labels = []
        designate_labels, other_labels = [], []
        context = [aXp.parent.get('PART') or notice['cfr_part']]
        for par in aXp.amdpars:
            als, context = parse_amdpar(par, context)
            amended_labels.extend(als)

        for al in amended_labels:
            if isinstance(al, DesignateAmendment):
                subpart_changes = process_designate_subpart(al)
                if subpart_changes:
                    notice_changes.update(subpart_changes)
                designate_labels.append(al)
            elif new_subpart_added(al, notice['cfr_part']):
                notice_changes.update(process_new_subpart(notice, al, par))
                designate_labels.append(al)
            else:
                other_labels.append(al)

        create_xmlless_changes(other_labels, notice_changes)

        section_xml = find_section(par)
        if section_xml is not None:
            for section in reg_text.build_from_section(
                    notice['cfr_part'], section_xml):
                create_xml_changes(other_labels, section, notice_changes)

        for appendix in parse_appendix_changes(other_labels,
                                               notice['cfr_part'], aXp.parent):
            create_xml_changes(other_labels, appendix, notice_changes)

        interp = parse_interp_changes(other_labels, notice['cfr_part'],
                                      aXp.parent)
        if interp:
            create_xml_changes(other_labels, interp, notice_changes)

        amends.extend(designate_labels)
        amends.extend(other_labels)
    if amends:
        notice['amendments'] = amends
        notice['changes'] = notice_changes.changes
开发者ID:jposi,项目名称:regulations-parser,代码行数:57,代码来源:build.py


示例6: test_build_from_section_double_collapsed

 def test_build_from_section_double_collapsed(self):
     with self.section() as root:
         root.P(_xml=u"""(a) <E T="03">Keyterm</E>—(1)(i) Content""")
         root.P("(ii) Content2")
     node = reg_text.build_from_section('8675', self.tree.render_xml())[0]
     node = self.node_accessor(node, ['8675', '309'])
     self.assertEqual(['a'], node.child_labels)
     self.assertEqual(['1'], node['a'].child_labels)
     self.assertEqual(['i', 'ii'], node['a']['1'].child_labels)
开发者ID:vrajmohan,项目名称:regulations-parser,代码行数:9,代码来源:tree_xml_parser_reg_text_tests.py


示例7: test_build_from_section_bad_spaces

 def test_build_from_section_bad_spaces(self):
     with self.section(section=16) as root:
         root.STARS()
         root.P(_xml="""(b)<E T="03">General.</E>Content Content.""")
     node = reg_text.build_from_section('8675', self.tree.render_xml())[0]
     node = self.node_accessor(node, ['8675', '16'])
     self.assertEqual(['b'], node.child_labels)
     self.assertEqual(node['b'].text.strip(),
                      "(b) General. Content Content.")
开发者ID:vrajmohan,项目名称:regulations-parser,代码行数:9,代码来源:tree_xml_parser_reg_text_tests.py


示例8: process_amendments

def process_amendments(notice, notice_xml):
    """Process changes to the regulation that are expressed in the notice."""
    all_amends = []     # will be added to the notice
    cfr_part = notice['cfr_parts'][0]
    notice_changes = changes.NoticeChanges()

    # process amendments in batches, based on their parent XML
    for amdparent in notice_xml.xpath('//AMDPAR/..'):
        context = [amdparent.get('PART') or cfr_part]
        amendments_by_section = defaultdict(list)
        normal_amends = []  # amendments not moving or adding a subpart
        for amdpar in amdparent.xpath('.//AMDPAR'):
            instructions = amdpar.xpath('./EREGS_INSTRUCTIONS')
            if not instructions:
                logger.warning('No <EREGS_INSTRUCTIONS>. Was this notice '
                               'preprocessed?')
                continue
            instructions = instructions[0]
            amendments = [amendment_from_xml(el) for el in instructions]
            context = [None if l is '?' else l
                       for l in instructions.get('final_context').split('-')]
            section_xml = find_section(amdpar)
            for amendment in amendments:
                all_amends.append(amendment)
                if isinstance(amendment, DesignateAmendment):
                    subpart_changes = process_designate_subpart(amendment)
                    if subpart_changes:
                        notice_changes.update(subpart_changes)
                elif new_subpart_added(amendment):
                    notice_changes.update(process_new_subpart(
                        notice, amendment, amdpar))
                elif section_xml is None:
                    normal_amends.append(amendment)
                else:
                    normal_amends.append(amendment)
                    amendments_by_section[section_xml].append(amendment)

        cfr_part = context[0]   # carry the part through to the next amdparent
        create_xmlless_changes(normal_amends, notice_changes)
        # Process amendments relating to a specific section in batches, too
        for section_xml, related_amends in amendments_by_section.items():
            for section in reg_text.build_from_section(cfr_part, section_xml):
                create_xml_changes(related_amends, section, notice_changes)

        for appendix in parse_appendix_changes(normal_amends, cfr_part,
                                               amdparent):
            create_xml_changes(normal_amends, appendix, notice_changes)

        interp = parse_interp_changes(normal_amends, cfr_part, amdparent)
        if interp:
            create_xml_changes(normal_amends, interp, notice_changes)

    if all_amends:
        notice['amendments'] = all_amends
        notice['changes'] = notice_changes.changes

    return notice
开发者ID:cmc333333,项目名称:regulations-parser,代码行数:57,代码来源:build.py


示例9: _setup_for_ambiguous

 def _setup_for_ambiguous(self, final_par):
     with self.section() as ctx:
         ctx.P("(g) Some Content")
         ctx.P("(h) H Starts")
         ctx.P("(1) H-1")
         ctx.P("(2) H-2")
         ctx.P("(i) Is this 8675-309-h-2-i or 8675-309-i")
         ctx.P(final_par)
     node = reg_text.build_from_section('8675', ctx.xml)[0]
     return NodeAccessor(node)
开发者ID:anthonygarvan,项目名称:regulations-parser,代码行数:10,代码来源:tree_xml_parser_reg_text_tests.py


示例10: _setup_for_ambiguous

 def _setup_for_ambiguous(self, final_par):
     with self.section() as root:
         root.P("(g) Some Content")
         root.P("(h) H Starts")
         root.P("(1) H-1")
         root.P("(2) H-2")
         root.P("(i) Is this 8675-309-h-2-i or 8675-309-i")
         root.P(final_par)
     node = reg_text.build_from_section('8675', self.tree.render_xml())[0]
     return self.node_accessor(node, ['8675', '309'])
开发者ID:vrajmohan,项目名称:regulations-parser,代码行数:10,代码来源:tree_xml_parser_reg_text_tests.py


示例11: test_build_from_section_reserved

 def test_build_from_section_reserved(self):
     xml = u"""
         <SECTION>
             <SECTNO>§ 8675.309</SECTNO>
             <RESERVED>[Reserved]</RESERVED>
         </SECTION>"""
     node = reg_text.build_from_section('8675', etree.fromstring(xml))[0]
     self.assertEqual(node.label, ['8675', '309'])
     self.assertEqual(u'§ 8675.309 [Reserved]', node.title)
     self.assertEqual([], node.children)
开发者ID:cfpb,项目名称:regulations-parser,代码行数:10,代码来源:tree_xml_parser_reg_text_tests.py


示例12: test_build_from_section_double_alpha

 def test_build_from_section_double_alpha(self):
     # Ensure we match a hierarchy like (x), (y), (z), (aa), (bb)…
     with XMLBuilder("SECTION") as ctx:
         ctx.SECTNO(u"§ 8675.309")
         ctx.SUBJECT("Definitions.")
         ctx.P("(aa) This is what things mean:")
     node = reg_text.build_from_section('8675', ctx.xml)[0]
     child = node.children[0]
     self.assertEqual('(aa) This is what things mean:', child.text.strip())
     self.assertEqual(['8675', '309', 'aa'], child.label)
开发者ID:anthonygarvan,项目名称:regulations-parser,代码行数:10,代码来源:tree_xml_parser_reg_text_tests.py


示例13: test_build_from_section_double_collapsed

 def test_build_from_section_double_collapsed(self):
     with self.section() as ctx:
         ctx.child_from_string(
             u'<P>(a) <E T="03">Keyterm</E>—(1)(i) Content</P>')
         ctx.P("(ii) Content2")
     node = reg_text.build_from_section('8675', ctx.xml)[0]
     node = NodeAccessor(node)
     self.assertEqual(['a'], node.child_labels)
     self.assertEqual(['1'], node['a'].child_labels)
     self.assertEqual(['i', 'ii'], node['a']['1'].child_labels)
开发者ID:anthonygarvan,项目名称:regulations-parser,代码行数:10,代码来源:tree_xml_parser_reg_text_tests.py


示例14: test_build_from_section_ambiguous

    def test_build_from_section_ambiguous(self):
        xml = u"""
            <SECTION>
                <SECTNO>§ 8675.309</SECTNO>
                <SUBJECT>Definitions.</SUBJECT>
                <P>(g) Some Content</P>
                <P>(h) H Starts</P>
                <P>(1) H-1</P>
                <P>(2) H-2</P>
                <P>(i) Is this 8675-309-h-2-i or 8675-309-i</P>
                <P>%s</P>
            </SECTION>
        """
        n8675_309 = reg_text.build_from_section(
            '8675', etree.fromstring(xml % '(ii) A'))[0]
        n8675_309_h = n8675_309.children[1]
        n8675_309_h_2 = n8675_309_h.children[1]
        self.assertEqual(2, len(n8675_309.children))
        self.assertEqual(2, len(n8675_309_h.children))
        self.assertEqual(2, len(n8675_309_h_2.children))

        n8675_309 = reg_text.build_from_section(
            '8675', etree.fromstring(xml % '(A) B'))[0]
        n8675_309_h = n8675_309.children[1]
        n8675_309_h_2 = n8675_309_h.children[1]
        n8675_309_h_2_i = n8675_309_h_2.children[0]
        self.assertEqual(2, len(n8675_309.children))
        self.assertEqual(2, len(n8675_309_h.children))
        self.assertEqual(1, len(n8675_309_h_2.children))
        self.assertEqual(1, len(n8675_309_h_2_i.children))

        n8675_309 = reg_text.build_from_section(
            '8675', etree.fromstring(xml % '(1) C'))[0]
        self.assertEqual(3, len(n8675_309.children))

        n8675_309 = reg_text.build_from_section(
            '8675', etree.fromstring(xml % '(3) D'))[0]
        n8675_309_h = n8675_309.children[1]
        n8675_309_h_2 = n8675_309_h.children[1]
        self.assertEqual(2, len(n8675_309.children))
        self.assertEqual(3, len(n8675_309_h.children))
        self.assertEqual(1, len(n8675_309_h_2.children))
开发者ID:cfpb,项目名称:regulations-parser,代码行数:42,代码来源:tree_xml_parser_reg_text_tests.py


示例15: test_build_from_section_intro_text

    def test_build_from_section_intro_text(self):
        with self.section() as root:
            root.P("Some content about this section.")
            root.P("(a) something something")
        node = reg_text.build_from_section('8675', self.tree.render_xml())[0]
        node = self.node_accessor(node, ['8675', '309'])
        self.assertEqual('Some content about this section.', node.text.strip())
        self.assertEqual(['a'], node.child_labels)

        self.assertEqual('(a) something something', node['a'].text.strip())
        self.assertEqual([], node['a'].children)
开发者ID:vrajmohan,项目名称:regulations-parser,代码行数:11,代码来源:tree_xml_parser_reg_text_tests.py


示例16: test_build_from_section_reserved_range

 def test_build_from_section_reserved_range(self):
     with XMLBuilder("SECTION") as ctx:
         ctx.SECTNO(u"§§ 8675.309-8675.311")
         ctx.RESERVED("[Reserved]")
     n309, n310, n311 = reg_text.build_from_section('8675', ctx.xml)
     self.assertEqual(n309.label, ['8675', '309'])
     self.assertEqual(n310.label, ['8675', '310'])
     self.assertEqual(n311.label, ['8675', '311'])
     self.assertEqual(u'§ 8675.309 [Reserved]', n309.title)
     self.assertEqual(u'§ 8675.310 [Reserved]', n310.title)
     self.assertEqual(u'§ 8675.311 [Reserved]', n311.title)
开发者ID:anthonygarvan,项目名称:regulations-parser,代码行数:11,代码来源:tree_xml_parser_reg_text_tests.py


示例17: test_build_from_section_bad_spaces

 def test_build_from_section_bad_spaces(self):
     with self.section(section=16) as ctx:
         ctx.STARS()
         ctx.child_from_string(
             '<P>(b)<E T="03">General.</E>Content Content.</P>')
     node = reg_text.build_from_section('8675', ctx.xml)[0]
     node = NodeAccessor(node)
     self.assertEqual(['8675', '16'], node.label)
     self.assertEqual(['b'], node.child_labels)
     self.assertEqual(node['b'].text.strip(),
                      "(b) General. Content Content.")
开发者ID:anthonygarvan,项目名称:regulations-parser,代码行数:11,代码来源:tree_xml_parser_reg_text_tests.py


示例18: test_build_from_section_intro_text

    def test_build_from_section_intro_text(self):
        with self.section() as ctx:
            ctx.P("Some content about this section.")
            ctx.P("(a) something something")
        node = reg_text.build_from_section('8675', ctx.xml)[0]
        node = NodeAccessor(node)
        self.assertEqual('Some content about this section.', node.text.strip())
        self.assertEqual(['a'], node.child_labels)

        self.assertEqual('(a) something something', node['a'].text.strip())
        self.assertEqual([], node['a'].children)
开发者ID:anthonygarvan,项目名称:regulations-parser,代码行数:11,代码来源:tree_xml_parser_reg_text_tests.py


示例19: test_build_from_section_collapsed

 def test_build_from_section_collapsed(self):
     with self.section() as root:
         root.P("(a) aaa")
         root.P("(1) 111")
         root.P(_xml=u"""(2) 222—(i) iii. (A) AAA""")
         root.P("(B) BBB")
     n309 = reg_text.build_from_section('8675', self.tree.render_xml())[0]
     n309 = self.node_accessor(n309, ['8675', '309'])
     self.assertEqual(['a'], n309.child_labels)
     self.assertEqual(['1', '2'], n309['a'].child_labels)
     self.assertEqual(['i'], n309['a']['2'].child_labels)
     self.assertEqual(['A', 'B'], n309['a']['2']['i'].child_labels)
开发者ID:vrajmohan,项目名称:regulations-parser,代码行数:12,代码来源:tree_xml_parser_reg_text_tests.py


示例20: test_build_from_section_collapsed_level

 def test_build_from_section_collapsed_level(self):
     with self.section() as root:
         root.P(_xml=u"""(a) <E T="03">Transfers </E>—(1)
                        <E T="03">Notice.</E> follow""")
         root.P("(2) More text")
         root.P(_xml="""(b) <E T="03">Contents</E> (1) Here""")
         root.P("(2) More text")
     node = reg_text.build_from_section('8675', self.tree.render_xml())[0]
     node = self.node_accessor(node, ['8675', '309'])
     self.assertEqual(['a', 'b'], node.child_labels)
     self.assertEqual(['1', '2'], node['a'].child_labels)
     self.assertEqual(['1', '2'], node['b'].child_labels)
开发者ID:vrajmohan,项目名称:regulations-parser,代码行数:12,代码来源:tree_xml_parser_reg_text_tests.py



注:本文中的regparser.tree.xml_parser.reg_text.build_from_section函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tree_utils.get_node_text函数代码示例发布时间:2022-05-26
下一篇:
Python struct.Node类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap