diff rdf/RDFImporter.cpp @ 493:3931711b5671

* RDF importer: add model titles where possible * RDF transform factory: report whether something appears to be RDF or not (so we can avoid trying to load it as something else if the RDF query fails)
author Chris Cannam
date Tue, 25 Nov 2008 13:43:56 +0000
parents 23945cdd7161
children b71116d3c180
line wrap: on
line diff
--- a/rdf/RDFImporter.cpp	Mon Nov 24 16:26:11 2008 +0000
+++ b/rdf/RDFImporter.cpp	Tue Nov 25 13:43:56 2008 +0000
@@ -59,6 +59,8 @@
     void getDataModelsSparse(std::vector<Model *> &, ProgressReporter *);
     void getDataModelsDense(std::vector<Model *> &, ProgressReporter *);
 
+    void getDenseModelTitle(Model *, QString, QString);
+
     void getDenseFeatureProperties(QString featureUri,
                                    int &sampleRate, int &windowLength,
                                    int &hopSize, int &width, int &height);
@@ -184,14 +186,12 @@
              " PREFIX mo: <http://purl.org/ontology/mo/>"
              " PREFIX af: <http://purl.org/ontology/af/>"
              
-             " SELECT ?feature ?signal_source ?feature_signal_type ?value "
+             " SELECT ?feature ?feature_signal_type ?value "
              " FROM <%1> "
              
              " WHERE { "
              
-             "   ?signal a mo:Signal ; "
-             "           mo:available_as ?signal_source ; "
-             "           af:signal_feature ?feature . "
+             "   ?signal af:signal_feature ?feature . "
              
              "   ?feature a ?feature_signal_type ; "
              "            af:value ?value . "
@@ -215,7 +215,6 @@
     for (int i = 0; i < results.size(); ++i) {
 
         QString feature = results[i]["feature"].value;
-        QString source = results[i]["signal_source"].value;
         QString type = results[i]["feature_signal_type"].value;
         QString value = results[i]["value"].value;
 
@@ -259,6 +258,8 @@
                 SparseTimeValueModel::Point point(j * hopSize, f, "");
                 m->addPoint(point);
             }
+
+            getDenseModelTitle(m, feature, type);
         
             models.push_back(m);
 
@@ -284,12 +285,56 @@
                 m->setColumn(x++, column);
             }
 
+            getDenseModelTitle(m, feature, type);
+        
             models.push_back(m);
         }
     }
 }
 
 void
+RDFImporterImpl::getDenseModelTitle(Model *m,
+                                    QString featureUri,
+                                    QString featureTypeUri)
+{
+    QString titleQuery = QString
+        (
+            " PREFIX dc: <http://purl.org/dc/elements/1.1/> "
+            " SELECT ?title "
+            " FROM <%1> " 
+            " WHERE { "
+            "   <%2> dc:title ?title . "
+            " } "
+            ).arg(m_uristring);
+    
+    SimpleSPARQLQuery::Value v;
+
+    v = SimpleSPARQLQuery::singleResultQuery
+        (SimpleSPARQLQuery::QueryFromSingleSource,
+         titleQuery.arg(featureUri),
+         "title");
+
+    if (v.value != "") {
+        std::cerr << "RDFImporterImpl::getDenseModelTitle: Title (from signal) \"" << v.value.toStdString() << "\"" << std::endl;
+        m->setObjectName(v.value);
+        return;
+    }
+
+    v = SimpleSPARQLQuery::singleResultQuery
+        (SimpleSPARQLQuery::QueryFromSingleSource,
+         titleQuery.arg(featureTypeUri),
+         "title");
+    
+    if (v.value != "") {
+        std::cerr << "RDFImporterImpl::getDenseModelTitle: Title (from signal type) \"" << v.value.toStdString() << "\"" << std::endl;
+        m->setObjectName(v.value);
+        return;
+    }
+
+    std::cerr << "RDFImporterImpl::getDenseModelTitle: No title available for feature <" << featureUri.toStdString() << ">" << std::endl;
+}
+
+void
 RDFImporterImpl::getDenseFeatureProperties(QString featureUri,
                                            int &sampleRate, int &windowLength,
                                            int &hopSize, int &width, int &height)
@@ -643,6 +688,19 @@
                 }
             }
 
+            QString titleQuery = QString
+                (
+                    " PREFIX dc: <http://purl.org/dc/elements/1.1/> "
+                    " SELECT ?title "
+                    " FROM <%1> " 
+                    " WHERE { "
+                    "   <%2> dc:title ?title . "
+                    " } "
+                    ).arg(m_uristring).arg(type);
+            QString title = SimpleSPARQLQuery::singleResultQuery
+                (s, titleQuery, "title").value;
+            if (title != "") model->setObjectName(title);
+
             modelMap[source][type][dimensions][haveDuration] = model;
             models.push_back(model);
         }
@@ -665,7 +723,7 @@
                            std::vector<float> &values,
                            QString label)
 {
-    std::cerr << "RDFImporterImpl::fillModel: adding point at frame " << ftime << std::endl;
+//    std::cerr << "RDFImporterImpl::fillModel: adding point at frame " << ftime << std::endl;
 
     SparseOneDimensionalModel *sodm =
         dynamic_cast<SparseOneDimensionalModel *>(model);