Mercurial > hg > svcore
diff rdf/PluginRDFDescription.cpp @ 742:c10cb8782576 coreaudio_tests
Merge from branch "default"
author | Chris Cannam |
---|---|
date | Sun, 01 Jul 2012 11:53:00 +0100 |
parents | 87a9168efd71 |
children | e802e550a1f2 |
line wrap: on
line diff
--- a/rdf/PluginRDFDescription.cpp Mon Nov 29 12:45:39 2010 +0000 +++ b/rdf/PluginRDFDescription.cpp Sun Jul 01 11:53:00 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) @@ -34,7 +42,7 @@ m_pluginUri = indexer->getURIForPluginId(pluginId); if (m_pluginUri == "") { cerr << "PluginRDFDescription: WARNING: No RDF description available for plugin ID \"" - << pluginId.toStdString() << "\"" << endl; + << pluginId << "\"" << endl; } else { // All the data we need should be in our RDF model already: // if it's not there, we don't know where to find it anyway @@ -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,57 +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 ?output_id ?output_type ?unit " - - " WHERE { " - - " <%1> vamp:output ?output . " - - " ?output vamp:identifier ?output_id ; " - " a ?output_type . " - - " OPTIONAL { " - " ?output vamp:unit ?unit " - " } . " - - " } " - ) - .arg(m_pluginUri)); - - SimpleSPARQLQuery::ResultList results = query.execute(); - - if (!query.isOK()) { - cerr << "ERROR: PluginRDFDescription::index: ERROR: Failed to query outputs for <" - << m_pluginUri.toStdString() << ">: " - << query.getErrorString().toStdString() << endl; + if (outputs.empty()) { + cerr << "ERROR: PluginRDFDescription::indexURL: NOTE: No outputs defined for <" + << m_pluginUri << ">" << endl; return false; } - if (results.empty()) { - cerr << "ERROR: PluginRDFDescription::indexURL: NOTE: No outputs defined for <" - << m_pluginUri.toStdString() << ">" << endl; - return false; - } + foreach (Node output, outputs) { - // 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 + 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; + } + + 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 = n.value; - for (int i = 0; i < results.size(); ++i) { + m_outputUriMap[outputId] = output.value; - QString outputUri = results[i]["output"].value; - QString outputId = results[i]["output_id"].value; - QString outputType = results[i]["output_type"].value; + n = index->complete(Triple(output, Uri("a"), Node())); + QString outputType; + if (n.type == Node::URI) outputType = n.value; - m_outputUriMap[outputId] = outputUri; + n = index->complete(Triple(output, index->expand("vamp:unit"), Node())); + QString outputUnit; + if (n.type == Node::Literal) outputUnit = n.value; if (outputType.contains("DenseOutput")) { m_outputDispositions[outputId] = OutputDense; @@ -331,55 +284,32 @@ } else { m_outputDispositions[outputId] = OutputDispositionUnknown; } +// cerr << "output " << output << " -> id " << outputId << ", type " << outputType << ", unit " +// << outputUnit << ", disposition " << m_outputDispositions[outputId] << endl; - if (results[i]["unit"].type == SimpleSPARQLQuery::LiteralValue) { - - QString unit = results[i]["unit"].value; - - if (unit != "") { - m_outputUnitMap[outputId] = unit; - } + if (outputUnit != "") { + m_outputUnitMap[outputId] = outputUnit; } - SimpleSPARQLQuery::Value v; - - v = SimpleSPARQLQuery::singleResultQuery - (m, - QString(" PREFIX vamp: <http://purl.org/ontology/vamp/> " - " PREFIX dc: <http://purl.org/dc/elements/1.1/> " - " SELECT ?title " - " WHERE { <%2> 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 ?%3 " - " WHERE { <%2> vamp:computes_%3 ?%3 } ") - .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; } }