Mercurial > hg > svcore
comparison rdf/RDFImporter.cpp @ 489:82ab61fa9223
* Reorganise our sparql queries on the basis that Redland must be
available, not only optional. So for anything querying the pool
of data about plugins, we use a single datastore and model which
is initialised at the outset by PluginRDFIndexer and then queried
directly; for anything that "reads from a file" (e.g. loading
annotations) we query directly using Rasqal, going to the
datastore when we need additional plugin-related information.
This may improve performance, but mostly it simplifies the code
and fixes a serious issue with RDF import in the previous versions
(namely that multiple sequential RDF imports would end up sharing
the same RDF data pool!)
author | Chris Cannam |
---|---|
date | Fri, 21 Nov 2008 16:12:29 +0000 |
parents | 1c66e199e7d9 |
children | c3fb8258e34d |
comparison
equal
deleted
inserted
replaced
488:1c66e199e7d9 | 489:82ab61fa9223 |
---|---|
140 void | 140 void |
141 RDFImporterImpl::getDataModelsDense(std::vector<Model *> &models, | 141 RDFImporterImpl::getDataModelsDense(std::vector<Model *> &models, |
142 ProgressReporter *reporter) | 142 ProgressReporter *reporter) |
143 { | 143 { |
144 SimpleSPARQLQuery query = SimpleSPARQLQuery | 144 SimpleSPARQLQuery query = SimpleSPARQLQuery |
145 (m_uristring, | 145 (SimpleSPARQLQuery::QueryFromSingleSource, |
146 QString | 146 QString |
147 ( | 147 ( |
148 " PREFIX mo: <http://purl.org/ontology/mo/>" | 148 " PREFIX mo: <http://purl.org/ontology/mo/>" |
149 " PREFIX af: <http://purl.org/ontology/af/>" | 149 " PREFIX af: <http://purl.org/ontology/af/>" |
150 | 150 |
256 void | 256 void |
257 RDFImporterImpl::getDenseFeatureProperties(QString featureUri, | 257 RDFImporterImpl::getDenseFeatureProperties(QString featureUri, |
258 int &sampleRate, int &windowLength, | 258 int &sampleRate, int &windowLength, |
259 int &hopSize, int &width, int &height) | 259 int &hopSize, int &width, int &height) |
260 { | 260 { |
261 SimpleSPARQLQuery::QueryType s = SimpleSPARQLQuery::QueryFromSingleSource; | |
262 | |
261 QString dimensionsQuery | 263 QString dimensionsQuery |
262 ( | 264 ( |
263 " PREFIX mo: <http://purl.org/ontology/mo/>" | 265 " PREFIX mo: <http://purl.org/ontology/mo/>" |
264 " PREFIX af: <http://purl.org/ontology/af/>" | 266 " PREFIX af: <http://purl.org/ontology/af/>" |
265 | 267 |
272 | 274 |
273 " } " | 275 " } " |
274 ); | 276 ); |
275 | 277 |
276 SimpleSPARQLQuery::Value dimensionsValue = | 278 SimpleSPARQLQuery::Value dimensionsValue = |
277 SimpleSPARQLQuery::singleResultQuery(m_uristring, | 279 SimpleSPARQLQuery::singleResultQuery |
278 dimensionsQuery | 280 (s, dimensionsQuery.arg(m_uristring).arg(featureUri), "dimensions"); |
279 .arg(m_uristring).arg(featureUri), | |
280 "dimensions"); | |
281 | 281 |
282 cerr << "Dimensions = \"" << dimensionsValue.value.toStdString() << "\"" | 282 cerr << "Dimensions = \"" << dimensionsValue.value.toStdString() << "\"" |
283 << endl; | 283 << endl; |
284 | 284 |
285 if (dimensionsValue.value != "") { | 285 if (dimensionsValue.value != "") { |
314 | 314 |
315 // Another laborious workaround for rasqal's failure to handle | 315 // Another laborious workaround for rasqal's failure to handle |
316 // multiple optionals properly | 316 // multiple optionals properly |
317 | 317 |
318 SimpleSPARQLQuery::Value srValue = | 318 SimpleSPARQLQuery::Value srValue = |
319 SimpleSPARQLQuery::singleResultQuery(m_uristring, | 319 SimpleSPARQLQuery::singleResultQuery(s, |
320 queryTemplate | 320 queryTemplate |
321 .arg(m_uristring).arg(featureUri) | 321 .arg(m_uristring).arg(featureUri) |
322 .arg("sampleRate"), | 322 .arg("sampleRate"), |
323 "sampleRate"); | 323 "sampleRate"); |
324 if (srValue.value != "") { | 324 if (srValue.value != "") { |
325 sampleRate = srValue.value.toInt(); | 325 sampleRate = srValue.value.toInt(); |
326 } | 326 } |
327 | 327 |
328 SimpleSPARQLQuery::Value hopValue = | 328 SimpleSPARQLQuery::Value hopValue = |
329 SimpleSPARQLQuery::singleResultQuery(m_uristring, | 329 SimpleSPARQLQuery::singleResultQuery(s, |
330 queryTemplate | 330 queryTemplate |
331 .arg(m_uristring).arg(featureUri) | 331 .arg(m_uristring).arg(featureUri) |
332 .arg("hopSize"), | 332 .arg("hopSize"), |
333 "hopSize"); | 333 "hopSize"); |
334 if (srValue.value != "") { | 334 if (srValue.value != "") { |
335 hopSize = hopValue.value.toInt(); | 335 hopSize = hopValue.value.toInt(); |
336 } | 336 } |
337 | 337 |
338 SimpleSPARQLQuery::Value winValue = | 338 SimpleSPARQLQuery::Value winValue = |
339 SimpleSPARQLQuery::singleResultQuery(m_uristring, | 339 SimpleSPARQLQuery::singleResultQuery(s, |
340 queryTemplate | 340 queryTemplate |
341 .arg(m_uristring).arg(featureUri) | 341 .arg(m_uristring).arg(featureUri) |
342 .arg("windowLength"), | 342 .arg("windowLength"), |
343 "windowLength"); | 343 "windowLength"); |
344 if (winValue.value != "") { | 344 if (winValue.value != "") { |
350 | 350 |
351 void | 351 void |
352 RDFImporterImpl::getDataModelsSparse(std::vector<Model *> &models, | 352 RDFImporterImpl::getDataModelsSparse(std::vector<Model *> &models, |
353 ProgressReporter *reporter) | 353 ProgressReporter *reporter) |
354 { | 354 { |
355 SimpleSPARQLQuery::QueryType s = SimpleSPARQLQuery::QueryFromSingleSource; | |
356 | |
355 // Our query is intended to retrieve every thing that has a time, | 357 // Our query is intended to retrieve every thing that has a time, |
356 // and every feature type and value associated with a thing that | 358 // and every feature type and value associated with a thing that |
357 // has a time. | 359 // has a time. |
358 | 360 |
359 // We will then need to refine this big bag of results into a set | 361 // We will then need to refine this big bag of results into a set |
441 " <%2> rdfs:label ?label . " | 443 " <%2> rdfs:label ?label . " |
442 " } " | 444 " } " |
443 | 445 |
444 ).arg(m_uristring); | 446 ).arg(m_uristring); |
445 | 447 |
446 SimpleSPARQLQuery query(m_uristring, queryString); | 448 SimpleSPARQLQuery query(s, queryString); |
447 query.setProgressReporter(reporter); | 449 query.setProgressReporter(reporter); |
448 | 450 |
449 cerr << "Query will be: " << queryString.toStdString() << endl; | 451 cerr << "Query will be: " << queryString.toStdString() << endl; |
450 | 452 |
451 SimpleSPARQLQuery::ResultList results = query.execute(); | 453 SimpleSPARQLQuery::ResultList results = query.execute(); |
503 | 505 |
504 bool haveTime = false; | 506 bool haveTime = false; |
505 bool haveDuration = false; | 507 bool haveDuration = false; |
506 | 508 |
507 QString label = SimpleSPARQLQuery::singleResultQuery | 509 QString label = SimpleSPARQLQuery::singleResultQuery |
508 (m_uristring, labelQueryString.arg(thinguri), "label").value; | 510 (s, labelQueryString.arg(thinguri), "label").value; |
509 | 511 |
510 SimpleSPARQLQuery rangeQuery(m_uristring, rangeQueryString.arg(thinguri)); | 512 SimpleSPARQLQuery rangeQuery(s, rangeQueryString.arg(thinguri)); |
511 SimpleSPARQLQuery::ResultList rangeResults = rangeQuery.execute(); | 513 SimpleSPARQLQuery::ResultList rangeResults = rangeQuery.execute(); |
512 if (!rangeResults.empty()) { | 514 if (!rangeResults.empty()) { |
513 // std::cerr << rangeResults.size() << " range results" << std::endl; | 515 // std::cerr << rangeResults.size() << " range results" << std::endl; |
514 time = RealTime::fromXsdDuration | 516 time = RealTime::fromXsdDuration |
515 (rangeResults[0]["time"].value.toStdString()); | 517 (rangeResults[0]["time"].value.toStdString()); |
518 // std::cerr << "duration string " << rangeResults[0]["duration"].value.toStdString() << std::endl; | 520 // std::cerr << "duration string " << rangeResults[0]["duration"].value.toStdString() << std::endl; |
519 haveTime = true; | 521 haveTime = true; |
520 haveDuration = true; | 522 haveDuration = true; |
521 } else { | 523 } else { |
522 QString timestring = SimpleSPARQLQuery::singleResultQuery | 524 QString timestring = SimpleSPARQLQuery::singleResultQuery |
523 (m_uristring, timeQueryString.arg(thinguri), "time").value; | 525 (s, timeQueryString.arg(thinguri), "time").value; |
524 if (timestring != "") { | 526 if (timestring != "") { |
525 time = RealTime::fromXsdDuration(timestring.toStdString()); | 527 time = RealTime::fromXsdDuration(timestring.toStdString()); |
526 haveTime = true; | 528 haveTime = true; |
527 } | 529 } |
528 } | 530 } |