source: php/trunk/classes/rdfa_Projection.php@ 29

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

rdfint

  • all classes: added missing comments on return value
  • Projection::construct and rdfa::SparqlQuery: added missing comment on exceptions
  • Data::parse
    • added note on merge feature
    • added code to return boolean
  • Property svn:eol-style set to native
File size: 5.8 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 Projection
24 * \brief This class implements a projection as described in the RDF API and RDFa API specs of W3C.
25 * \details A projection relates to a specific subject of RDF data parsed by an instance of
26 * the rdfa::Data class and is to be created by the projection API methods this class only.
27 * \author Christian Langanke
28 * \author Adrian Gschwend
29 * \date 2011
30 */
31class Projection {
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_PROJECTION';
41
42 private $debugger;
43 private $rdfaData;
44 private $subject;
45
46 // ---------------------------------------
47
48 /**
49 * Creates a Projection instance from a Data instance, reflecting a given subject in the triple data.
50 *
51 * \param rdfaData instance of rdfa::Data holding the graph of the subject
52 * \param subject Subject of the projection
53 * \param template Associative array( URI/CURIE => membername) as a template to be applied to the projection object
54 *
55 * \exception Exception The parameter rdfaData is not of object rdfa::Data
56 *
57 * \note A projection is to be created by the following methods only:
58 * - rdfa::Data::getProjection()
59 * - rdfa::Data::getProjections()
60 * - rdfa::Data::query()
61 */
62 public function __construct( $rdfaData, $subject, $template) {
63
64 // setup debugger
65 $this->debugger = \fDebug::getInstance();
66
67 // check for required class
68 if ((!is_object( $rdfaData)) ||
69 ('\\' . get_class( $rdfaData) != '\\rdfa\\Data'))
70 throw new \Exception( 'Invalid Parameter: $rdfdata is not object of class \rdfa\Data.');
71
72 // initialize
73 $this->rdfaData = $rdfaData;
74 $this->subject = $subject;
75
76 $debugmessage = "Creating projection for subject: $subject";
77
78 // create public members from template
79 if (($template != Null) && (is_array( $template))) {
80 $debugmessage .= "\nApplying template:\n";
81 foreach ( $template as $key => $uri) {
82 $value = $this->get( $uri);
83 if ($value != false) {
84 $this->$key = $value;
85 $debugmessage .= "$key=$value\n";
86 } else {
87 $debugmessage .= "### not found: $key\n";
88 }
89 }
90 }
91
92 $this->debugger->sendMessage( $debugmessage,
93 self::debugcontext);
94
95 } // public function __construct
96
97 // --------------------------------------------------------
98
99 /**
100 * Gets properties of the subject of the projection.
101 *
102 * \retval array List of properties
103 */
104 public function getProperties() {
105 return $this->rdfaData->getProperties( $this->subject);
106 } // public function getProperties
107
108 // --------------------------------------------------------
109
110 /**
111 * Gets an associative list of unique properties of the projection
112 * with their values.
113 *
114 * \retval array Associative list of unqique properties and their values
115 *
116 * \note
117 * - All non-unique properties are \c NOT returned !
118 * - This method is a library specific extension to the RDF API and RDFa API
119 */
120 public function _getUniqueProperties() {
121 return $this->rdfaData->_getUniqueProperties( $this->subject);
122 } // public function _getUniqueProperties
123
124 // --------------------------------------------------------
125
126 /**
127 * Gets the subject of of the subject of the projection.
128 *
129 * \retval string Subject of the property
130 */
131 public function getSubject() {
132 return $this->subject;
133 } // public function getSubject
134
135 // --------------------------------------------------------
136
137 /**
138 * Gets the first available value of a given property.
139 *
140 * \param property Property to retrieve the first value of#
141 * \retval string First value of the property
142 */
143
144 public function get( $property) {
145 return $this->rdfaData->_getFirstValue( $this->subject, $property);
146 } // public function get
147
148 // --------------------------------------------------------
149
150 /**
151 * Gets a list of all available values of a given property.
152 *
153 * \param property Property to retrieve all values of
154 */
155
156 public function getAll( $property) {
157 return $this->rdfaData->getValues( $this->subject, $property);
158 } // public function getAll
159
160 // --------------------------------------------------------
161
162 /**
163 * Sets a property value.
164 *
165 * \param property Property to be added
166 * \param value Value to be set for the property
167 * \param type The type of the value, either 'uri', 'literal' or 'bnode'
168 * (case-insensitive). Specifying the first character is sufficient.
169 * If not specified, strings starting with 'http://' are taken as a URI,
170 * otherwise as a literal
171 * \retval rdfa::Projection Success
172 * \retval boolean false: invalid value type specified
173 *
174 * \see rdfa::Data::setValue
175 *
176 * \note
177 * - This method is a library specific extension to the RDFa API
178 * - The parameter type is a library specific extension to the RDF API
179 */
180
181 public function set( $property, $value, $type = NULL) {
182
183 // insert code here
184 }
185
186} // class Projection
187
188?>
Note: See TracBrowser for help on using the repository browser.