allowing multiple summaries per bill text
This commit is contained in:
@@ -6,6 +6,7 @@ from pipelines.orm.data_science_dev.congress.bill import (
|
||||
BillActionRecordedVote,
|
||||
BillRelation,
|
||||
BillText,
|
||||
BillTextSummary,
|
||||
BillTopic,
|
||||
BillTopicPosition,
|
||||
)
|
||||
@@ -54,6 +55,7 @@ __all__ = [
|
||||
"BillActionRecordedVote",
|
||||
"BillRelation",
|
||||
"BillText",
|
||||
"BillTextSummary",
|
||||
"BillTopic",
|
||||
"BillTopicPosition",
|
||||
"ClassificationMethod",
|
||||
|
||||
@@ -105,13 +105,12 @@ class BillText(DataScienceDevTableBase):
|
||||
)
|
||||
|
||||
bill_id: Mapped[int] = mapped_column(ForeignKey("main.bill.id", ondelete="CASCADE"))
|
||||
primary_summary_id: Mapped[int | None] = mapped_column(
|
||||
ForeignKey("main.bill_text_summary.id", ondelete="SET NULL")
|
||||
)
|
||||
version_code: Mapped[str]
|
||||
version_name: Mapped[str | None]
|
||||
text_content: Mapped[str | None]
|
||||
summary: Mapped[str | None]
|
||||
summarization_model: Mapped[str | None]
|
||||
summarization_user_prompt_version: Mapped[str | None]
|
||||
summarization_system_prompt_version: Mapped[str | None]
|
||||
date: Mapped[date | None]
|
||||
source_datetime_raw: Mapped[str | None]
|
||||
text_url_xml: Mapped[str | None]
|
||||
@@ -122,6 +121,57 @@ class BillText(DataScienceDevTableBase):
|
||||
)
|
||||
|
||||
bill: Mapped[Bill] = relationship("Bill", back_populates="bill_texts")
|
||||
summaries: Mapped[list[BillTextSummary]] = relationship(
|
||||
"BillTextSummary",
|
||||
back_populates="bill_text",
|
||||
cascade="all, delete-orphan",
|
||||
foreign_keys="BillTextSummary.bill_text_id",
|
||||
order_by=lambda: (
|
||||
BillTextSummary.created.desc(),
|
||||
BillTextSummary.id.desc(),
|
||||
),
|
||||
)
|
||||
primary_summary: Mapped[BillTextSummary | None] = relationship(
|
||||
"BillTextSummary",
|
||||
foreign_keys=[primary_summary_id],
|
||||
post_update=True,
|
||||
)
|
||||
|
||||
def latest_summary(self) -> BillTextSummary | None:
|
||||
"""Return the newest summary row for this bill text."""
|
||||
return self.summaries[0] if self.summaries else None
|
||||
|
||||
def default_summary(self) -> BillTextSummary | None:
|
||||
"""Return the primary summary when set, otherwise the newest summary."""
|
||||
return self.primary_summary or self.latest_summary()
|
||||
|
||||
|
||||
class BillTextSummary(DataScienceDevTableBase):
|
||||
"""Stores one generated summary for a bill text version."""
|
||||
|
||||
__tablename__ = "bill_text_summary"
|
||||
__table_args__ = (
|
||||
Index("ix_bill_text_summary_bill_text_id", "bill_text_id"),
|
||||
Index(
|
||||
"ix_bill_text_summary_bill_text_id_created",
|
||||
"bill_text_id",
|
||||
"created",
|
||||
),
|
||||
)
|
||||
|
||||
bill_text_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("main.bill_text.id", ondelete="CASCADE")
|
||||
)
|
||||
summary: Mapped[str]
|
||||
summarization_model: Mapped[str | None]
|
||||
summarization_user_prompt_version: Mapped[str | None]
|
||||
summarization_system_prompt_version: Mapped[str | None]
|
||||
|
||||
bill_text: Mapped[BillText] = relationship(
|
||||
"BillText",
|
||||
back_populates="summaries",
|
||||
foreign_keys=[bill_text_id],
|
||||
)
|
||||
|
||||
|
||||
class BillAction(DataScienceDevTableBase):
|
||||
|
||||
@@ -11,6 +11,7 @@ from pipelines.orm.data_science_dev.congress import (
|
||||
BillActionRecordedVote,
|
||||
BillRelation,
|
||||
BillText,
|
||||
BillTextSummary,
|
||||
BillTopic,
|
||||
BillTopicPosition,
|
||||
ClassificationMethod,
|
||||
@@ -51,6 +52,7 @@ __all__ = [
|
||||
"BillActionRecordedVote",
|
||||
"BillRelation",
|
||||
"BillText",
|
||||
"BillTextSummary",
|
||||
"BillTopic",
|
||||
"BillTopicPosition",
|
||||
"ClassificationMethod",
|
||||
|
||||
Reference in New Issue
Block a user