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

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

rdfint

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