Mercurial > hg > svcore
comparison rdf/RDFTransformFactory.cpp @ 730:27c861cce97b dataquay
Further fixes for Dataquay compatibility
author | Chris Cannam |
---|---|
date | Mon, 21 May 2012 14:33:35 +0100 |
parents | 11289d40a57a |
children | e802e550a1f2 |
comparison
equal
deleted
inserted
replaced
729:11289d40a57a | 730:27c861cce97b |
---|---|
122 m_isRDF(false) | 122 m_isRDF(false) |
123 { | 123 { |
124 //!!! retrieve data if remote... then | 124 //!!! retrieve data if remote... then |
125 m_store->addPrefix("vamp", Uri("http://purl.org/ontology/vamp/")); | 125 m_store->addPrefix("vamp", Uri("http://purl.org/ontology/vamp/")); |
126 try { | 126 try { |
127 m_store->import(QUrl::fromLocalFile(url), BasicStore::ImportIgnoreDuplicates); | 127 QUrl qurl; |
128 if (url.startsWith("file:")) { | |
129 qurl = QUrl(url); | |
130 } else { | |
131 qurl = QUrl::fromLocalFile(url); | |
132 } | |
133 m_store->import(qurl, BasicStore::ImportIgnoreDuplicates); | |
128 m_isRDF = true; | 134 m_isRDF = true; |
129 } catch (...) { } | 135 } catch (...) { } |
130 } | 136 } |
131 | 137 |
132 RDFTransformFactoryImpl::~RDFTransformFactoryImpl() | 138 RDFTransformFactoryImpl::~RDFTransformFactoryImpl() |
158 std::vector<Transform> transforms; | 164 std::vector<Transform> transforms; |
159 | 165 |
160 std::map<QString, Transform> uriTransformMap; | 166 std::map<QString, Transform> uriTransformMap; |
161 | 167 |
162 Nodes tnodes = m_store->match | 168 Nodes tnodes = m_store->match |
163 (Triple(Node(), "a", m_store->expand("vamp:Transform"))).a(); | 169 (Triple(Node(), Uri("a"), m_store->expand("vamp:Transform"))).subjects(); |
164 | 170 |
165 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance(); | 171 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance(); |
166 | 172 |
167 foreach (Node tnode, tnodes) { | 173 foreach (Node tnode, tnodes) { |
168 | 174 |
169 Node pnode = m_store->matchFirst | 175 Node pnode = m_store->complete |
170 (Triple(tnode, "vamp:plugin", Node())).c; | 176 (Triple(tnode, m_store->expand("vamp:plugin"), Node())); |
171 | 177 |
172 if (pnode == Node()) { | 178 if (pnode == Node()) { |
173 cerr << "RDFTransformFactory: WARNING: No vamp:plugin for " | 179 cerr << "RDFTransformFactory: WARNING: No vamp:plugin for " |
174 << "vamp:Transform node " << tnode | 180 << "vamp:Transform node " << tnode |
175 << ", skipping this transform" << endl; | 181 << ", skipping this transform" << endl; |
214 | 220 |
215 for (int j = 0; j < sizeof(optionals)/sizeof(optionals[0]); ++j) { | 221 for (int j = 0; j < sizeof(optionals)/sizeof(optionals[0]); ++j) { |
216 | 222 |
217 QString optional = optionals[j]; | 223 QString optional = optionals[j]; |
218 | 224 |
219 Node onode = m_store->matchFirst | 225 Node onode = m_store->complete |
220 (Triple(Uri(transformUri), optional, Node())).c; | 226 (Triple(Uri(transformUri), |
227 m_store->expand(QString("vamp:") + optional), Node())); | |
221 | 228 |
222 if (onode.type != Node::Literal) continue; | 229 if (onode.type != Node::Literal) continue; |
223 | 230 |
224 if (optional == "program") { | 231 if (optional == "program") { |
225 transform.setProgram(onode.value); | 232 transform.setProgram(onode.value); |
245 } else { | 252 } else { |
246 cerr << "RDFTransformFactory: ERROR: Inconsistent optionals lists (unexpected optional \"" << optional << "\"" << endl; | 253 cerr << "RDFTransformFactory: ERROR: Inconsistent optionals lists (unexpected optional \"" << optional << "\"" << endl; |
247 } | 254 } |
248 } | 255 } |
249 | 256 |
250 SVDEBUG << "RDFTransformFactory: NOTE: Transform is: " << endl; | 257 cerr << "RDFTransformFactory: NOTE: Transform is: " << endl; |
251 cerr << transform.toXmlString() << endl; | 258 cerr << transform.toXmlString() << endl; |
252 | 259 |
253 transforms.push_back(transform); | 260 transforms.push_back(transform); |
254 } | 261 } |
255 | 262 |
258 | 265 |
259 bool | 266 bool |
260 RDFTransformFactoryImpl::setOutput(Transform &transform, | 267 RDFTransformFactoryImpl::setOutput(Transform &transform, |
261 QString transformUri) | 268 QString transformUri) |
262 { | 269 { |
263 Node outputNode = m_store->matchFirst | 270 Node outputNode = m_store->complete |
264 (Triple(Uri(transformUri), "vamp:output", Node())).c; | 271 (Triple(Uri(transformUri), m_store->expand("vamp:output"), Node())); |
265 | 272 |
266 if (outputNode == Node()) return true; | 273 if (outputNode == Node()) return true; |
267 | 274 |
268 if (outputNode.type != Node::URI && outputNode.type != Node::Blank) { | 275 if (outputNode.type != Node::URI && outputNode.type != Node::Blank) { |
269 m_errorString = QString("vamp:output for output of transform <%1> is not a URI or blank node").arg(transformUri); | 276 m_errorString = QString("vamp:output for output of transform <%1> is not a URI or blank node").arg(transformUri); |
272 | 279 |
273 // Now, outputNode might be the subject of a triple within m_store | 280 // Now, outputNode might be the subject of a triple within m_store |
274 // that tells us the vamp:identifier, or it might be the subject | 281 // that tells us the vamp:identifier, or it might be the subject |
275 // of a triple within the indexer that tells us it | 282 // of a triple within the indexer that tells us it |
276 | 283 |
277 Node identNode = m_store->matchFirst | 284 Node identNode = m_store->complete |
278 (Triple(outputNode, "vamp:identifier", Node())).c; | 285 (Triple(outputNode, m_store->expand("vamp:identifier"), Node())); |
279 | 286 |
280 if (identNode == Node()) { | 287 if (identNode == Node()) { |
281 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance(); | 288 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance(); |
282 const BasicStore *index = indexer->getIndex(); | 289 const BasicStore *index = indexer->getIndex(); |
283 identNode = index->matchFirst | 290 identNode = index->complete |
284 (Triple(outputNode, "vamp:identifier", Node())).c; | 291 (Triple(outputNode, index->expand("vamp:identifier"), Node())); |
285 } | 292 } |
286 | 293 |
287 if (identNode == Node() || identNode.type != Node::Literal) { | 294 if (identNode == Node() || identNode.type != Node::Literal) { |
288 m_errorString = QString("No vamp:identifier found for output of transform <%1>, or vamp:identifier is not a literal").arg(transformUri); | 295 m_errorString = QString("No vamp:identifier found for output of transform <%1>, or vamp:identifier is not a literal").arg(transformUri); |
289 return false; | 296 return false; |
298 bool | 305 bool |
299 RDFTransformFactoryImpl::setParameters(Transform &transform, | 306 RDFTransformFactoryImpl::setParameters(Transform &transform, |
300 QString transformUri) | 307 QString transformUri) |
301 { | 308 { |
302 Nodes bindings = m_store->match | 309 Nodes bindings = m_store->match |
303 (Triple(Uri(transformUri), "vamp:parameter_binding", Node())).c(); | 310 (Triple(Uri(transformUri), m_store->expand("vamp:parameter_binding"), Node())).objects(); |
304 | 311 |
305 foreach (Node binding, bindings) { | 312 foreach (Node binding, bindings) { |
306 | 313 |
307 Node paramNode = m_store->matchFirst | 314 Node paramNode = m_store->complete |
308 (Triple(binding, "vamp:parameter", Node())).c; | 315 (Triple(binding, m_store->expand("vamp:parameter"), Node())); |
309 | 316 |
310 if (paramNode == Node()) { | 317 if (paramNode == Node()) { |
311 cerr << "RDFTransformFactoryImpl::setParameters: No vamp:parameter for binding " << binding << endl; | 318 cerr << "RDFTransformFactoryImpl::setParameters: No vamp:parameter for binding " << binding << endl; |
312 continue; | 319 continue; |
313 } | 320 } |
314 | 321 |
315 Node valueNode = m_store->matchFirst | 322 Node valueNode = m_store->complete |
316 (Triple(binding, "vamp:value", Node())).c; | 323 (Triple(binding, m_store->expand("vamp:value"), Node())); |
317 | 324 |
318 if (paramNode == Node()) { | 325 if (paramNode == Node()) { |
319 cerr << "RDFTransformFactoryImpl::setParameters: No vamp:value for binding " << binding << endl; | 326 cerr << "RDFTransformFactoryImpl::setParameters: No vamp:value for binding " << binding << endl; |
320 continue; | 327 continue; |
321 } | 328 } |
322 | |
323 Node idNode = m_store->matchFirst | |
324 (Triple(paramNode, "vamp:identifier", Node())).c; | |
325 | 329 |
330 // As with output above, paramNode might be the subject of a | |
331 // triple within m_store that tells us the vamp:identifier, or | |
332 // it might be the subject of a triple within the indexer that | |
333 // tells us it | |
334 | |
335 Node idNode = m_store->complete | |
336 (Triple(paramNode, m_store->expand("vamp:identifier"), Node())); | |
337 | |
326 if (idNode == Node()) { | 338 if (idNode == Node()) { |
339 PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance(); | |
340 const BasicStore *index = indexer->getIndex(); | |
341 idNode = index->complete | |
342 (Triple(paramNode, index->expand("vamp:identifier"), Node())); | |
343 } | |
344 | |
345 if (idNode == Node() || idNode.type != Node::Literal) { | |
327 cerr << "RDFTransformFactoryImpl::setParameters: No vamp:identifier for parameter " << paramNode << endl; | 346 cerr << "RDFTransformFactoryImpl::setParameters: No vamp:identifier for parameter " << paramNode << endl; |
328 continue; | 347 continue; |
329 } | 348 } |
330 | 349 |
331 transform.setParameter(idNode.value, valueNode.value.toFloat()); | 350 transform.setParameter(idNode.value, valueNode.value.toFloat()); |