justmars / statute-patterns Goto Github PK
View Code? Open in Web Editor NEWConstruction of regex patterns for Philippine statutory law.
Home Page: https://lawsql.com
License: BSD 3-Clause "New" or "Revised" License
Construction of regex patterns for Philippine statutory law.
Home Page: https://lawsql.com
License: BSD 3-Clause "New" or "Revised" License
Deal with legacy situation.
Bad codification event; see values={'locator': 'Section 1', 'caption': 'Scope.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991', 'action': 'Modified'}
Bad codification event; see values={'locator': 'A', 'caption': 'Pleadings allowed.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991'}
Bad codification event; see values={'locator': 'B', 'caption': 'Verifications.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991'}
Bad codification event; see values={'locator': 'Section 5', 'caption': 'Answer.', 'content': 'Within ten (10) days from service of summons,', 'statute': 'Resolution of the Court En Banc dated 10-15-1991'}
Bad codification event; see values={'locator': 'Section 6', 'caption': 'Effect of failure to answer.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991'}
Bad codification event; see values={'locator': 'Section 7', 'caption': 'Preliminary conference; appearance of parties.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991'}
Bad codification event; see values={'locator': 'Section 8', 'caption': 'Record of preliminary conference.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991'}
Bad codification event; see values={'locator': 'Section 9', 'caption': 'Submission of affidavits and position papers.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991'}
Bad codification event; see values={'locator': 'Section 10', 'caption': 'Rendition of judgment.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991'}
Bad codification event; see values={'locator': 'Section 18', 'caption': 'Referral to Lupon.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991'}
Bad codification event; see values={'locator': 'Section 19', 'caption': 'Prohibited pleadings and motions.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991'}
Bad codification event; see values={'locator': 'Section 20', 'caption': 'Affidavits.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991'}
Bad codification event; see values={'locator': 'Section 1', 'caption': 'Scope.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991', 'action': 'Modified', 'material_path': '1.1.2.7.9.3.', 'codification_id': 'mv-2022-rule-am-19-10-20-sc-civil-procedure-rules-of-court-v1'}
Bad codification event; see values={'locator': 'A', 'caption': 'Pleadings allowed.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991', 'action': 'Originated', 'material_path': '1.1.2.7.9.4.', 'codification_id': 'mv-2022-rule-am-19-10-20-sc-civil-procedure-rules-of-court-v1'}
Bad codification event; see values={'locator': 'B', 'caption': 'Verifications.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991', 'action': 'Originated', 'material_path': '1.1.2.7.9.4.', 'codification_id': 'mv-2022-rule-am-19-10-20-sc-civil-procedure-rules-of-court-v1'}
Bad codification event; see values={'locator': 'Section 5', 'caption': 'Answer.', 'content': 'Within ten (10) days from service of summons,', 'statute': 'Resolution of the Court En Banc dated 10-15-1991', 'action': 'Originated', 'material_path': '1.1.2.7.9.6.', 'codification_id': 'mv-2022-rule-am-19-10-20-sc-civil-procedure-rules-of-court-v1'}
Bad codification event; see values={'locator': 'Section 6', 'caption': 'Effect of failure to answer.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991', 'action': 'Originated', 'material_path': '1.1.2.7.9.7.', 'codification_id': 'mv-2022-rule-am-19-10-20-sc-civil-procedure-rules-of-court-v1'}
Bad codification event; see values={'locator': 'Section 7', 'caption': 'Preliminary conference; appearance of parties.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991', 'action': 'Originated', 'material_path': '1.1.2.7.9.8.', 'codification_id': 'mv-2022-rule-am-19-10-20-sc-civil-procedure-rules-of-court-v1'}
Bad codification event; see values={'locator': 'Section 8', 'caption': 'Record of preliminary conference.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991', 'action': 'Originated', 'material_path': '1.1.2.7.9.9.', 'codification_id': 'mv-2022-rule-am-19-10-20-sc-civil-procedure-rules-of-court-v1'}
Bad codification event; see values={'locator': 'Section 9', 'caption': 'Submission of affidavits and position papers.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991', 'action': 'Originated', 'material_path': '1.1.2.7.9.10.', 'codification_id': 'mv-2022-rule-am-19-10-20-sc-civil-procedure-rules-of-court-v1'}
Bad codification event; see values={'locator': 'Section 10', 'caption': 'Rendition of judgment.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991', 'action': 'Originated', 'material_path': '1.1.2.7.9.11.', 'codification_id': 'mv-2022-rule-am-19-10-20-sc-civil-procedure-rules-of-court-v1'}
Bad codification event; see values={'locator': 'Section 18', 'caption': 'Referral to Lupon.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991', 'action': 'Originated', 'material_path': '1.1.2.7.9.12.', 'codification_id': 'mv-2022-rule-am-19-10-20-sc-civil-procedure-rules-of-court-v1'}
Bad codification event; see values={'locator': 'Section 19', 'caption': 'Prohibited pleadings and motions.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991', 'action': 'Originated', 'material_path': '1.1.2.7.9.13.', 'codification_id': 'mv-2022-rule-am-19-10-20-sc-civil-procedure-rules-of-court-v1'}
Bad codification event; see values={'locator': 'Section 20', 'caption': 'Affidavits.', 'statute': 'Resolution of the Court En Banc dated 10-15-1991', 'action': 'Originated', 'material_path': '1.1.2.7.9.14.', 'codification_id': 'mv-2022-rule-am-19-10-20-sc-civil-procedure-rules-of-court-v1'}
class Base(Enum):
const = r"((PHIL\.\s+)?CONST(ITUTION|\.?)|(Phil\.\s+)?Const(itution|\.?))" # can refer to 3
admin = r"Administrative\s+Code" # can refer to 3
elect = r"Election\s+Code" # can refer to 2
corp = r"Corporation\s+Code" # can refer to 2
agrarian = r"Agrarian\s+Reform\s+Code" # can refer to 2
civil = r"Civil\s+Code" # can refer to 2
tax = r"(N\.?I\.?R\.?C\.?|National\s+Internal\s+Revenue\s+Code)" # can refer to 3
penal = r"Penal\s+Code" # can refer to 2
coop = r"Cooperative\s+Code" # can refer to 2
insure = r"Insurance\s+Code" # can refer to 2
rules = r"Rules\s+of\s+Court" # can refer to 3
@property
def pattern(self) -> Pattern:
return re.compile(self.value)
def find(self, raw: str) -> Match | None:
return self.pattern.search(raw)
NAMED_LAWS = [
NamedLaw(
base=Base.const.value,
name="1987 Constitution",
year=1987,
serial=StatuteBase(
statute_category=StatuteCategory.CONST, statute_serial_id="1987"
),
aliases=[
add_suffix_PH(rf"1987\s+{Base.const.value}"),
rf"1987\s+{Base.const.value}",
],
),
NamedLaw(
base=Base.const.value,
name="1973 Constitution",
year=1973,
serial=StatuteBase(
statute_category=StatuteCategory.CONST, statute_serial_id="1973"
),
aliases=[
add_suffix_PH(rf"1973\s+{Base.const.value}"),
rf"1973\s+{Base.const.value}",
],
),
...
from statute_utils import StatuteID
serial_title = 'Administrative Matter No. 05-8-26-SC'
l = StatuteID.get_statute_matches(serial_title.lower())
In Administrative Matters, variant folder names become the id. This should not be the case since the serial title without the variant should be retained.
class Rule(BaseModel):
"""Used to identify the statute based on a category and identifier. The `col` and `index` field attributes are not native to Pydantic; these are populated in anticipation of future use via the `sqlpyd` library."""
cat: StatuteCategory = Field(
col=str,
index=True,
)
idx: constr(to_lower=True) = Field( # type: ignore
...,
regex="[a-z0-9-]+",
col=str,
index=True,
)
This becomes usable in the following context:
class CodeRow(Page, Rule, TableConfig): # see Rule use here
__prefix__ = "lex"
__tablename__ = "codifications"
__indexes__ = [["statute_category", "statute_serial_id"]]
statute_id: str | None = Field(
None, col=str, fk=(StatuteRow.__tablename__, "id")
)
TableConfig is sqlpyd
-native and detects that the fields cat
and idx
are going to be part of the database table "codifications".
The appropriation markers in the title should only lead to a canned units result, i.e.
If no existing units path exists. At present, it applies the canned unit results even with a pre-existing path.
class StatuteCounted(NamedTuple):
statute: StatuteBase
mentions: int
@classmethod
def extract_statutes(cls, content: str) -> Iterator[str]:
"""Extract iterator of statute serial texts so that these can be counted via `Counter()`"""
if statutes := StatuteID.get_statute_matches(content):
for s in statutes:
if isinstance(s, StatuteBase): # cat + idx exists
if s.is_single:
yield f"{s.statute_category} {s.statute_serial_id}"
else: # more than one StatuteBase should exist
for dx in s.deconstructed_identifiers:
if isinstance(dx, StatuteBase): # cat + idx exists
yield f"{dx.statute_category} {dx.statute_serial_id}"
@classmethod
def count_statutes(cls, content: str):
statutes_detected = list(cls.extract_statutes(content))
counted = Counter(statutes_detected)
unique_statutes = iter(set(statutes_detected))
for i in unique_statutes:
mentions = counted[i]
elements = i.split()
cat = StatuteCategory(elements[0])
idx = elements[1]
try:
base = StatuteBase(statute_category=cat, statute_serial_id=idx)
yield cls(statute=base, mentions=mentions)
except Exception as e:
msg = f"Bad {elements=} in forming statute base; see {e=}"
logger.error(msg)
Existing approach:
https://github.com/justmars/lawrgx/blob/8e893d0fa2c7a6b71059257971bbda887baf569a/lawrgx/names.py
Instead of manually constructing named patterns, may want to use something more programmatic. See experimental:
Node items have the format:
- locator: x
action: y
statute: Republic Act No. 386 # this is a standardized serial title
Extract the cat
(ra) and idx
(386) values from the serial title.
Revised the serializer function.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.