source: php/trunk/classes/rdfa_SparqlQuery.php@ 28

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

rdfint

  • change note sections to use the doxygen note command
  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
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
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.
26 * <br>This is a library specific extension to the RDF API and RDFa API.
27 * \author Christian Langanke
28 * \author Adrian Gschwend
29 * \date 2011
30 */
31
32class SparqlQuery {
33
34 /**
35 * Version of the class
36 */
37 const version = '1.0.0';
38 /**
39 * Name of the fDebug context
40 */
41 const debugcontext = 'RDFA_SPARQLQUERY';
42
43 private $debugger;
44 private $endpoint;
45 private $statement;
46
47 // ---------------------------------------
48
49 /**
50 * Creates a SPARQL qery class instance.
51 *
52 * \param endpoint instance of SparqlEndpoint holding the endpoint configuration
53 * \param statement SPARQL CONSTRUCT query statement to execute.
54 *
55 * \note To effectively execute the query, invoke the method
56 * - rdfa::SparqlQuery::run()
57 */
58 public function __construct( $endpoint, $statement) {
59
60 // setup debugger
61 $this->debugger = \fDebug::getInstance();
62
63 // check for required class
64 if ((!is_object( $endpoint)) ||
65 ('\\' . get_class( $endpoint) != '\\rdfa\\SparqlEndpoint'))
66 throw new \Exception( get_class().'::__construct: Parameter $endpoint is not object of class \rdfa\SparqlEndpoint.');
67
68 // check for statement, may not be empty
69 if (strlen( $statement) < 1)
70 throw new \Exception( get_class().'::__construct: Parameter $statement is empty.');
71
72 // initialize instance vars
73 $this->endpoint = $endpoint;
74 $this->statement = $statement;
75
76 $debugmessage = "Creating SPARQL query object\n" .
77 "SPARQL query statement: \n" .
78 $this->getStatement();
79 $this->debugger->sendMessage( $debugmessage, self::debugcontext);
80
81 } // public function __construct
82
83 // ---------------------------------------
84
85 /**
86 * Gets the SPARQL query statementof the object.
87 */
88
89 public function getStatement() {
90 return $this->statement;
91 }
92
93 // ---------------------------------------
94
95 /**
96 * Runs the SPARQL query of the object.
97 *
98 * Returns indexed RDF data.
99 */
100
101 public function run() {
102 $store = \ARC2::getRemoteStore( $this->endpoint->getConfigurationValues());
103
104 $debugmessage = "Executing SPARQL query\n" .
105 "SPARQL query statement: \n" .
106 $this->getStatement();
107 $this->debugger->sendMessage( $debugmessage, self::debugcontext);
108 return $store->query( $this->statement, 'raw');
109 }
110
111} // class SparqlEndpoint
112
113?>
Note: See TracBrowser for help on using the repository browser.