Rule Model
Bases: BaseModel
A Rule
is detected if it matches either:
Each rule implies:
- Previous validation via regex strings
- Path to an intended local directory
- Extractable content
- Serial title generated by
StatuteSerialCategory.serialize()
- Countability via a
collection.Counter
built-in
Source code in statute_patterns/components/rule.py
Python | |
---|---|
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
Functions
__hash__()
Pydantic models are not hashable by default.
It is implemented here to take advantage of collections.Counter
which works only on objects with a hash. This is the
basis of count_rules()
.
Source code in statute_patterns/components/rule.py
extract_folders(base_path=STATUTE_PATH)
Using the category
and id
of the object,
get the possible folder paths.
Source code in statute_patterns/components/rule.py
Python | |
---|---|
from_path(details_path)
classmethod
Construct rule from a properly structured statute's details.yaml
file.
Source code in statute_patterns/components/rule.py
Python | |
---|---|
get_details(details_path)
classmethod
Assumes a properly structured path with three path
parents from details.yaml, e.g. path to /statutes/ra/386/details.yaml
means 3 parents from the same would be /statutes. Will
create the rule based on the details path and pull data from other
related paths to generate the details of the rule.
Source code in statute_patterns/components/rule.py
get_path(base_path=STATUTE_PATH)
For most cases, there only be one path to path/to/statutes/ra/386 where:
- path/to/statutes = base_path
- 'ra' is the category
- '386' is the id.
Source code in statute_patterns/components/rule.py
get_paths(base_path=STATUTE_PATH)
Ordinarily, the following directory structure would suffice in generating the path to a unique statute:
This is not true in complex statutes.
To simplify, imagine Statute A, B and C have the same category and identifier. But refer to different documents:
/statutes
/statute-category
/statute-serial-id # dated Jan. 1, 2000
details.yaml # we'd need a different `statute-serial-id`
/statute-serial-id # dated Jan. 10, 2000
details.yaml # we'd need a different `statute-serial-id`
Because of this dilemma, we introduce a digit in the creation of statute folders referring to more than one variant of the intended document.
So in the case of /statutes/rule_am/
, let's consider 00-5-03-sc
.
This should be a valid statute under self.get_path()
.
However, since there exists 2 variants, we need to rename the original folder to contemplate 2 distinct documents:
Unlike get_path()
which only retrieves one Path, all Paths will be retrieved
using the plural form of the function self.get_paths()
Source code in statute_patterns/components/rule.py
units_path(statute_folder)
There are two kinds of unit files:
- the preferred / customized variant with the filename convention
statute-category
+statute-serial-id
+.yaml
, e.g.ra386.yaml
- the one scraped which is the default in the absence of a preferred
variant, e.g.
units.yaml