Justice
A Justice, as defined in this reference document, is one of many justices sitting in the Supreme Court:
Bases: BaseModel
Justice
Field | Type | Description |
---|---|---|
id | int | Unique identifier of the Justice based on appointment roster |
full_name | str | First + last + suffix |
first_name | str | - |
last_name | str | - |
suffix | str | e.g. Jr., Sr., III, etc. |
nick_name | str | - |
gender | str | - |
alias | str | Other names |
start_term | str | Time justice appointed |
end_term | str | Time justice |
chief_date | str | Date appointed as Chief Justice (optional) |
birth_date | str | Date of birth |
retire_date | str | Based on the Birth Date, if it exists, it is the maximum term of service allowed by law. |
inactive_date | str | Which date is earliest inactive date of the Justice, the retire date is set automatically but it is not guaranteed to to be the actual inactive date. So the inactive date is either that specified in the end_term or the retire_date , whichever is earlier. |
The list of justices from the sc.yaml file are parsed through this model prior to being inserted into the database.
Source code in corpus_judge/justice_model.py
Python | |
---|---|
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
Creating a Justice table
The source file for the sqlite database is sc.yaml
. This ought to be edited whenever
new justices are added. It is referenced via JUSTICE_FILE
:
Note the default table name used by CandidateJustice
is "justices".
from corpus_judge import JUSTICE_FILE
from sqlite_utils import Database
from pathlib import Path
import yaml
def add_justices(db: Database):
tbl = db["justices"] # default table name
if not tbl.exists():
file_content = JUSTICE_FILE.read_bytes()
records = yaml.safe_load(file_content)
tbl.insert_all(records, ignore=True) # type: ignore
p = Path("new.db")
db = Database(p)
add_justices(db)
Cleaning Raw Justice Names
Bases: NamedTuple
Source code in corpus_judge/justice_name.py
Functions
clean(text)
classmethod
Each ponente
name stored in the database can be uniform. Will
parse text, apply some cleaning steps, and result in a lower-cased form
of the original text
, e.g.:
Some constraints:
- Must be more than 4 characters
- Must be less than 40 characters
Examples:
>>> OpinionWriterName.clean("REYES , J.B.L, Acting C.J.") # sample name 1
'reyes, j.b.l.'
>>> OpinionWriterName.clean("REYES, J, B. L. J.") # sample name 2
'reyes, j.b.l.'
Source code in corpus_judge/justice_name.py
extract(text)
classmethod
Will mark per_curiam
to be True if the regex pattern matches,
else, will clean the writer represented by the text, if possible.
Examples:
>>> OpinionWriterName.extract('Justice Marvic M.V.F. Leonen')
OpinionWriterName(writer='leonen', per_curiam=False)
>>> OpinionWriterName.extract('Justice Filomena D. Signh') # note bad spelling
OpinionWriterName(writer='singh', per_curiam=False)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str | None
|
Text to evaluate. |
required |
Returns:
Type | Description |
---|---|
Self | None
|
Self | None: Instance representing the writer. |
Source code in corpus_judge/justice_name.py
Candidate Justice
Bases: NamedTuple
Source code in corpus_judge/justice_select.py
Python | |
---|---|
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
Attributes
choice: dict | None
property
Based on @rows
, match the cleaned_name to either the alias
of the justice or the justice's last name; on match, determine whether the
designation should be 'C.J.' or 'J.'
detail: JusticeDetail | None
property
Get object to match fields directly
Returns:
Type | Description |
---|---|
JusticeDetail | None
|
JusticeDetail | None: Can subsequently be used in third-party library. |
ponencia: dict[str, Any]
property
Produces a dict of partial fields that include the following keys:
justice_id
: intraw_ponente
: strper_curiam
: bool
rows: list[dict]
property
When selecting a ponente or voting members, create a candidate list of
justices based on the valid_date
.
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: Filtered list of justices |
View chief justice dates
WITH end_chief_date(d) AS (
-- For each chief justice, get a second date: the date that the next chief justice is appointed; Can get this by getting the first chief date greater than the present chief date and using an ascending order. */
SELECT
DATE(
tbl2.chief_date,
'-1 day'
)
FROM
{{ justice_table }}
tbl2
WHERE
tbl2.chief_date IS NOT NULL
AND tbl2.chief_date > tbl1.chief_date
ORDER BY
tbl2.chief_date ASC
LIMIT
1
), time_as_chief(period) AS (
-- Difference between the two chief dates: that will be the time served as chief in years format */
SELECT
(
SELECT
DATE(d)
FROM
end_chief_date
) - DATE(
tbl1.chief_date
)
)
SELECT
tbl1.id,
tbl1.last_name,
tbl1.chief_date,
(
SELECT
d
FROM
end_chief_date
) max_end_chief_date,
MIN(
tbl1.inactive_date,
(
SELECT
d
FROM
end_chief_date
)
) actual_inactive_as_chief,
(
SELECT
period
FROM
time_as_chief
) years_as_chief
FROM
{{ justice_table }}
tbl1
WHERE
tbl1.chief_date IS NOT NULL
ORDER BY
tbl1.chief_date DESC
[
{
'id': 178,
'last_name': 'Gesmundo',
'chief_date': '2021-04-05',
'max_end_chief_date': None,
'actual_inactive_as_chief': None,
'years_as_chief': None
},
{
'id': 162,
'last_name': 'Peralta',
'chief_date': '2019-10-23',
'max_end_chief_date': '2021-04-04',
'actual_inactive_as_chief': '2021-03-27',
'years_as_chief': 2
},
{
'id': 163,
'last_name': 'Bersamin',
'chief_date': '2018-11-26',
'max_end_chief_date': '2019-10-22',
'actual_inactive_as_chief': '2019-10-18',
'years_as_chief': 1
},
{
'id': 160,
'last_name': 'Leonardo-De Castro',
'chief_date': '2018-08-28',
'max_end_chief_date': '2018-11-25',
'actual_inactive_as_chief': '2018-10-08',
'years_as_chief': 0
}...
]