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 | // load library setup
|
---|
22 | require_once( '../sample_config.php');
|
---|
23 | define( 'RDFINT', getenv( 'PHP_LIBROOT_RDFINT'));
|
---|
24 | require_once( RDFINT.'/rdfa.php');
|
---|
25 |
|
---|
26 | $debugger = \fDebug::getInstance();
|
---|
27 | const debugcontext = "RDFA_SAMPLE";
|
---|
28 |
|
---|
29 |
|
---|
30 | $turtlefile = "sample.ttl";
|
---|
31 |
|
---|
32 | // ---------------------------------------------------------------
|
---|
33 |
|
---|
34 | $aNamespace = array( 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
|
---|
35 | 'foaf' => 'http://xmlns.com/foaf/0.1/',
|
---|
36 | 'resource' => 'http://data.uduvudu.org/resource/');
|
---|
37 |
|
---|
38 | // parse file
|
---|
39 | $debugger->sendMessage( "Parsing file: $turtlefile", debugcontext);
|
---|
40 | $rdfaData = new \rdfa\Data();
|
---|
41 |
|
---|
42 | // setup namespace mappings
|
---|
43 | foreach ( $aNamespace as $prefix => $uriNamespace) {
|
---|
44 | $rdfaData->setMapping( $prefix, $uriNamespace);
|
---|
45 | }
|
---|
46 | $rdfaData->parse( $turtlefile);
|
---|
47 |
|
---|
48 | // start using the data
|
---|
49 | $aUriPersons = $rdfaData->getSubjects( 'rdf:type', 'foaf:Person');
|
---|
50 | $debugmessage = count( $aUriPersons) . " persons found";
|
---|
51 | foreach ($aUriPersons as $uriPerson) {
|
---|
52 | $debugmessage .= "\n$uriPerson";
|
---|
53 | }
|
---|
54 | $debugger->sendMessage( $debugmessage, debugcontext);
|
---|
55 |
|
---|
56 |
|
---|
57 | foreach ($aUriPersons as $uriPerson) {
|
---|
58 |
|
---|
59 | $debugger->sendMessage( "Retrieving name of person", debugcontext);
|
---|
60 | $litName = $rdfaData->_getFirstValue( $uriPerson, 'foaf:name');
|
---|
61 |
|
---|
62 | // get triples of work blank node
|
---|
63 | $debugger->sendMessage( "Filter for data of work", debugcontext);
|
---|
64 | $aUriWork = $rdfaData->getValues( $uriPerson, 'foaf:work');
|
---|
65 |
|
---|
66 | $debugger->sendMessage( "Retrieving city of work", debugcontext);
|
---|
67 | $litCity = $rdfaData->_getFirstValue( $aUriWork[ 0], 'foaf:city');
|
---|
68 |
|
---|
69 | $debugger->sendMessage( "Data for person complete: $uriPerson\n".
|
---|
70 | "Name: $litName\n".
|
---|
71 | "City: $litCity", debugcontext);
|
---|
72 | }
|
---|
73 |
|
---|
74 | ?>
|
---|