comparison rdf/RDFTransformFactory.cpp @ 729:11289d40a57a dataquay

Finish converting RDFTransformFactory
author Chris Cannam
date Sat, 19 May 2012 18:57:52 +0100
parents f2de9a42830e
children 27c861cce97b
comparison
equal deleted inserted replaced
728:f2de9a42830e 729:11289d40a57a
297 297
298 bool 298 bool
299 RDFTransformFactoryImpl::setParameters(Transform &transform, 299 RDFTransformFactoryImpl::setParameters(Transform &transform,
300 QString transformUri) 300 QString transformUri)
301 { 301 {
302 SimpleSPARQLQuery paramQuery 302 Nodes bindings = m_store->match
303 (SimpleSPARQLQuery::QueryFromModel, 303 (Triple(Uri(transformUri), "vamp:parameter_binding", Node())).c();
304 QString
305 (
306 " PREFIX vamp: <http://purl.org/ontology/vamp/> "
307
308 " SELECT ?param_id ?param_value "
309
310 " WHERE { "
311 " <%1> vamp:parameter_binding ?binding . "
312 " ?binding vamp:parameter ?param ; "
313 " vamp:value ?param_value . "
314 " ?param vamp:identifier ?param_id "
315 " } "
316 )
317 .arg(transformUri));
318 304
319 SimpleSPARQLQuery::ResultList paramResults = paramQuery.execute(); 305 foreach (Node binding, bindings) {
320 306
321 if (!paramQuery.isOK()) { 307 Node paramNode = m_store->matchFirst
322 m_errorString = paramQuery.getErrorString(); 308 (Triple(binding, "vamp:parameter", Node())).c;
323 return false; 309
324 } 310 if (paramNode == Node()) {
325 311 cerr << "RDFTransformFactoryImpl::setParameters: No vamp:parameter for binding " << binding << endl;
326 if (paramQuery.wasCancelled()) { 312 continue;
327 m_errorString = "Query cancelled"; 313 }
328 return false; 314
329 } 315 Node valueNode = m_store->matchFirst
330 316 (Triple(binding, "vamp:value", Node())).c;
331 for (int j = 0; j < paramResults.size(); ++j) { 317
318 if (paramNode == Node()) {
319 cerr << "RDFTransformFactoryImpl::setParameters: No vamp:value for binding " << binding << endl;
320 continue;
321 }
322
323 Node idNode = m_store->matchFirst
324 (Triple(paramNode, "vamp:identifier", Node())).c;
332 325
333 QString paramId = paramResults[j]["param_id"].value; 326 if (idNode == Node()) {
334 QString paramValue = paramResults[j]["param_value"].value; 327 cerr << "RDFTransformFactoryImpl::setParameters: No vamp:identifier for parameter " << paramNode << endl;
328 continue;
329 }
335 330
336 if (paramId == "" || paramValue == "") continue; 331 transform.setParameter(idNode.value, valueNode.value.toFloat());
337
338 transform.setParameter(paramId, paramValue.toFloat());
339 } 332 }
340 333
341 return true; 334 return true;
342 } 335 }
343 336