Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_RAPStore2.php |
— | — | @@ -4,7 +4,7 @@ |
5 | 5 | * SMW SQL 2 Store for everything SMW does, but it decorates all edits to |
6 | 6 | * the store with calls to a RAP store, so it keeps in parallel a second |
7 | 7 | * store with all the semantic data. This allows for a SPARQL endpoint. |
8 | | - * |
| 8 | + * |
9 | 9 | * @todo It is not good that SMW_RAPStore2 is basically |
10 | 10 | * a copy of SMW_RAPStore. The architecture of these two stores need to be |
11 | 11 | * rethought so that code duplication can be avoided. |
— | — | @@ -41,48 +41,48 @@ |
42 | 42 | public function SMWRAPStore2() { |
43 | 43 | global $smwgRAPPath,$wgServer; |
44 | 44 | |
45 | | - |
| 45 | + |
46 | 46 | $this->modeluri = SMWExporter::expandURI($wgServer."/model"); |
47 | | - $this->baseuri = SMWExporter::expandURI($wgServer."/id"); |
| 47 | + $this->baseuri = SMWExporter::expandURI($wgServer."/id"); |
48 | 48 | } |
49 | 49 | |
50 | 50 | ///// Writing methods ///// |
51 | 51 | |
52 | 52 | function deleteSubject(Title $subject) { |
53 | | - |
| 53 | + |
54 | 54 | // Translate SMWSemanticData to a RAP Model |
55 | 55 | $rdfmodel = $this->getRAPModel(); |
56 | | - |
| 56 | + |
57 | 57 | $rapsub = new Resource(SMWExporter::expandURI($this->getURI($subject))); |
58 | 58 | $this->removeSubjectFromRAP($rdfmodel, $rapsub); |
59 | | - |
| 59 | + |
60 | 60 | return parent::deleteSubject($subject); |
61 | 61 | } |
62 | 62 | |
63 | 63 | function updateData(SMWSemanticData $data){ |
64 | 64 | // Create a local memmodel |
65 | 65 | $model = ModelFactory::getDefaultModel(); |
66 | | - |
| 66 | + |
67 | 67 | // Get DB-Model |
68 | 68 | $rdfmodel = $this->getRAPModel(); |
69 | 69 | |
70 | 70 | $ed = SMWExporter::makeExportData($data); //ExpData |
71 | | - |
| 71 | + |
72 | 72 | // Delete all we know about the subject! |
73 | 73 | $rapsub = new Resource(SMWExporter::expandURI($ed->getSubject()->getName())); |
74 | 74 | $this->removeSubjectFromRAP($rdfmodel, $rapsub); |
75 | | - |
| 75 | + |
76 | 76 | $tl = $ed->getTripleList(); // list of tenary arrays |
77 | | - |
| 77 | + |
78 | 78 | // Temporary List of all Blank Nodes in this dataobject |
79 | 79 | $blankNodes = array(); |
80 | | - |
| 80 | + |
81 | 81 | foreach ($tl as $triple) { |
82 | 82 | $s = $triple[0]->getName(); // Subject |
83 | 83 | $p = $triple[1]->getName(); // Predicate |
84 | 84 | $o = $triple[2]->getName(); // Object |
85 | | - |
86 | | - |
| 85 | + |
| 86 | + |
87 | 87 | // ------------------------------------------------------------------- |
88 | 88 | // Subject |
89 | 89 | // ------------------------------------------------------------------- |
— | — | @@ -103,14 +103,14 @@ |
104 | 104 | $rap_subj = $blankNodes[$bNodeId]; |
105 | 105 | } |
106 | 106 | } |
107 | | - |
| 107 | + |
108 | 108 | // ------------------------------------------------------------------- |
109 | 109 | // Predicate |
110 | 110 | // ------------------------------------------------------------------- |
111 | 111 | $rap_pred = new Resource(SMWExporter::expandURI($triple[1]->getName())); |
112 | | - |
| 112 | + |
113 | 113 | // ------------------------------------------------------------------- |
114 | | - // Object |
| 114 | + // Object |
115 | 115 | // ------------------------------------------------------------------- |
116 | 116 | $rap_obj = new Resource(SMWExporter::expandURI($triple[2]->getName())); |
117 | 117 | if($triple[2] instanceof SMWExpLiteral){ |
— | — | @@ -128,31 +128,31 @@ |
129 | 129 | $blankNodes[$bNodeId] = $rap_obj; |
130 | 130 | } |
131 | 131 | } |
132 | | - |
| 132 | + |
133 | 133 | // now add the new Statement |
134 | | - $statement = new Statement($rap_subj, $rap_pred, $rap_obj); |
| 134 | + $statement = new Statement($rap_subj, $rap_pred, $rap_obj); |
135 | 135 | $model->add($statement); |
136 | 136 | } |
137 | | - |
| 137 | + |
138 | 138 | // Add the mem-model to the store |
139 | 139 | $rdfmodel->addModel($model); |
140 | 140 | |
141 | | - |
| 141 | + |
142 | 142 | // Close connections |
143 | 143 | $model->close(); |
144 | 144 | $rdfmodel->close(); |
145 | 145 | $this->closeRAP(); |
146 | | - |
147 | | - |
| 146 | + |
| 147 | + |
148 | 148 | return parent::updateData($data); |
149 | 149 | } |
150 | 150 | |
151 | 151 | function changeTitle(Title $oldtitle, Title $newtitle, $pageid, $redirid=0) { |
152 | | - |
| 152 | + |
153 | 153 | // Save it in parent store now! |
154 | 154 | // We need that so we get all information correctly! |
155 | 155 | $result = parent::changeTitle($oldtitle, $newtitle, $pageid, $redirid); |
156 | | - |
| 156 | + |
157 | 157 | // Delete the old stuff |
158 | 158 | $nameOld = SMWExporter::expandURI($this->getURI($oldtitle)); |
159 | 159 | $rdfmodel = $this->getRAPModel(); |
— | — | @@ -169,7 +169,7 @@ |
170 | 170 | $oldpage->setValues($oldtitle->getDBKey(), $oldtitle->getNamespace(), $redirid); |
171 | 171 | $semdata = $this->getSemanticData($oldpage); |
172 | 172 | $this->updateData($semdata,false); |
173 | | - |
| 173 | + |
174 | 174 | return $result; |
175 | 175 | } |
176 | 176 | |
— | — | @@ -199,7 +199,7 @@ |
200 | 200 | } |
201 | 201 | $this->reportProgress("Checking RAP model...\n",$verbose); |
202 | 202 | if ($rdfstore->modelExists($this->modeluri)) { |
203 | | - $this->reportProgress("RAP model exiists.\n",$verbose); |
| 203 | + $this->reportProgress("RAP model exiists.\n",$verbose); |
204 | 204 | } else { |
205 | 205 | $this->reportProgress("Creating RAP model...\n",$verbose); |
206 | 206 | $rdfstore->getNewModel($this->modeluri, $this->baseuri); |
— | — | @@ -230,7 +230,7 @@ |
231 | 231 | $this->rapstore = ModelFactory::getDbStore('MySQL', $smwgRapDBserver, $smwgRapDBname, $smwgRapDBuser, $smwgRapDBpassword); |
232 | 232 | return $this->rapstore; |
233 | 233 | } |
234 | | - |
| 234 | + |
235 | 235 | /** |
236 | 236 | * Returns the actual model where all the triples are saved. |
237 | 237 | */ |
— | — | @@ -238,7 +238,7 @@ |
239 | 239 | $rapstore = $this->getRAPStore(); |
240 | 240 | return $rapstore->getModel($this->modeluri); |
241 | 241 | } |
242 | | - |
| 242 | + |
243 | 243 | /** |
244 | 244 | * Closes the connection to the RAP DB. As of now, this is disabled since it |
245 | 245 | * seems to close the connection to the MW DB as well (probably, because it |
— | — | @@ -249,27 +249,10 @@ |
250 | 250 | //$this->rapstore->close(); |
251 | 251 | } |
252 | 252 | |
253 | | - /** |
254 | | - * Print some output to indicate progress. The output message is given by |
255 | | - * $msg, while $verbose indicates whether or not output is desired at all. |
256 | | - * Copied from SMW_SQLStore. |
257 | | - */ |
258 | | - protected function reportProgress($msg, $verbose) { |
259 | | - if (!$verbose) { |
260 | | - return; |
261 | | - } |
262 | | - if (ob_get_level() == 0) { // be sure to have some buffer, otherwise some PHPs complain |
263 | | - ob_start(); |
264 | | - } |
265 | | - print $msg; |
266 | | - ob_flush(); |
267 | | - flush(); |
268 | | - } |
269 | | - |
270 | 253 | ///// Additional helpers |
271 | 254 | /** |
272 | 255 | * Deletes all relations for the given subject from RAP. |
273 | | - * This especially also handles n-ary relations recursevly as we would lose them |
| 256 | + * This especially also handles n-ary relations recursevly as we would lose them |
274 | 257 | **/ |
275 | 258 | protected function removeSubjectFromRAP($rdfmodel, Resource $subject){ |
276 | 259 | $oldmodel = $rdfmodel->find($subject, null, null); |
— | — | @@ -277,21 +260,21 @@ |
278 | 261 | $i->moveFirst(); |
279 | 262 | while ($i->current() != null) { |
280 | 263 | $stmt = $i->current(); |
281 | | - |
| 264 | + |
282 | 265 | $rdfmodel->remove($stmt); |
283 | | - |
| 266 | + |
284 | 267 | $obj = $stmt->object(); |
285 | 268 | if($obj instanceof BlankNode){ |
286 | 269 | // It's a blank node in the object, this means a n-ary relation has been saved |
287 | 270 | // So delete everything for this blank node as well! |
288 | 271 | $this->removeSubjectFromRAP($rdfmodel, $obj); |
289 | 272 | } |
290 | | - |
| 273 | + |
291 | 274 | $i->next(); |
292 | 275 | } |
293 | 276 | // TODO Delete More Stuff, if we save more stuff |
294 | 277 | } |
295 | | - |
| 278 | + |
296 | 279 | /** |
297 | 280 | * Having a title of a page, what is the URI that is described by that page? |
298 | 281 | * |
— | — | @@ -302,12 +285,12 @@ |
303 | 286 | if($title instanceof Title){ |
304 | 287 | $dv = SMWDataValueFactory::newTypeIDValue('_wpg'); |
305 | 288 | $dv->setTitle($title); |
306 | | - $exp = $dv->getExportData(); |
307 | | - $uri = $exp->getSubject()->getName(); |
| 289 | + $exp = $dv->getExportData(); |
| 290 | + $uri = $exp->getSubject()->getName(); |
308 | 291 | }else{ |
309 | 292 | // There could be other types as well that we do NOT handle here |
310 | 293 | } |
311 | | - |
| 294 | + |
312 | 295 | return $uri; // still requires expandURI() |
313 | 296 | } |
314 | 297 | } |