Skip to content

Commit

Permalink
feat: modified slug
Browse files Browse the repository at this point in the history
  • Loading branch information
justmars committed Aug 13, 2023
1 parent 31b8ee6 commit afe146e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
61 changes: 31 additions & 30 deletions citation_utils/citation.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,15 @@ def ser_model(self) -> dict[str, str | datetime.date | None]:
"offg": self.serialize_offg(self.offg),
}

def get_db_id(self) -> str | None:
"""Value created usable unique identifier of a decision."""
def set_slug(self) -> str | None:
"""Create a unique identifier of a decision.
Examples:
>>> text = "GR 138570, Oct. 10, 2000"
>>> Citation.extract_citation(text).set_slug()
'gr-138570-2000-10-10'
"""
bits = [
self.serialize_cat(self.docket_category),
self.serialize_num(self.docket_serial),
Expand All @@ -156,12 +163,33 @@ def get_db_id(self) -> str | None:
return "-".join(bits) # type: ignore
return None

@classmethod
def get_docket_slug_from_text(cls, v: str) -> str | None:
"""Given a docket string, format the string into a slug
that has the same signature as a database primary key.
Examples:
>>> text = "GR 138570, Oct. 10, 2000"
>>> Citation.get_docket_slug_from_text(text)
'gr-138570-2000-10-10'
Args:
v (str): The text to evaluate
Returns:
str | None: The slug to use, if possible.
"""
if cite := cls.extract_citation(v):
if cite.is_docket:
return cite.set_slug()
return None

def make_docket_row(self):
"""This presumes that a valid docket exists. Although a citation can
be a non-docket, e.g. phil, scra, etc., for purposes of creating a
a route-based row for a prospective decision object, the identifier will be
based on a docket id."""
if id := self.get_db_id():
if id := self.set_slug():
return self.model_dump() | {"id": id}
logging.error(f"Undocketable: {self=}")
return None
Expand Down Expand Up @@ -307,33 +335,6 @@ def extract_citation(cls, text: str) -> Self | None:
except StopIteration:
return None

@classmethod
def create_docket_slug(cls, v: str) -> str | None:
"""Given a docket string, format the string into a slug
that can be a database primary key.
Examples:
>>> text = "GR 138570, Oct. 10, 2000"
>>> Citation.create_docket_slug(text)
'gr-138570-2000-10-10'
Args:
v (str): The text to evaluate
Returns:
str | None: The slug to use, if possible.
"""
if cite := cls.extract_citation(v):
if cite.is_docket:
return "-".join(
[
cite.docket_category.name.lower(), # type: ignore
cite.docket_serial.lower(), # type: ignore
cite.docket_date.isoformat(), # type: ignore
]
)
return None

@classmethod
def make_citation_string(
cls,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "citation_utils"
version = "0.4.9"
version = "0.4.10"
description = "Pattern matching Philippine Supreme Court citations."
authors = ["Marcelino G. Veloso III <contact@mv3.dev>"]
homepage = "https://lawsql.com"
Expand Down

0 comments on commit afe146e

Please sign in to comment.