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 | $searchedName = 'Adrian Gschwend';
|
---|
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 | $aQueryPerson = array( 'rdf:type' => 'foaf:Person',
|
---|
39 | 'foaf:name' => $searchedName);
|
---|
40 |
|
---|
41 | $aTemplatePerson = array( 'name' => 'foaf:name',
|
---|
42 | 'uri_work' => 'foaf:work');
|
---|
43 | $aTemplateWorkAdress = array( 'city' => 'foaf:city');
|
---|
44 |
|
---|
45 | // parse file
|
---|
46 | $debugger->sendMessage( "Parsing file: $turtlefile", debugcontext);
|
---|
47 | $rdfaData = new \rdfa\Data();
|
---|
48 |
|
---|
49 | // setup namespace mappings
|
---|
50 | foreach ( $aNamespace as $prefix => $uriNamespace) {
|
---|
51 | $rdfaData->setMapping( $prefix, $uriNamespace);
|
---|
52 | }
|
---|
53 | $rdfaData->parse( $turtlefile);
|
---|
54 |
|
---|
55 | // start using the data
|
---|
56 | $aPersons = $rdfaData->query( $aQueryPerson, $aTemplatePerson);
|
---|
57 | $debugmessage = count( $aPersons) . " persons with searched name: $searchedName ";
|
---|
58 | foreach ($aPersons as $person) {
|
---|
59 | $debugmessage .= "\n{$person->getSubject()}";
|
---|
60 | }
|
---|
61 | $debugger->sendMessage( $debugmessage, debugcontext);
|
---|
62 |
|
---|
63 | foreach ($aPersons as $person) {
|
---|
64 |
|
---|
65 | $litName = $person->name;
|
---|
66 |
|
---|
67 | // get triples of work blank node
|
---|
68 | $debugger->sendMessage( "Filter for data of work {$person->uri_work}", debugcontext);
|
---|
69 | $work = $rdfaData->getProjection( $person->uri_work, $aTemplateWorkAdress);
|
---|
70 |
|
---|
71 | $debugger->sendMessage( "Retrieving city of work", debugcontext);
|
---|
72 | $litCity = $work->city;
|
---|
73 |
|
---|
74 | $debugger->sendMessage( "Data for person complete: {$person->getSubject()}\n".
|
---|
75 | "Name: $litName\n".
|
---|
76 | "City: $litCity", debugcontext);
|
---|
77 | }
|
---|