Extract
This presumes existence of a local path to a separate library where the contents of the rule can be extracted from.
Extract Rules
If text contains serialized (e.g. Republic Act No. 386)
and named rules (the Civil Code of the Philippines),
extract the Rules
into their canonical serial variants.
Examples:
>>> from statute_patterns import extract_rules
>>> text = "The Civil Code of the Philippines, the old Spanish Civil Code; Rep Act No. 386"
>>> list(extract_rules(text)) # get all rules
[
Rule(cat='ra', id='386'),
Rule(cat='ra', id='386'),
Rule(cat='spain', id='civil')
]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
Text to search for statute patterns. |
required |
Yields:
Type | Description |
---|---|
Iterator[Rule]
|
Iterator[Rule]: Serialized Rules and Named Rule patterns |
Source code in statute_patterns/__main__.py
Extract Rule
Thin wrapper over extract_rules()
. If text contains a
matching Rule
, get the first one found.
Examples:
>>> from statute_patterns import extract_rule
>>> text = "The Civil Code of the Philippines, the old Spanish Civil Code; Rep Act No. 386"
>>> extract_rule(text) # get the first matching rule
Rule(cat='ra', id='386')
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
Text to search for statute patterns. |
required |
Returns:
Type | Description |
---|---|
Rule | None
|
Rule | None: The first Rule found, if it exists |
Source code in statute_patterns/__main__.py
Count Rules
Based on results from extract_rules()
,
get the count of each unique rule found.
Examples:
>>> from statute_patterns import count_rules
>>> text = "The Civil Code of the Philippines, the old Spanish Civil Code; Rep Act No. 386"
>>> list(count_rules(text)): # get unique rules with counts
[
{'cat': 'ra', 'id': '386', 'mentions': 2},
{'cat': 'spain', 'id': 'civil', 'mentions': 1}
]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
Text to search for statute patterns. |
required |
Returns:
Type | Description |
---|---|
Iterator[dict]
|
Iterator[dict]: Unique rules converted into dicts with their counts |
Source code in statute_patterns/__main__.py
Detail Rule
We can extract the details of the rule with the StatuteDetails.from_rule()
also accessible via Rule.get_details()
.
Statute Details
Bases: BaseModel
A StatuteDetails
object presupposes the existence of a Rule
object.
After all, it's only when there's a valid path to a Rule
that the
details and provisions of that rule can be extracted. Some notable fields
are described below:
Field | Type | Function |
---|---|---|
rule | Rule |
How we source the path |
title | str | The statute's serial title, e.g. Republic Act No. 386 |
description | str | The statute's official title, e.g. An Act to... |
Source code in statute_patterns/components/details.py
Functions
from_rule(rule, base_path=STATUTE_PATH)
classmethod
From a constructed rule (see Rule.from_path
), get the
details of said rule. Limitation: the category and identifier must
be unique.
Source code in statute_patterns/components/details.py
slug_id(p, dt, v)
classmethod
Use the path's parameters with the date and variant, to create a slug that can serve as the url / primary key of the statute.