Skip to content

Named Statutes

Named Pattern

Bases: BasePattern

A Rule can be extracted from a NamedPattern

Source code in statute_patterns/models.py
Python
class NamedPattern(BasePattern):
    """A [`Rule`][rule-model] can be extracted from a `NamedPattern`"""

    name: str
    regex_base: str
    rule: Rule

    @property
    def regex(self) -> str:
        return stx(rf"(?P<{self.group_name}>{self.regex_base})")

    @property
    def group_name(self) -> str:
        texts = " ".join([self.rule.cat, self.rule.id])
        return slugify(texts, separator="_", lowercase=True)

Named Statute Collection

Bases: BaseCollection

Each named legal title, not falling under the SerialNames Patterns, will also have its own manually crafted regex string. Examples include 'the Spanish Civil Code' or the '1987 Constitution' or the 'Code of Professional Responsibility'.

Source code in statute_patterns/models.py
Python
class NamedPatternCollection(BaseCollection):
    """Each named legal title, not falling under the SerialNames Patterns,
    will also have its own manually crafted regex string. Examples include
    'the Spanish Civil Code' or the '1987 Constitution' or the
    'Code of Professional Responsibility'.
    """

    collection: list[NamedPattern]

    def extract_rules(self, text: str) -> Iterator[Rule]:
        for m in self.pattern.finditer(text):
            for named in self.collection:
                if m.lastgroup == named.group_name:
                    yield named.rule