Jump to content

User:Psiĥedelisto/Court case title.py

From Wikipedia, the free encyclopedia

This script converts Supreme Court of the Philippines case names into Wikipedia MOS compatible full case names.

Script

[edit]
#!/usr/bin/python3

#I know this script's code is bad, and globals are bad. I was using it in the REPL for a while,
#not that that's a good excuse. It's free, so there's that. :-)

import string
import re
import sys
O=str()

def selectULT(e):
    E = ''.join(c for c in e if c.isalnum())
    if E.lower() in ['ii', 'iii', 'iv', 'vi', 'vii', 'viii', 'ix']:
        return e.upper()
    # Ingles-inglesin mo 'ko sa bayan ko punyeta!?
    elif E.lower() in ['from', 'by', 'the', 'and', 'of', 'for', 'represented', 
                       'et', 'al.', 'in', 'as', 'his', 'her', 'capacity', 'de', 
                       'del', 'all', 'their', 'to', 'on', 'official', 'personal',
                       'composed', 'who', 'have', 'has', 'had', 'having',
                       'manager', 'proprietor', 'surnamed', 'minors', 'parents',
                       'minor', 'parent']:
        return e.lower()
    # 'Yan na lang po
    elif E.lower() in ['ang', 'ng', 'mga', 'ay']:
        return e.lower()
    elif e.lower() in ['y', 'al.', 'and/or']:
        return e.lower()
    elif E.upper() in ['USA', 'KK', 'LLC', 'PLC', 'GMA', 'ABSCBN', 'TV5', 'RTC', 'CA']:
        return e.upper()
    elif e == "v.": 
        return "v."
    elif e == "v" or e == "x": 
        return e.upper()
    elif re.match('\\([A-Z]{2,}\\)', e): # i.e. "NUJP"
        return None if e[-1] != ',' else ","
    elif e.lower().startswith('http') or e.lower().startswith('www'):
        return e.lower()
    elif e.lower() == "representative":
        return "Rep."
    elif e.lower() == "senator":
        return "Sen."
    elif e.lower() == "honorable":
        return "Hon."
    else:
        return e.title()


def makeO():
    global O
    S=s.replace('\n',' ').replace('vs.','v.')
    S=re.sub(', ([Pp]etitioner|[Rr]espondent)s?[,.]', '', S)
    O=' '.join(ee.strip() for ee in filter(None, [selectULT(e) for e in S.split()]))
    # v. his Excellency → v. His Excellency
    O=re.sub('v\. ([a-z])', lambda m: "v. "+m.expand('\\1').upper(), O)
    # Disini, Jr. → Disini Jr.
    O=re.sub(', ([JS]r)\.', ' \\1.', O)

s=sys.stdin.read()
makeO(); print(O.replace(" ,",',').replace('E-','e').replace('&','and'))

Examples

[edit]
$ export F=/tmp/disini; cat "$F"; echo; echo; CourtCT.py < "$F"
JOSE JESUS M. DISINI, JR., ROWENA S. DISINI, LIANNE IVY P. MEDINA, JANETTE TORAL and ERNESTO SONIDO, JR., Petitioners,
vs.
THE SECRETARY OF JUSTICE, THE SECRETARY OF THE DEPARTMENT OF THE INTERIOR AND LOCAL GOVERNMENT, THE EXECUTIVE DIRECTOR OF THE INFORMATION AND COMMUNICATIONS TECHNOLOGY OFFICE, THE CHIEF OF THE PHILIPPINE NATIONAL POLICE and THE DIRECTOR OF THE NATIONAL BUREAU OF INVESTIGATION, Respondents.

Jose Jesus M. Disini Jr., Rowena S. Disini, Lianne Ivy P. Medina, Janette Toral and Ernesto Sonido Jr. v. The Secretary of Justice, the Secretary of the Department of the Interior and Local Government, the Executive Director of the Information and Communications Technology Office, the Chief of the Philippine National Police and the Director of the National Bureau of Investigation

$ export F=/tmp/gr203407; cat "$F"; echo; echo; CourtCT.py < "$F"
BAGONG ALYANSANG MAKABAYAN SECRETARY GENERAL RENATO M. REYES, JR., National Artist BIENVENIDO L. LUMBERA, Chairperson of Concerned Artists of the Philippines, ELMER C. LABOG, Chairperson of Kilusang Mayo Uno, CRISTINA E. PALABAY, Secretary General of Karapatan, FERDINAND R. GAITE, Chairperson of COURAGE, JOEL B. MAGLUNSOD, Vice President of Anakpawis Party-List, LANA R. LINABAN, Secretary General Gabriela Women's Party, ADOLFO ARES P. GUTIERREZ, and JULIUS GARCIA MATIBAG, Petitioners,
vs.
BENIGNO SIMEON C. AQUINO III, President of the Republic of the Philippines, PAQUITO N. OCHOA, JR., Executive Secretary, SENATE OF THE PHILIPPINES, represented by SENATE PRESIDENT JUAN PONCE ENRILE, HOUSE OF REPRESENTATIVES, represented by SPEAKER FELICIANO BELMONTE, JR., LEILA DE LIMA, Secretary of the Department of Justice, LOUIS NAPOLEON C. CASAMBRE, Executive Director of the Information and Communications Technology Office, NONNATUS CAESAR R. ROJAS, Director of the National Bureau of Investigation, D/GEN. NICANOR A. BARTOLOME, Chief of the Philippine National Police, MANUEL A. ROXAS II, Secretary of the Department of the Interior and Local Government, Respondents.

Bagong Alyansang Makabayan Secretary General Renato M. Reyes Jr., National Artist Bienvenido L. Lumbera, Chairperson of Concerned Artists of the Philippines, Elmer C. Labog, Chairperson of Kilusang Mayo Uno, Cristina E. Palabay, Secretary General of Karapatan, Ferdinand R. Gaite, Chairperson of Courage, Joel B. Maglunsod, Vice President of Anakpawis Party-List, Lana R. Linaban, Secretary General Gabriela Women'S Party, Adolfo Ares P. Gutierrez, and Julius Garcia Matibag v. Benigno Simeon C. Aquino III, President of the Republic of the Philippines, Paquito N. Ochoa Jr., Executive Secretary, Senate of the Philippines, represented by Senate President Juan Ponce Enrile, House of Representatives, represented by Speaker Feliciano Belmonte Jr., Leila de Lima, Secretary of the Department of Justice, Louis Napoleon C. Casambre, Executive Director of the Information and Communications Technology Office, Nonnatus Caesar R. Rojas, Director of the National Bureau of Investigation, D/Gen. Nicanor A. Bartolome, Chief of the Philippine National Police, Manuel A. Roxas II, Secretary of the Department of the Interior and Local Government

$ export F=/tmp/silly; cat "$F"; echo; echo; CourtCT.py < "$F"
SERJ TANKIAN, THE QUEEN OF MEXICO, QUEENIE X. V. I. TANKIAN, PURDUE MILIEU INC., PUNGENT LLC, AND SENATOR FALCIS V IN HIS OFFICIAL CAPACITY AS RULER OF THE WORLD, petitioners, vs. WIKIMEDIA FOUNDATION USA, INC., TAMBAYAN PILIPINS AY ANG BAHAY NATIN INC., ET AL., respondents.

Serj Tankian, the Queen of Mexico, Queenie X. V. I. Tankian, Purdue Milieu Inc., Pungent LLC, and Sen. Falcis V in his official capacity as Ruler of the World v. Wikimedia Foundation USA, Inc., Tambayan Pilipins ay ang Bahay Natin Inc., et al.