regulations.generator.layers package¶
Submodules¶
regulations.generator.layers.base module¶
-
class
regulations.generator.layers.base.
InlineLayer
[source]¶ Bases:
regulations.generator.layers.base.LayerBase
Represents a layer which replaces text by looking at offsets
-
apply_layer
(text, label_id)[source]¶ Entry point when processing the regulation tree. Given the node’s text and its label_id, yield all replacement text
-
-
class
regulations.generator.layers.base.
LayerBase
[source]¶ Bases:
object
Base class for most layers; each layer contains information which is added on top of the regulation, such as definitions, internal citations, keyterms, etc.
-
data_source
¶ Data is pulled from the API; this field indicates the name of the endpoint to pull data from
-
inline_replacements
(text_index, original_text)[source]¶ Return triplets of (original text, replacement text, offsets)
-
shorthand
¶ A short description for this layer. This is used in query strings and the like to define which layers should be used
-
-
class
regulations.generator.layers.base.
ParagraphLayer
[source]¶ Bases:
regulations.generator.layers.base.LayerBase
Represents a layer which applies meta data to nodes
-
class
regulations.generator.layers.base.
Replacement
(original, replacement, locations)¶ Bases:
tuple
-
locations
¶ Alias for field number 2
-
original
¶ Alias for field number 0
-
replacement
¶ Alias for field number 1
-
-
class
regulations.generator.layers.base.
SearchReplaceLayer
[source]¶ Bases:
regulations.generator.layers.base.LayerBase
Represents a layer which replaces text by searching for and replacing a specific substring. Also accounts for the string appearing multiple times (via the ‘locations’ field)
regulations.generator.layers.defined module¶
regulations.generator.layers.definitions module¶
regulations.generator.layers.diff_applier module¶
-
class
regulations.generator.layers.diff_applier.
DiffApplier
(diff_json, label_requested)[source]¶ Bases:
object
Diffs between two versions of a regulation are represented in our particular JSON format. This class applies that diff to the older version of the regulation, generating HTML that clearly shows the changes between old and new.
-
ADDED_OP
= 'added'¶
-
DELETE
= u'delete'¶
-
DELETED_OP
= 'deleted'¶
-
EQUAL
= u'equal'¶
-
INSERT
= u'insert'¶
-
MODIFIED_OP
= 'modified'¶
-
apply_diff
(original, label, component='text')[source]¶ Here we delete or add whole nodes in addition to passing to apply_diff_changes when text has been modified
-
classmethod
has_moved
(label_op, seen_count)[source]¶ A label is moved if it’s been deleted in one position but added int another
-
relevant_added
(label)[source]¶ Get the operations that add nodes, for the requested section/pargraph.
-
remove_moved_labels
(label_ops)[source]¶ If a label has been moved, we will display it in the new position
-
regulations.generator.layers.external_citation module¶
regulations.generator.layers.footnotes module¶
-
class
regulations.generator.layers.footnotes.
FootnotesLayer
(layer, version=None)[source]¶ Bases:
regulations.generator.layers.base.ParagraphLayer
Assembles the footnotes for this node, if available
-
attach_metadata
(node)[source]¶ Return a tuple of ‘footnotes’ and collection of footnotes. Footnotes are “collected” from the node and its children. .. note:
This does not handle the case where the same note reference is used in multiple children.
-
data_source
= 'formatting'¶
-
shorthand
= 'footnotes'¶
-
regulations.generator.layers.formatting module¶
regulations.generator.layers.graphics module¶
regulations.generator.layers.internal_citation module¶
regulations.generator.layers.interpretations module¶
regulations.generator.layers.key_terms module¶
regulations.generator.layers.layers_applier module¶
-
class
regulations.generator.layers.layers_applier.
LayersApplier
[source]¶ Bases:
object
Most layers replace content. We try to do this intelligently here, so that layers don’t step over each other.
-
HTML_TAG_REGEX
= <_sre.SRE_Pattern object>¶
-
regulations.generator.layers.location_replace module¶
-
class
regulations.generator.layers.location_replace.
LocationReplace
[source]¶ Bases:
object
Applies location based layers to XML nodes. We use XML so that we only take into account the original text when we’re doing a replacement.
-
static
find_all_offsets
(pattern, text, offset=0)[source]¶ Don’t use regular expressions as they are a tad slow
-
location_replace
(xml_node, original, replacement, locations)[source]¶ For the xml_node, replace the locations instances of orginal with replacement. @todo: This doesn’t appear to be used anymore?
-
location_replace_text
(text, original, replacement, locations)[source]¶ Given plain text, do replacements
-
static
regulations.generator.layers.meta module¶
regulations.generator.layers.paragraph_markers module¶
regulations.generator.layers.toc_applier module¶
regulations.generator.layers.tree_builder module¶
-
class
regulations.generator.layers.tree_builder.
AddQueue
[source]¶ Bases:
object
Maintain a sorted list of nodes to add. This maintains a sorted queue of (label, node) tuples.
-
regulations.generator.layers.tree_builder.
add_child
(parent_node, node)[source]¶ Add a child node to a parent, maintaining the order of the children.
-
regulations.generator.layers.tree_builder.
add_node_to_tree
(node, parent_label, tree_hash)[source]¶ Add the node to the tree by adding it to it’s parent in order.
-
regulations.generator.layers.tree_builder.
all_children_are_roman
(parent_node)[source]¶ Return true if all the children of the parent node have roman labels
-
regulations.generator.layers.tree_builder.
build_tree_hash
(tree)[source]¶ Build a hash map of a tree’s nodes, so that we don’t have to keep walking the tree.
-
regulations.generator.layers.tree_builder.
make_label_sortable
(label, roman=False)[source]¶ Make labels sortable, but converting them as appropriate. Also, appendices have labels that look like 30(a), we make those appropriately sortable.
-
regulations.generator.layers.tree_builder.
parent_in_tree
(parent_label, tree_hash)[source]¶ Return True if the parent of node_label is in the tree
regulations.generator.layers.utils module¶
-
regulations.generator.layers.utils.
convert_to_python
(data)[source]¶ Convert raw data (e.g. from json conversion) into the appropriate Python objects