| 1 | <?PHP
|
|---|
| 2 |
|
|---|
| 3 | /* RDFInt.php - RDF Interfaces for PHP
|
|---|
| 4 | * Copyright 2011 netlabs.org
|
|---|
| 5 | * Author: Christian Langanke, Adrian Gschwend
|
|---|
| 6 | *
|
|---|
| 7 | * Licensed under the Apache License, Version 2.0 (the "License");
|
|---|
| 8 | * you may not use this file except in compliance with the License.
|
|---|
| 9 | * You may obtain a copy of the License at
|
|---|
| 10 | *
|
|---|
| 11 | * http://www.apache.org/licenses/LICENSE-2.0
|
|---|
| 12 | *
|
|---|
| 13 | * Unless required by applicable law or agreed to in writing, software
|
|---|
| 14 | * distributed under the License is distributed on an "AS IS" BASIS,
|
|---|
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|---|
| 16 | * See the License for the specific language governing permissions and
|
|---|
| 17 | * limitations under the License.
|
|---|
| 18 | */
|
|---|
| 19 |
|
|---|
| 20 | // load library setup
|
|---|
| 21 | require_once( '../sample_config.php');
|
|---|
| 22 | define( 'RDFINT', getenv( 'PHP_LIBROOT_RDFINT'));
|
|---|
| 23 | require_once( RDFINT.'/rdfa.php');
|
|---|
| 24 |
|
|---|
| 25 | $debugger = \fDebug::getInstance();
|
|---|
| 26 | const debugcontext = "RDFA_SAMPLE";
|
|---|
| 27 |
|
|---|
| 28 | $turtlefile = "sample.ttl";
|
|---|
| 29 |
|
|---|
| 30 | // ---------------------------------------------------------------
|
|---|
| 31 |
|
|---|
| 32 | $aNamespace = array( 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
|
|---|
| 33 | 'foaf' => 'http://xmlns.com/foaf/0.1/',
|
|---|
| 34 | 'resource' => 'http://data.uduvudu.org/resource/');
|
|---|
| 35 |
|
|---|
| 36 | $aTemplatePerson = array( 'name' => 'foaf:name',
|
|---|
| 37 | 'uri_work' => 'foaf:work');
|
|---|
| 38 | $aTemplateWorkAdress = array( 'city' => 'foaf:city');
|
|---|
| 39 |
|
|---|
| 40 | // parse file
|
|---|
| 41 | $debugger->sendMessage( "Parsing file: $turtlefile", debugcontext);
|
|---|
| 42 | $rdfaData = new \rdfa\Data();
|
|---|
| 43 |
|
|---|
| 44 | // setup namespace mappings
|
|---|
| 45 | foreach ( $aNamespace as $prefix => $uriNamespace) {
|
|---|
| 46 | $rdfaData->setMapping( $prefix, $uriNamespace);
|
|---|
| 47 | }
|
|---|
| 48 | $rdfaData->parse( $turtlefile);
|
|---|
| 49 |
|
|---|
| 50 | // start using the data
|
|---|
| 51 | $aPersons = $rdfaData->getProjections( 'rdf:type', 'foaf:Person', $aTemplatePerson);
|
|---|
| 52 | $debugmessage = count( $aPersons) . " persons found";
|
|---|
| 53 | foreach ($aPersons as $person) {
|
|---|
| 54 | $debugmessage .= "\n{$person->getSubject()}";
|
|---|
| 55 | }
|
|---|
| 56 | $debugger->sendMessage( $debugmessage, debugcontext);
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 | foreach ($aPersons as $person) {
|
|---|
| 60 |
|
|---|
| 61 | $debugger->sendMessage( "Retrieving name of person", debugcontext);
|
|---|
| 62 | $litName = $person->name;
|
|---|
| 63 |
|
|---|
| 64 | // get triples of work blank node
|
|---|
| 65 | $debugger->sendMessage( "Filter for data of work", debugcontext);
|
|---|
| 66 | $work = $rdfaData->getProjection( $person->uri_work, $aTemplateWorkAdress);
|
|---|
| 67 |
|
|---|
| 68 | $debugger->sendMessage( "Retrieving city of work", debugcontext);
|
|---|
| 69 | $litCity = $work->city;
|
|---|
| 70 |
|
|---|
| 71 | $debugger->sendMessage( "Data for person complete: {$person->getSubject()}\n".
|
|---|
| 72 | "Name: $litName\n".
|
|---|
| 73 | "City: $litCity", debugcontext);
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | ?>
|
|---|