src/snac/util/EADParser.php
/**
     * Post-Process Created TSV files
     *
     * Reads in and modifies the TSV files created by the XSLT processing.  Currently modifies
     * the CPF-Table to make it OR-ready for multiple rows per record.
     *
     * @param $dir string The directory where files are stored
     */
Post-Process Created TSV files
Reads in and modifies the TSV files created by the XSLT processing.  Currently modifies
the CPF-Table to make it OR-ready for multiple rows per record.

@param $dir string The directory where files are stored
Post - Process Created TSV files Reads in and modifies the TSV files created by the XSLT processing . Currently modifies the CPF - Table to make it OR - ready for multiple rows per record . @param $dir string The directory where files are stored
private function postProcess($dir) {
        $cpftable = [];
        $colsToSplit = [];
        if (($handle = fopen($dir."/CPF-Table.tsv", "r")) !== false) {
            while (($line = fgetcsv($handle, 10000000, "\t")) !== false) {
                $additionalRows = [];
                $currentLine = [];
                $numCols = count($line);
                foreach ($line as $j => $v) {
                    $parts = explode($this->ROW_SEPARATOR, $v);
                    foreach ($parts as $part) {
                        if (strpos($part, $this->COLUMN_SEPARATOR) !== false)
                            $colsToSplit[$j] = true;
                    }
                    if (count($parts) == 1) {
                        $currentLine[$j] = $v;
                    } else {
                        $currentLine[$j] = array_shift($parts);
                        for ($k = 0; $k < count($additionalRows) && !empty($parts); $k++) {
                            $additionalRows[$k][$j] = array_shift($parts);
                        }
                        if (!empty($parts)) {
                            foreach ($parts as $part) {
                                $newLine = [];
                                for ($l = 0; $l < $numCols; $l++)
                                    $newLine[$l] = "";
                                $newLine[$j] = $part;
                                array_push($additionalRows, $newLine);
                            }
                        }
                    }
                }
                array_push($cpftable, $currentLine);
                if (!empty($additionalRows)) {
                    foreach ($additionalRows as $newRow)
                        array_push($cpftable, $newRow);
                }
            }
            fclose($handle);
        }
        if (!empty($cpftable)) {
            $numOrigCols = count($cpftable[0]);
            $headers = $cpftable[0];
            $newtable = [];
            $newheaders = [];
            for ($i = 0; $i < $numOrigCols; $i++) {
                array_push($newheaders, $headers[$i]);
                if (isset($colsToSplit[$i]))
                    array_push($newheaders, $headers[$i] . " Type");
            }
            array_push($newtable, $newheaders);
            foreach($cpftable as $i => $row) {
                if ($i == 0) continue;
                $newRow = [];
                for ($j = 0; $j < count($row); $j++) {
                    if (isset($colsToSplit[$j])) {
                        $parts = explode($this->COLUMN_SEPARATOR, $row[$j]);
                        foreach ($parts as $part)
                            array_push($newRow, $part);
                        if (count($parts) < 2)
                            array_push($newRow, '');
                    } else {
                        array_push($newRow, $row[$j]);
                    }
                }
                array_push($newtable, $newRow);
            } 
            if (($handle = fopen($dir."/CPF-Table.tsv", "w")) !== false) {
                foreach ($newtable as $row) {
                    fputcsv($handle, $row, "\t");
                }
                fclose($handle);
            }
        }
    }
private function postProcess ( $ dir ) { $ cpftable = [ ] ; $ colsToSplit = [ ] ; if ( ( $ handle = fopen ( $ dir . " /CPF-Table.tsv " , " r " ) ) !== false ) { while ( ( $ line = fgetcsv ( $ handle , 10000000 , " \t " ) ) !== false ) { $ additionalRows = [ ] ; $ currentLine = [ ] ; $ numCols = count ( $ line ) ; foreach ( $ line as $ j => $ v ) { $ parts = explode ( $ this -> ROW_SEPARATOR , $ v ) ; foreach ( $ parts as $ part ) { if ( strpos ( $ part , $ this -> COLUMN_SEPARATOR ) !== false ) $ colsToSplit [ $ j ] = true ; } if ( count ( $ parts ) == 1 ) { $ currentLine [ $ j ] = $ v ; } else { $ currentLine [ $ j ] = array_shift ( $ parts ) ; for ( $ k = 0 ; $ k < count ( $ additionalRows ) && ! empty ( $ parts ) ; $ k ++ ) { $ additionalRows [ $ k ] [ $ j ] = array_shift ( $ parts ) ; } if ( ! empty ( $ parts ) ) { foreach ( $ parts as $ part ) { $ newLine = [ ] ; for ( $ l = 0 ; $ l < $ numCols ; $ l ++ ) $ newLine [ $ l ] = " " ; $ newLine [ $ j ] = $ part ; array_push ( $ additionalRows , $ newLine ) ; } } } } array_push ( $ cpftable , $ currentLine ) ; if ( ! empty ( $ additionalRows ) ) { foreach ( $ additionalRows as $ newRow ) array_push ( $ cpftable , $ newRow ) ; } } fclose ( $ handle ) ; } if ( ! empty ( $ cpftable ) ) { $ numOrigCols = count ( $ cpftable [ 0 ] ) ; $ headers = $ cpftable [ 0 ] ; $ newtable = [ ] ; $ newheaders = [ ] ; for ( $ i = 0 ; $ i < $ numOrigCols ; $ i ++ ) { array_push ( $ newheaders , $ headers [ $ i ] ) ; if ( isset ( $ colsToSplit [ $ i ] ) ) array_push ( $ newheaders , $ headers [ $ i ] . "  Type " ) ; } array_push ( $ newtable , $ newheaders ) ; foreach ( $ cpftable as $ i => $ row ) { if ( $ i == 0 ) continue ; $ newRow = [ ] ; for ( $ j = 0 ; $ j < count ( $ row ) ; $ j ++ ) { if ( isset ( $ colsToSplit [ $ j ] ) ) { $ parts = explode ( $ this -> COLUMN_SEPARATOR , $ row [ $ j ] ) ; foreach ( $ parts as $ part ) array_push ( $ newRow , $ part ) ; if ( count ( $ parts ) < 2 ) array_push ( $ newRow , '' ) ; } else { array_push ( $ newRow , $ row [ $ j ] ) ; } } array_push ( $ newtable , $ newRow ) ; } if ( ( $ handle = fopen ( $ dir . " /CPF-Table.tsv " , " w " ) ) !== false ) { foreach ( $ newtable as $ row ) { fputcsv ( $ handle , $ row , " \t " ) ; } fclose ( $ handle ) ; } } }
Post-Process Created TSV files
 Reads in and modifies the TSV files created by the XSLT processing.
Post - Process Created TSV files Reads in and modifies the TSV files created by the XSLT processing .
// Files in the directory //$dir."/Join-Table.tsv" //$dir."/CPF-Table.tsv" //$dir."/RD-Table.tsv" // Read in the CPF table and add new rows as needed (we need to see all rows before new columns) // check if we need to split this column // only split by two // Write the updated CPF Table 