changeset 503:3176aade1a03

* Make RDFTransformFactory::writeTransformToRDF write out partial library and plugin descriptions adequate to identify the plugin on disk, if no RDF description for the plugin has been found
author Chris Cannam
date Fri, 05 Dec 2008 09:40:42 +0000
parents bd7c46636bd0
children 3376dc26dece
files rdf/RDFTransformFactory.cpp
diffstat 1 files changed, 25 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/rdf/RDFTransformFactory.cpp	Thu Dec 04 17:17:06 2008 +0000
+++ b/rdf/RDFTransformFactory.cpp	Fri Dec 05 09:40:42 2008 +0000
@@ -27,6 +27,7 @@
 #include "PluginRDFIndexer.h"
 #include "PluginRDFDescription.h"
 #include "base/ProgressReporter.h"
+#include "plugin/PluginIdentifier.h"
 
 #include "transform/TransformFactory.h"
 
@@ -381,22 +382,37 @@
     QString str;
     QTextStream s(&str);
 
-    // assumes the usual prefixes are available
-
-    s << uri << " a vamp:Transform ;" << endl;
+    // assumes the usual prefixes are available; requires that uri be
+    // a local fragment (e.g. ":transform") rather than a uri enclosed
+    // in <>, so that we can suffix it if need be
 
     QString pluginId = transform.getPluginIdentifier();
     QString pluginUri = PluginRDFIndexer::getInstance()->getURIForPluginId(pluginId);
 
+    if (pluginUri != "") {
+        s << uri << " a vamp:Transform ;" << endl;
+        s << "    vamp:plugin <" << pluginUri << "> ;" << endl;
+    } else {
+        std::cerr << "WARNING: RDFTransformFactory::writeTransformToRDF: No plugin URI available for plugin id \"" << pluginId.toStdString() << "\", writing synthetic plugin and library resources" << std::endl;
+        QString type, soname, label;
+        PluginIdentifier::parseIdentifier(pluginId, type, soname, label);
+        s << uri << "_plugin a vamp:Plugin ;" << endl;
+        s << "    vamp:identifier \"" << label << "\" .\n" << endl;
+        s << uri << "_library a vamp:PluginLibrary ;" << endl;
+        s << "    vamp:identifier \"" << soname << "\" ;" << endl;
+        s << "    vamp:available_plugin " << uri << "_plugin .\n" << endl;
+        s << uri << " a vamp:Transform ;" << endl;
+        s << "    vamp:plugin " << uri << "_plugin ;" << endl;
+    }
+
     PluginRDFDescription description(pluginId);
-    QString outputUri = description.getOutputUri(transform.getOutput());
+    QString outputId = transform.getOutput();
+    QString outputUri = description.getOutputUri(outputId);
 
     if (transform.getOutput() != "" && outputUri == "") {
-        std::cerr << "WARNING: RDFTransformFactory::writeTransformToRDF: No output URI available for transform output id \"" << transform.getOutput().toStdString() << "\"" << std::endl;
+        std::cerr << "WARNING: RDFTransformFactory::writeTransformToRDF: No output URI available for transform output id \"" << transform.getOutput().toStdString() << "\", writing a synthetic output resource" << std::endl;
     }
 
-    s << "    vamp:plugin <" << pluginUri << "> ;" << endl;
-
     if (transform.getStepSize() != 0) {
         s << "    vamp:step_size \"" << transform.getStepSize() << "\"^^xsd:int ; " << endl;
     }
@@ -432,6 +448,8 @@
 
     if (outputUri != "") {
         s << "    vamp:output <" << outputUri << "> ." << endl;
+    } else if (outputId != "") {
+        s << "    vamp:output [ vamp:identifier \"" << outputId << "\" ] ." << endl;
     } else {
         s << "    ." << endl;
     }