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

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

rdfint

  • initial version
  • Property svn:eol-style set to native
File size: 4.6 KB
Line 
1<?php
2
3/* RDFInt - 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 specified in the RDF API and RDFa 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 * Note: a projection is to be created by the following methods only:
52 * - rdfa::Data::getProjection()
53 * - rdfa::Data::getProjections()
54 * - rdfa::Data::query()
55 *
56 * \param rdfaData instance of Reader holding the RDF data
57 * \param subject subject of the projection
58 * \param template template array specifying the members to be created from data linked to the subject
59 */
60 public function __construct( $rdfaData, $subject, $template) {
61
62 // setup debugger
63 $this->debugger = \fDebug::getInstance();
64
65 // check for required class
66 if ((!is_object( $rdfaData)) ||
67 ('\\' . get_class( $rdfaData) != '\\rdfa\\Data'))
68 throw new \Exception( 'Invalid Parameter: $rdfdata is not object of class \rdfa\Data.');
69
70 // initialize
71 $this->rdfaData = $rdfaData;
72 $this->subject = $subject;
73
74 $debugmessage = "Creating projection for subject: $subject";
75
76 // create public members from template
77 if (($template != Null) && (is_array( $template))) {
78 $debugmessage .= "\nApplying template:\n";
79 foreach ( $template as $key => $uri) {
80 $value = $this->get( $uri);
81 if ($value != false) {
82 $this->$key = $value;
83 $debugmessage .= "$key=$value\n";
84 } else {
85 $debugmessage .= "### not found: $key\n";
86 }
87 }
88 }
89
90 $this->debugger->sendMessage( $debugmessage,
91 self::debugcontext);
92
93 } // public function __construct
94
95 // --------------------------------------------------------
96
97 /**
98 * Gets properties of the subject of the projection.
99 * Returns a list of properties.
100 */
101 public function getProperties() {
102 return $this->rdfaData->getProperties( $this->subject);
103 } // public function getProperties
104
105 // --------------------------------------------------------
106
107 /**
108 * Gets unique properties of the subject of the projection.
109 *
110 * Ths method returns an associative list of properties => values.
111 * All non-unique properties are NOT returned !
112 *
113 * <strong>NOTE: This method is a library specific extension to the RDF API and RDFa API.</strong>
114 *
115 */
116 public function getUniqueProperties() {
117 return $this->rdfaData->getUniqueProperties( $this->subject);
118 } // public function getUniqueProperties
119
120 // --------------------------------------------------------
121
122 /**
123 * Gets the subject of of the subject of the projection.
124 */
125 public function getSubject() {
126 return $this->subject;
127 } // public function getSubject
128
129 // --------------------------------------------------------
130
131 /**
132 * Gets the first available value of a given property.
133 *
134 * \param property property to retrieve the first value of
135 */
136
137 public function get( $property) {
138 return $this->rdfaData->getFirstValue( $this->subject, $property);
139 } // public function get
140
141 // --------------------------------------------------------
142
143 /**
144 * Gets a list of all available values of a given property.
145 *
146 * \param property property to retrieve all values of
147 */
148
149 public function getAll( $property) {
150 return $this->rdfaData->getValues( $this->subject, $property);
151 } // public function getAll
152
153} // class Projection
154
155?>
Note: See TracBrowser for help on using the repository browser.