justmars/statute-patterns

Handle non-serialized rules

justmars opened this issue · 1 comments

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}",
        ],
    ),
...

In the implementation for serials, we have to identify the digits because the serial numbers are part of the regex pattern.

https://github.com/justmars/lawrgx/blob/156db4aef5fb60e318088d8b7084f3351771c447/lawrgx/serials.py#L65)

Serial Title Category Serial Note
Republic Act No. 386 RA 386 '386' can be found by matching the regex_serials
Republic Act No. 7160 RA 7160 and 7610 '7160 and 7610' can be found by matching the regex_serials; this then needs to be processed separately to arrive at the proper Rule

In the implementation for named statutes, the formula is more bespoke, so that each of the entities have their own regular expression. To be clear, see:

Named Title Category Serial Note
Spanish Civil Code SPAIN civil Both variables can be serialized back into a distinct Rule
Spanish Code of Commerce SPAIN commerce Both variables can be serialized back into a distinct Rule
Old Penal Code SPAIN penal Both variables can be serialized back into a distinct Rule