Skip to content

Commit

Permalink
Allow fully manual motion specification
Browse files Browse the repository at this point in the history
  • Loading branch information
ajparsons committed Nov 25, 2024
1 parent c07f952 commit 8e4f389
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
12 changes: 12 additions & 0 deletions data/raw/manual_motion_linking.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,17 @@
{
"decision_gid": "uk.org.publicwhip/debate/2023-04-19d.336.0",
"motion_gid": "uk.org.publicwhip/debate/2023-04-19d.323.2.7"
},
{
"decision_gid": "uk.org.publicwhip/debate/2024-10-09c.415.0",
"motion": {
"date": "2024-10-09",
"gid": "uk.org.publicwhip/debate/2024-10-09c.332.0.2",
"speech_id": "uk.org.publicwhip/debate/2024-10-09c.332.0",
"motion_lines": [
"[Reasoned amendment - opposing a second reading]"
],
"motion_title": "Renters' Rights Bill: Reasoned Amendment to Second Reading"
}
}
]
34 changes: 31 additions & 3 deletions src/parl_motion_detector/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import rich
from mysoc_validator import Transcript
from mysoc_validator.models.transcripts import Chamber
from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, TypeAdapter

from parl_motion_detector.detector import PhraseDetector

Expand All @@ -28,10 +28,31 @@
DEBUG: bool = False


class ManualLink(BaseModel):
decision_gid: str
motion_gid: str


class ManualText(BaseModel):
decision_gid: str
motion: Motion


ManualInfo = ManualLink | ManualText


@lru_cache
def get_manual_connections(data_dir: Path) -> dict[str, str]:
data = json.loads(Path(data_dir, "raw", "manual_motion_linking.json").read_text())
return {x["motion_gid"]: x["decision_gid"] for x in data}
data = Path(data_dir, "raw", "manual_motion_linking.json").read_text()
items = TypeAdapter(list[ManualLink | ManualText]).validate_json(data)
return {x.motion_gid: x.decision_gid for x in items if isinstance(x, ManualLink)}


@lru_cache
def get_manual_text(data_dir: Path) -> dict[str, Motion]:
data = Path(data_dir, "raw", "manual_motion_linking.json").read_text()
items = TypeAdapter(list[ManualLink | ManualText]).validate_json(data)
return {x.decision_gid: x.motion for x in items if isinstance(x, ManualText)}


amendment_be_made = PhraseDetector(criteria=["That the amendment be made."])
Expand Down Expand Up @@ -687,6 +708,13 @@ def assign_manual(self):
elif len(mdecision) == 0:
raise ValueError(f"Manual lookup failed to find {mdecision_gid}")

# when motions are just missing, sometimes we specify the whole thing by hand
manual_motions = get_manual_text(self.data_dir)
for decision in decisions:
if decision.gid in manual_motions:
motion = manual_motions[decision.gid]
self.assign_motion_decision(motion, decision, "manual text")

def assigned_gids(self):
division_gids = [x.gid for x in self.division_assignments]
agreement_gids = [x.gid for x in self.agreement_assignments]
Expand Down
6 changes: 3 additions & 3 deletions src/parl_motion_detector/motions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ class Flag(StrEnum):
class Motion(BaseModel):
date: str
motion_title: str = ""
major_heading_id: str
minor_heading_id: str
major_heading_id: str = ""
minor_heading_id: str = ""
major_heading_title: str = ""
minor_heading_title: str = ""
speech_start_pid: str
speech_start_pid: str = ""
speech_id: str
final_speech_id: str = ""
end_reason: str = ""
Expand Down

0 comments on commit 8e4f389

Please sign in to comment.