forked from eregs/regulations-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request eregs#341 from cmc333333/seperate-interp-1
Separate interpretations, phase 1
- Loading branch information
Showing
11 changed files
with
211 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from setuptools import setup, find_packages | ||
|
||
|
||
setup( | ||
name='interpparser', | ||
version="0.0.1", | ||
packages=find_packages(), | ||
classifiers=[ | ||
'License :: Public Domain', | ||
'License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication' | ||
], | ||
entry_points={ | ||
'eregs_ns.parser.layer.cfr': | ||
'interpretations = interpparser.layers:Interpretations' | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,4 @@ setuptools==21.1.0 | |
six==1.10.0 | ||
stevedore==1.13.0 | ||
-e . | ||
-e interpparser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
from regparser.tree.struct import Node | ||
from interpparser.layers import Interpretations | ||
|
||
|
||
def test_process(): | ||
root = Node(children=[ | ||
Node("Interp11a", | ||
[Node("child1"), Node("child2")], | ||
['102', '11', 'a', Node.INTERP_MARK], | ||
node_type=Node.INTERP), | ||
Node("Interp11c5v", | ||
label=['102', '11', 'c', '5', 'v', Node.INTERP_MARK], | ||
node_type=Node.INTERP), | ||
Node("InterpB5ii", | ||
label=['102', 'B', '5', 'ii', Node.INTERP_MARK], | ||
node_type=Node.INTERP), | ||
Node(children=[ | ||
Node(label=['102'], children=[ | ||
Node("Interp9c1", | ||
label=['102', '9', 'c', '1', Node.INTERP_MARK], | ||
node_type=Node.INTERP) | ||
]) | ||
]) | ||
]) | ||
|
||
interp = Interpretations(root) | ||
interp.pre_process() | ||
interp11a = interp.process(Node(label=['102', '11', 'a'])) | ||
interp11c5v = interp.process(Node( | ||
label=['102', '11', 'c', '5', 'v'] | ||
)) | ||
interpB5ii = interp.process(Node(label=['102', 'B', '5', 'ii'])) | ||
interp9c1 = interp.process(Node(label=['102', '9', 'c', '1'])) | ||
|
||
assert len(interp11a) == 1 | ||
assert len(interp11c5v) == 1 | ||
assert len(interpB5ii) == 1 | ||
assert len(interp9c1) == 1 | ||
assert interp11a[0]['reference'] == '102-11-a-Interp' | ||
assert interp11c5v[0]['reference'] == '102-11-c-5-v-Interp' | ||
assert interpB5ii[0]['reference'] == '102-B-5-ii-Interp' | ||
assert interp9c1[0]['reference'] == '102-9-c-1-Interp' | ||
assert interp.process(Node(label=['102', '10', 'a'])) is None | ||
|
||
|
||
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_process_has_multiple_paragraphs(): | ||
root = Node(label=['100'], children=[ | ||
Node("\n\n\n", | ||
node_type=Node.INTERP, | ||
label=['100', '11', 'a', Node.INTERP_MARK], | ||
children=[Node("Interp11a-1", node_type=Node.INTERP, | ||
label=['100', '11', 'a', Node.INTERP_MARK, '1'])]) | ||
]) | ||
interp = Interpretations(root) | ||
interp.pre_process() | ||
assert interp.process(Node(label=['100', '11', 'a'])) is not None | ||
|
||
|
||
def test_process_applies_to_multiple(): | ||
i1a = Node('Text', title='Paragraph 1(a) and 1(b)', node_type=Node.INTERP, | ||
label=['100', '1', 'a', Node.INTERP_MARK]) | ||
i1 = Node(label=['100', '1', Node.INTERP_MARK], node_type=Node.INTERP, | ||
children=[i1a]) | ||
root = Node(label=['100', Node.INTERP_MARK], node_type=Node.INTERP, | ||
children=[i1]) | ||
interp = Interpretations(root) | ||
interp.pre_process() | ||
assert interp.process(Node(label=['100', '1', 'a'])) is not None | ||
assert interp.process(Node(label=['100', '1', 'b'])) is not None | ||
|
||
|
||
def test_process_regressions(): | ||
i1a = Node('Text', title='Paragraph 1(a) and 1(b)', | ||
label=['100', '1', 'a', Node.INTERP_MARK]) | ||
interp = Interpretations(i1a) | ||
interp.pre_process() | ||
assert interp.process(Node(label=['100', '1', 'a'])) is None | ||
|
||
i1a1 = Node('Text', title='Paragraph 1(a) and 1(b)', | ||
label=['100', '1', 'a', Node.INTERP_MARK, '1'], | ||
node_type=Node.INTERP) | ||
interp = Interpretations(i1a1) | ||
interp.pre_process() | ||
assert interp.process(Node(label=['100', '1', 'a'])) is None | ||
|
||
|
||
def test_empty_interpretations(): | ||
interp = Interpretations(None) | ||
assert interp.empty_interpretation(Node('\n\n')) | ||
assert interp.empty_interpretation(Node('', [Node('Subpar')])) | ||
assert not interp.empty_interpretation(Node('Content')) | ||
assert not interp.empty_interpretation( | ||
Node('', [Node('Something', label=['1', Node.INTERP_MARK, '3'])])) | ||
|
||
|
||
def test_pre_process_multiple_interps(): | ||
interpG = Node('GGGG', title='Appendix G', | ||
label=['1111', 'G', 'Interp'], node_type=Node.INTERP) | ||
interpH = Node('HHHH', title='Appendix H', | ||
label=['1111', 'H', 'Interp'], node_type=Node.INTERP) | ||
interpGH = Node('GHGHGH', title='Appendices G and H', | ||
label=['1111', 'G_H', 'Interp'], | ||
node_type=Node.INTERP) | ||
|
||
tree = Node(label=['1111'], children=[ | ||
Node(label=['1111', 'Interp'], node_type=Node.INTERP, children=[ | ||
interpGH, interpG, interpH])]) | ||
|
||
interp = Interpretations(tree) | ||
interp.pre_process() | ||
|
||
node = Node('App G', label=['1111', 'G'], node_type=Node.APPENDIX) | ||
assert interp.process(node) == [{'reference': '1111-G_H-Interp'}, | ||
{'reference': '1111-G-Interp'}] |
Oops, something went wrong.