function _handleData($data) { global $bNodeCounter; global $propertyMapping; global $objectProperties; global $skippedProperties; global $formProperties; global $relations; #var_dump($data);exit; $result = array(); $ntriples = array(); foreach ($data as $i => $itemSpec) { if (!is_array($itemSpec)) { $result['next'] = $itemSpec; continue; } foreach ($itemSpec as $key => $value) { $s = URI_BASE . $i; // Add a (short) label _createTriple($s, 'http://www.w3.org/2000/01/rdf-schema#label', $i); #if ($key !== 'title') { # continue; #} // Skip iff defined in skip array if (in_array($key, $skippedProperties)) { continue; } // Handle special Properties _handleProperty($key, $value); // Special case: form if ($key === 'form') { $p = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'; $o = $formProperties[$value]; $ntriples[] = _createTriple($s, $p, $o, true); continue; } $p = null; if (isset($propertyMapping[$key])) { $p = $propertyMapping[$key]; } else { $p = VOCAB_BASE . urlencode($key); } // Skip emtpy values if ($value === '') { continue; } $o = null; if (is_string($value)) { $o = $value; if (in_array($key, $objectProperties)) { $o = URI_BASE . urlencode($o); $ntriples[] = _createTriple($s, $p, $o, true); } else { $ntriples[] = _createTriple($s, $p, $o); } } else { // Special case: relationships if ($key === 'relationships') { foreach ($value as $oItemSpec) { $rel = strtolower(trim($oItemSpec['relationship'])); $rel = str_replace(':', '', $rel); $p = VOCAB_BASE . ucfirst(urlencode($rel)); $relations[$rel] = $p; $o = null; if ($oItemSpec['link'] !== '') { $o = str_replace(' ', '+', $oItemSpec['link']); } else { $o = VOCAB_BASE . urlencode($oItemSpec['relation']); } $ntriples[] = _createTriple($s, $p, $o, true); $ntriples[] = _createTriple($o, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $p, true); $ntriples[] = _createTriple($o, 'http://www.w3.org/2000/01/rdf-schema#label', $oItemSpec['relation']); } continue; } foreach ($value as $oItemSpec) { if (count($oItemSpec) === 1) { foreach ($oItemSpec as $itemKey => $itemValue) { $p = VOCAB_BASE . $itemKey; if (in_array($itemKey, $objectProperties)) { $o = URI_BASE . urlencode($itemValue); $ntriples[] = _createTriple($s, $p, $o, true); } else { $ntriples[] = _createTriple($s, $p, $itemValue); } } } else { $bNodeID = '_:bnode' . $bNodeCounter++; $ntriples[] = _createTriple($s, $p, $bNodeID, false, false, true); foreach ($oItemSpec as $itemKey => $itemValue) { $ntriples[] = $bNodeID . ' <' . $itemKey . '> "' . $itemValue . '" . ' . PHP_EOL; $ntriples[] = _createTriple($bNodeID, $itemKey, $itemValue, false, true, false); } } } } } } $result['ntriples'] = $ntriples; return $result; }
function _handleData($data) { global $organizations; global $documentSubTypes; global $persons; global $events; global $documentTitles; $result = array(); $ntriples = array(); foreach ($data as $i => $itemSpec) { if (!is_array($itemSpec)) { $result['next'] = $itemSpec; continue; } $s = URI_BASE . 'document/' . $i; foreach ($itemSpec as $key => $value) { if (is_string($value)) { $value = trim($value); } if ($value === '') { continue; } if ($key === 'doc_id') { $ntriples[] = _createTriple($s, 'http://prelex.publicdata.eu/ontology/doc_id', $value); } else { if ($key === 'com_number') { $ntriples[] = _createTriple($s, 'http://prelex.publicdata.eu/ontology/com_number', $value); } else { if ($key === 'prelex_perma_url') { $ntriples[] = _createTriple($s, 'http://prelex.publicdata.eu/ontology/perma_url', $value, true); } else { if ($key === 'eurlex_perma_url') { $ntriples[] = _createTriple($s, 'http://eur-lex.publicdata.eu/ontology/perma_url', $value, true); } else { if ($key === 'dg_responsible') { $orgUri = URI_BASE . 'organization/' . urlencode($value); $organizations[$orgUri] = $value; $ntriples[] = _createTriple($s, 'http://prelex.publicdata.eu/ontology/dg_responsible', $orgUri, true); } else { if ($key === 'legal_basis') { // value may be an array if (is_array($value)) { foreach ($value as $v) { $ntriples[] = _createTriple($s, 'http://prelex.publicdata.eu/ontology/legal_basis', $v['legal_basis']); } } else { $ntriples[] = _createTriple($s, 'http://prelex.publicdata.eu/ontology/legal_basis', $value); } } else { if ($key === 'prelex_procedure') { $ntriples[] = _createTriple($s, 'http://prelex.publicdata.eu/ontology/prelex_procedure', $value); } else { if ($key === 'title') { $documentTitles[$i] = $value; $ntriples[] = _createTriple($s, 'http://purl.org/dc/terms/title', $value); } else { if ($key === 'legislative_type') { $typeURI = URI_BASE . 'legislativeType/' . urlencode($value); $documentSubTypes[$typeURI] = $value; $ntriples[] = _createTriple($s, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $typeURI, true); } else { if ($key === 'commissioner') { $personUri = URI_BASE . 'person/' . urlencode($value); $persons[$personUri] = $value; $ntriples[] = _createTriple($s, 'http://prelex.publicdata.eu/ontology/commissioner', $personUri, true); } else { if ($key === 'adoption_commission') { $ntriples[] = _createTriple($s, 'http://prelex.publicdata.eu/ontology/adoption_commission', $value, false, false, false, 'http://www.w3.org/2001/XMLSchema#date'); } else { if ($key === 'adoption_council') { $ntriples[] = _createTriple($s, 'http://prelex.publicdata.eu/ontology/adoption_council', $value, false, false, false, 'http://www.w3.org/2001/XMLSchema#date'); } else { if ($key === 'events') { // events is an array foreach ($value as $event) { $eventURI = URI_BASE . 'event/' . $event['event_id']; $events[$eventURI] = $event; $ntriples[] = _createTriple($s, 'http://prelex.publicdata.eu/ontology/event', $eventURI, true); } } else { if ($key === 'directory_codes') { // directory_codes is an array foreach ($value as $dirCode) { $ntriples[] = _createTriple($s, 'http://prelex.publicdata.eu/ontology/directory_code', $dirCode['directory_code']); } } } } } } } } } } } } } } } } } $result['ntriples'] = $ntriples; return $result; }