source: php/trunk/classes/rdfa_SparqlQuery.php

Last change on this file was 72, checked in by cla, 14 years ago

rdfint

  • implemented core wrapper class for external libraries (current support: only ARC)
  • modified classes to adapt to new core class
    • SparqlQuery::run
    • Data:parse
    • Data:_serialize
  • added samples rdfa_serialize and rdfa_serialize
  • Property svn:eol-style set to native
File size: 3.5 KB
RevLine 
[2]1<?php
2
[3]3/* RDFInt.php - RDF Interfaces for PHP
[2]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
20namespace rdfa;
21
22/**
23 * \class SparqlQuery
24 * \brief This class implements a class for executing SPARQL queries agains an endpoint
25 * by the Data::parse method.
[17]26 * <br>This is a library specific extension to the RDF API and RDFa API.
[30]27 * \note For further information see the section
28 * \htmllink{page_w3cspecs.html,W3C Specifications Overview and Library Compatibility}
[2]29 * \author Christian Langanke
30 * \author Adrian Gschwend
31 * \date 2011
32 */
33
34class SparqlQuery {
35
36 /**
37 * Version of the class
38 */
39 const version = '1.0.0';
40 /**
41 * Name of the fDebug context
42 */
43 const debugcontext = 'RDFA_SPARQLQUERY';
44
45 private $debugger;
46 private $endpoint;
47 private $statement;
48
49 // ---------------------------------------
50
51 /**
52 * Creates a SPARQL qery class instance.
53 *
54 * \param endpoint instance of SparqlEndpoint holding the endpoint configuration
55 * \param statement SPARQL CONSTRUCT query statement to execute.
56 *
[29]57 * \exception Exception The parameter endpoint is not of object rdfa::SparqlEndpoint
58 *
[28]59 * \note To effectively execute the query, invoke the method
[2]60 * - rdfa::SparqlQuery::run()
61 */
62 public function __construct( $endpoint, $statement) {
63
64 // setup debugger
65 $this->debugger = \fDebug::getInstance();
66
67 // check for required class
68 if ((!is_object( $endpoint)) ||
69 ('\\' . get_class( $endpoint) != '\\rdfa\\SparqlEndpoint'))
70 throw new \Exception( get_class().'::__construct: Parameter $endpoint is not object of class \rdfa\SparqlEndpoint.');
71
72 // check for statement, may not be empty
73 if (strlen( $statement) < 1)
74 throw new \Exception( get_class().'::__construct: Parameter $statement is empty.');
75
76 // initialize instance vars
77 $this->endpoint = $endpoint;
78 $this->statement = $statement;
79
80 $debugmessage = "Creating SPARQL query object\n" .
81 "SPARQL query statement: \n" .
82 $this->getStatement();
83 $this->debugger->sendMessage( $debugmessage, self::debugcontext);
84
85 } // public function __construct
86
87 // ---------------------------------------
88
89 /**
90 * Gets the SPARQL query statementof the object.
[29]91 *
92 * \retval string SPARQL statement
[2]93 */
94
95 public function getStatement() {
96 return $this->statement;
97 }
98
99 // ---------------------------------------
100
101 /**
102 * Runs the SPARQL query of the object.
103 *
[29]104 * \retval array indexed RDF data in internal format
[2]105 */
106
107 public function run() {
108
109 $debugmessage = "Executing SPARQL query\n" .
110 "SPARQL query statement: \n" .
111 $this->getStatement();
112 $this->debugger->sendMessage( $debugmessage, self::debugcontext);
[68]113
[72]114 $core = new \rdfint_core\Core();
115 return $core->runQuery( $this->endpoint->getConfigurationValues(), $this->statement);
[2]116 }
117
118} // class SparqlEndpoint
119
120?>
Note: See TracBrowser for help on using the repository browser.