Mercurial > hg > svcore
diff rdf/PluginRDFDescription.cpp @ 739:51d3b8e816b8
Merge from branch "dataquay". Next release will require Dataquay v0.9
author | Chris Cannam |
---|---|
date | Fri, 25 May 2012 14:58:21 +0100 |
parents | 87a9168efd71 |
children | e802e550a1f2 |
line wrap: on
line diff
--- a/rdf/PluginRDFDescription.cpp Wed May 23 17:17:17 2012 +0100 +++ b/rdf/PluginRDFDescription.cpp Fri May 25 14:58:21 2012 +0100 @@ -4,7 +4,7 @@ Sonic Visualiser An audio file viewer and annotation editor. Centre for Digital Music, Queen Mary, University of London. - This file copyright 2008 QMUL. + This file copyright 2008-2012 QMUL. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -16,16 +16,24 @@ #include "PluginRDFDescription.h" #include "PluginRDFIndexer.h" -#include "SimpleSPARQLQuery.h" #include "base/Profiler.h" #include "plugin/PluginIdentifier.h" +#include <dataquay/BasicStore.h> + #include <iostream> using std::cerr; using std::endl; +using Dataquay::Uri; +using Dataquay::Node; +using Dataquay::Nodes; +using Dataquay::Triple; +using Dataquay::Triples; +using Dataquay::BasicStore; + PluginRDFDescription::PluginRDFDescription(QString pluginId) : m_pluginId(pluginId), m_haveDescription(false) @@ -172,93 +180,52 @@ { Profiler profiler("PluginRDFDescription::index"); - SimpleSPARQLQuery::QueryType m = SimpleSPARQLQuery::QueryFromModel; + PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance(); + const BasicStore *index = indexer->getIndex(); + Uri plugin(m_pluginUri); - QString queryTemplate = - QString( - " PREFIX vamp: <http://purl.org/ontology/vamp/> " - " PREFIX foaf: <http://xmlns.com/foaf/0.1/> " - " PREFIX dc: <http://purl.org/dc/elements/1.1/> " - " SELECT ?%3 " - " WHERE { " - " <%1> %2 ?%3 . " - " }") - .arg(m_pluginUri); + Node n = index->complete + (Triple(plugin, index->expand("vamp:name"), Node())); - SimpleSPARQLQuery::Value v; - - v = SimpleSPARQLQuery::singleResultQuery - (m, queryTemplate.arg("vamp:name").arg("name"), "name"); - - if (v.type == SimpleSPARQLQuery::LiteralValue && v.value != "") { - m_pluginName = v.value; + if (n.type == Node::Literal && n.value != "") { + m_pluginName = n.value; } - v = SimpleSPARQLQuery::singleResultQuery - (m, queryTemplate.arg("dc:description").arg("description"), "description"); - - if (v.type == SimpleSPARQLQuery::LiteralValue && v.value != "") { - m_pluginDescription = v.value; + n = index->complete + (Triple(plugin, index->expand("dc:description"), Node())); + + if (n.type == Node::Literal && n.value != "") { + m_pluginDescription = n.value; } - v = SimpleSPARQLQuery::singleResultQuery - (m, - QString( - " PREFIX vamp: <http://purl.org/ontology/vamp/> " - " PREFIX foaf: <http://xmlns.com/foaf/0.1/> " - " SELECT ?name " - " WHERE { " - " <%1> foaf:maker ?maker . " - " ?maker foaf:name ?name . " - " }") - .arg(m_pluginUri), - "name"); - - if (v.type == SimpleSPARQLQuery::LiteralValue && v.value != "") { - m_pluginMaker = v.value; + n = index->complete + (Triple(plugin, index->expand("foaf:maker"), Node())); + + if (n.type == Node::URI || n.type == Node::Blank) { + n = index->complete(Triple(n, index->expand("foaf:name"), Node())); + if (n.type == Node::Literal && n.value != "") { + m_pluginMaker = n.value; + } } // If we have a more-information URL for this plugin, then we take - // that. Otherwise, a more-information URL for the plugin - // library would do nicely. Failing that, we could perhaps use - // any foaf:page URL at all that appears in the file -- but - // perhaps that would be unwise + // that. Otherwise, a more-information URL for the plugin library + // would do nicely. - v = SimpleSPARQLQuery::singleResultQuery - (m, - QString( - " PREFIX vamp: <http://purl.org/ontology/vamp/> " - " PREFIX foaf: <http://xmlns.com/foaf/0.1/> " - " SELECT ?page " - " WHERE { " - " <%1> foaf:page ?page . " - " }") - .arg(m_pluginUri), - "page"); + n = index->complete + (Triple(plugin, index->expand("foaf:page"), Node())); - if (v.type == SimpleSPARQLQuery::URIValue && v.value != "") { + if (n.type == Node::URI && n.value != "") { + m_pluginInfoURL = n.value; + } - m_pluginInfoURL = v.value; + n = index->complete + (Triple(Node(), index->expand("vamp:available_plugin"), plugin)); - } else { - - v = SimpleSPARQLQuery::singleResultQuery - (m, - QString( - " PREFIX vamp: <http://purl.org/ontology/vamp/> " - " PREFIX foaf: <http://xmlns.com/foaf/0.1/> " - " SELECT ?page " - " WHERE { " - " ?library vamp:available_plugin <%1> ; " - " a vamp:PluginLibrary ; " - " foaf:page ?page . " - " }") - .arg(m_pluginUri), - "page"); - - if (v.type == SimpleSPARQLQuery::URIValue && v.value != "") { - - m_pluginInfoURL = v.value; + if (n.value != "") { + n = index->complete(Triple(n, index->expand("foaf:page"), Node())); + if (n.type == Node::URI && n.value != "") { + m_pluginInfoURL = n.value; } } @@ -270,87 +237,43 @@ { Profiler profiler("PluginRDFDescription::indexOutputs"); - SimpleSPARQLQuery::QueryType m = SimpleSPARQLQuery::QueryFromModel; + PluginRDFIndexer *indexer = PluginRDFIndexer::getInstance(); + const BasicStore *index = indexer->getIndex(); + Uri plugin(m_pluginUri); - SimpleSPARQLQuery query - (m, - QString - ( - " PREFIX vamp: <http://purl.org/ontology/vamp/> " + Nodes outputs = index->match + (Triple(plugin, index->expand("vamp:output"), Node())).objects(); - " SELECT ?output " - - " WHERE { " - " <%1> vamp:output ?output . " - " } " - ) - .arg(m_pluginUri)); - - SimpleSPARQLQuery::ResultList results = query.execute(); - - if (!query.isOK()) { - cerr << "ERROR: PluginRDFDescription::index: ERROR: Failed to query outputs for <" - << m_pluginUri << ">: " - << query.getErrorString() << endl; - return false; - } - - if (results.empty()) { + if (outputs.empty()) { cerr << "ERROR: PluginRDFDescription::indexURL: NOTE: No outputs defined for <" << m_pluginUri << ">" << endl; return false; } - // Note that an output may appear more than once, if it inherits - // more than one type (e.g. DenseOutput and QuantizedOutput). So - // these results must accumulate + foreach (Node output, outputs) { - for (int i = 0; i < results.size(); ++i) { - - if (results[i]["output"].type != SimpleSPARQLQuery::URIValue || - results[i]["output"].value == "") { - cerr << "ERROR: PluginRDFDescription::indexURL: No valid URI for output " << i << " of plugin <" << m_pluginUri << ">" << endl; + if ((output.type != Node::URI && output.type != Node::Blank) || + output.value == "") { + cerr << "ERROR: PluginRDFDescription::indexURL: No valid URI for output " << output << " of plugin <" << m_pluginUri << ">" << endl; return false; } - - QString outputUri = results[i]["output"].value; - - SimpleSPARQLQuery::Value v; - - v = SimpleSPARQLQuery::singleResultQuery - (m, - QString(" PREFIX vamp: <http://purl.org/ontology/vamp/> " - " SELECT ?output_id " - " WHERE { <%1> vamp:identifier ?output_id } ") - .arg(outputUri), "output_id"); - - if (v.type != SimpleSPARQLQuery::LiteralValue || v.value == "") { - cerr << "ERROR: PluginRDFDescription::indexURL: No identifier for output <" << outputUri << ">" << endl; + + Node n = index->complete(Triple(output, index->expand("vamp:identifier"), Node())); + if (n.type != Node::Literal || n.value == "") { + cerr << "ERROR: PluginRDFDescription::indexURL: No vamp:identifier for output <" << output << ">" << endl; return false; } - QString outputId = v.value; + QString outputId = n.value; - v = SimpleSPARQLQuery::singleResultQuery - (m, - QString(" PREFIX vamp: <http://purl.org/ontology/vamp/> " - " SELECT ?output_type " - " WHERE { <%1> a ?output_type } ") - .arg(outputUri), "output_type"); + m_outputUriMap[outputId] = output.value; + n = index->complete(Triple(output, Uri("a"), Node())); QString outputType; - if (v.type == SimpleSPARQLQuery::URIValue) outputType = v.value; + if (n.type == Node::URI) outputType = n.value; - v = SimpleSPARQLQuery::singleResultQuery - (m, - QString(" PREFIX vamp: <http://purl.org/ontology/vamp/> " - " SELECT ?unit " - " WHERE { <%1> vamp:unit ?unit } ") - .arg(outputUri), "unit"); - + n = index->complete(Triple(output, index->expand("vamp:unit"), Node())); QString outputUnit; - if (v.type == SimpleSPARQLQuery::LiteralValue) outputUnit = v.value; - - m_outputUriMap[outputId] = outputUri; + if (n.type == Node::Literal) outputUnit = n.value; if (outputType.contains("DenseOutput")) { m_outputDispositions[outputId] = OutputDense; @@ -361,48 +284,32 @@ } else { m_outputDispositions[outputId] = OutputDispositionUnknown; } +// cerr << "output " << output << " -> id " << outputId << ", type " << outputType << ", unit " +// << outputUnit << ", disposition " << m_outputDispositions[outputId] << endl; if (outputUnit != "") { m_outputUnitMap[outputId] = outputUnit; } - v = SimpleSPARQLQuery::singleResultQuery - (m, - QString(" PREFIX vamp: <http://purl.org/ontology/vamp/> " - " PREFIX dc: <http://purl.org/dc/elements/1.1/> " - " SELECT ?title " - " WHERE { <%1> dc:title ?title } ") - .arg(outputUri), "title"); - - if (v.type == SimpleSPARQLQuery::LiteralValue && v.value != "") { - m_outputNames[outputId] = v.value; + n = index->complete(Triple(output, index->expand("dc:title"), Node())); + if (n.type == Node::Literal && n.value != "") { + m_outputNames[outputId] = n.value; } - QString queryTemplate = - QString(" PREFIX vamp: <http://purl.org/ontology/vamp/> " - " SELECT ?%2 " - " WHERE { <%1> vamp:computes_%2 ?%2 } ") - .arg(outputUri); - - v = SimpleSPARQLQuery::singleResultQuery - (m, queryTemplate.arg("event_type"), "event_type"); - - if (v.type == SimpleSPARQLQuery::URIValue && v.value != "") { - m_outputEventTypeURIMap[outputId] = v.value; + n = index->complete(Triple(output, index->expand("vamp:computes_event_type"), Node())); +// cerr << output << " -> computes_event_type " << n << endl; + if (n.type == Node::URI && n.value != "") { + m_outputEventTypeURIMap[outputId] = n.value; } - v = SimpleSPARQLQuery::singleResultQuery - (m, queryTemplate.arg("feature"), "feature"); + n = index->complete(Triple(output, index->expand("vamp:computes_feature"), Node())); + if (n.type == Node::URI && n.value != "") { + m_outputFeatureAttributeURIMap[outputId] = n.value; + } - if (v.type == SimpleSPARQLQuery::URIValue && v.value != "") { - m_outputFeatureAttributeURIMap[outputId] = v.value; - } - - v = SimpleSPARQLQuery::singleResultQuery - (m, queryTemplate.arg("signal_type"), "signal_type"); - - if (v.type == SimpleSPARQLQuery::URIValue && v.value != "") { - m_outputSignalTypeURIMap[outputId] = v.value; + n = index->complete(Triple(output, index->expand("vamp:computes_signal_type"), Node())); + if (n.type == Node::URI && n.value != "") { + m_outputSignalTypeURIMap[outputId] = n.value; } }