| 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 |
|
|---|
| 33 | $aNamespace = array( 'dbo' => 'http://dbpedia.org/ontology/',
|
|---|
| 34 | 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
|
|---|
| 35 | 'dcterms' => 'http://purl.org/dc/terms/'
|
|---|
| 36 | );
|
|---|
| 37 |
|
|---|
| 38 | // setup data RDF object
|
|---|
| 39 | $rdfaData = new \rdfa\Data();
|
|---|
| 40 |
|
|---|
| 41 | // setup namespace mappings
|
|---|
| 42 | foreach ( $aNamespace as $prefix => $uriNamespace) {
|
|---|
| 43 | $rdfaData->setMapping( $prefix, $uriNamespace);
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | $uriCityToSearch = 'http://dbpedia.org/resource/Biel/Bienne';
|
|---|
| 48 |
|
|---|
| 49 | $config = array(
|
|---|
| 50 | 'remote_store_endpoint' => 'http://dbpedia.org/sparql',
|
|---|
| 51 | 'reader_timeout' => 30
|
|---|
| 52 | );
|
|---|
| 53 |
|
|---|
| 54 | $statement = '
|
|---|
| 55 | PREFIX dbo: <http://dbpedia.org/ontology/>
|
|---|
| 56 | PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|---|
| 57 | PREFIX dcterms: <http://purl.org/dc/terms/>
|
|---|
| 58 |
|
|---|
| 59 | CONSTRUCT
|
|---|
| 60 | {
|
|---|
| 61 | ?s rdfs:label ?city_name .
|
|---|
| 62 | }
|
|---|
| 63 | WHERE {
|
|---|
| 64 | ?s dcterms:subject <http://dbpedia.org/resource/Category:Cities_in_Switzerland> .
|
|---|
| 65 | ?s rdfs:label ?city_name FILTER (LANG(?city_name) = "en")
|
|---|
| 66 | }
|
|---|
| 67 | ';
|
|---|
| 68 |
|
|---|
| 69 | // create endpoint configuration object
|
|---|
| 70 | $endpoint = new \rdfa\SparqlEndpoint( $config);
|
|---|
| 71 |
|
|---|
| 72 | // create SPARQL query object
|
|---|
| 73 | $query = new \rdfa\SparqlQuery( $endpoint, $statement);
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 | // test sparql query directly
|
|---|
| 77 | $data = $query->run();
|
|---|
| 78 |
|
|---|
| 79 | // let the parse method execute the query to
|
|---|
| 80 | $result = $rdfaData->parse( $query);
|
|---|
| 81 |
|
|---|
| 82 | // show items found
|
|---|
| 83 | $aSubject = $rdfaData->getSubjects();
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 | ?>
|
|---|