Created
May 29, 2014 20:09
-
-
Save krusynth/042436d1830f7c761d15 to your computer and use it in GitHub Desktop.
State Decoded parser for Philadelphia for American Legal data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* San Francisco parser for State Decoded. | |
* Extends AmericanLegal base classes. | |
* | |
* PHP version 5 | |
* | |
* @license http://www.gnu.org/licenses/gpl.html GPL 3 | |
* @version 0.8 | |
* @link http://www.statedecoded.com/ | |
* @since 0.3 | |
*/ | |
/** | |
* This class may be populated with custom functions. | |
*/ | |
require 'class.AmericanLegal.inc.php'; | |
class State extends AmericanLegalState {} | |
class Parser extends AmericanLegalParser | |
{ | |
/* | |
* Most codes have a Table of Contents as the first LEVEL. | |
*/ | |
public function pre_parse_chapter(&$chapter) | |
{ | |
// Get all of the titles. | |
$titles = $chapter->REFERENCE->TITLE; | |
$title_count = count($titles); | |
// We skip the last title, thus " - 1" | |
for($i = 0; $i < $title_count - 1; $i++) | |
{ | |
unset($name, $identifier, $order_by); | |
$title = $titles[$i]; | |
// Clean up the title, strip some html. | |
$title = trim(str_replace('"', '', $title)); | |
if(preg_match($this->structure_regex, $title, $matches)) | |
{ | |
$name = $matches['name']; | |
$identifier = $matches['number']; | |
} | |
else | |
{ | |
switch($title) | |
{ | |
case 'THE PHILADELPHIA CODE' : | |
$name = 'The Philadelphia Code'; | |
$identifier = 'Philadelphia'; | |
$order_by = '0'; | |
break; | |
case 'PHILADELPHIA HOME RULE CHARTER' : | |
$name = 'Philadelphia Home Rule Charter'; | |
$identifier = 'Charter'; | |
$order_by = '1'; | |
break; | |
} | |
} | |
if(isset($name) && isset($identifier)) | |
{ | |
$structure = new stdClass(); | |
$structure->name = $this->clean_title($name); | |
$structure->label = 'Code'; | |
$structure->identifier = $this->clean_identifier($identifier); | |
if(!isset($order_by)) | |
{ | |
$order_by = $this->get_structure_order_by($structure); | |
} | |
$structure->order_by = $order_by; | |
if(isset($last_structure)) | |
{ | |
$structure->parent_id = $last_structure->id; | |
} | |
$structure->level = count($this->structures) + 1; | |
// if(isset($matches[3]) && strlen(trim($matches[3]))) | |
// { | |
// $structure->metadata = new stdClass(); | |
// $structure->metadata->text = trim($matches[3]); | |
// } | |
$this->create_structure($structure); | |
$last_structure = $structure; | |
$this->structures[] = $structure; | |
} | |
else { | |
$this->logger->message('Cannot get title from structure: "' . $title . '"', 5); | |
} | |
} | |
// If there's two levels,this has a table of contents. | |
if(count($chapter->LEVEL->LEVEL) == 2 && isset($chapter->LEVEL->LEVEL[1]->LEVEL) && isset($chapter->LEVEL->LEVEL[1]->LEVEL->LEVEL)) | |
{ | |
$this->logger->message('Skipping first level.', 2); | |
unset($chapter->LEVEL->LEVEL[0]); | |
} | |
} | |
public function get_structure_order_by($structure) | |
{ | |
// Make room for the charter by adding one. | |
return 1 + (int) parent::get_structure_order_by($structure); | |
} | |
public function get_section_parts($section) | |
{ | |
/* | |
* Parse the catch line and section number. | |
*/ | |
$section_title = $this->clean_title((string) $section->RECORD->HEADING); | |
$this->logger->message('Title: ' . $section_title, 2); | |
switch($section_title) | |
{ | |
case 'PREFACE TO THE TENTH EDITION' : | |
$section_parts = array( | |
'catch_line' => 'Preface to the Tenth Edition', | |
'number' => 'Preface' | |
); | |
break; | |
case 'PREAMBLE' : | |
$section_parts = array( | |
'catch_line' => 'Preamble', | |
'number' => 'Preamble' | |
); | |
break; | |
} | |
if(!isset($section_parts)) | |
{ | |
$section_parts = parent::get_section_parts($section_title); | |
} | |
return $section_parts; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment