diff options
-rw-r--r-- | src/libs/client/Loader.cpp | 20 | ||||
-rw-r--r-- | src/libs/client/Loader.h | 2 | ||||
-rw-r--r-- | src/libs/client/Makefile.am | 4 | ||||
-rw-r--r-- | src/libs/client/Namespaces.cpp | 43 | ||||
-rw-r--r-- | src/libs/client/Namespaces.h | 44 | ||||
-rw-r--r-- | src/libs/client/RDFQuery.cpp | 80 | ||||
-rw-r--r-- | src/libs/client/RDFQuery.h | 62 |
7 files changed, 11 insertions, 244 deletions
diff --git a/src/libs/client/Loader.cpp b/src/libs/client/Loader.cpp index 5120b97b..aebe4c80 100644 --- a/src/libs/client/Loader.cpp +++ b/src/libs/client/Loader.cpp @@ -16,8 +16,8 @@ #include <iostream> #include <raptor.h> +#include "raul/RDFQuery.h" #include "Loader.h" -#include "RDFQuery.h" #include "ModelEngineInterface.h" namespace Ingen { @@ -32,9 +32,9 @@ Loader::Loader(SharedPtr<ModelEngineInterface> engine, SharedPtr<Namespaces> nam _namespaces = SharedPtr<Namespaces>(new Namespaces()); // FIXME: hack - _namespaces->add("ingen", "http://codeson.net/ns/ingen#"); - _namespaces->add("ingenuity", "http://codeson.net/ns/ingenuity#"); - _namespaces->add("lv2", "http://lv2plug.in/ontology#>"); + (*_namespaces)["ingen"] = "http://codeson.net/ns/ingen#"; + (*_namespaces)["ingenuity"] = "http://codeson.net/ns/ingenuity#"; + (*_namespaces)["lv2"] = "http://lv2plug.in/ontology#>"; } @@ -69,7 +69,7 @@ Loader::load(const Glib::ustring& filename, /* Get polyphony (mandatory) */ // FIXME: polyphony datatype - RDFQuery query(Glib::ustring( + RDFQuery query(*_namespaces, Glib::ustring( "SELECT DISTINCT ?poly \nFROM <") + document_uri + ">\nWHERE {\n\t" + patch_uri + " ingen:polyphony ?poly .\n" "}"); @@ -89,7 +89,7 @@ Loader::load(const Glib::ustring& filename, if (patch_name == "") { patch_name = string(filename.substr(filename.find_last_of("/")+1)); - query = RDFQuery(Glib::ustring( + query = RDFQuery(*_namespaces, Glib::ustring( "SELECT DISTINCT ?name FROM <") + document_uri + "> WHERE {\n" + patch_uri + " ingen:name ?name .\n" "}"); @@ -107,7 +107,7 @@ Loader::load(const Glib::ustring& filename, /* Load nodes */ - query = RDFQuery(Glib::ustring( + query = RDFQuery(*_namespaces, Glib::ustring( "SELECT DISTINCT ?name ?plugin ?floatkey ?floatval FROM <") + document_uri + "> WHERE {\n" + patch_uri + " ingen:node ?node .\n" "?node ingen:name ?name ;\n" @@ -144,7 +144,7 @@ Loader::load(const Glib::ustring& filename, /* Set node port control values */ - query = RDFQuery(Glib::ustring( + query = RDFQuery(*_namespaces, Glib::ustring( "SELECT DISTINCT ?nodename ?portname ?portval FROM <") + document_uri + "> WHERE {\n" + patch_uri + " ingen:node ?node .\n" "?node ingen:name ?nodename ;\n" @@ -173,7 +173,7 @@ Loader::load(const Glib::ustring& filename, /* Load this patch's ports */ - query = RDFQuery(Glib::ustring( + query = RDFQuery(*_namespaces, Glib::ustring( "SELECT DISTINCT ?port ?type ?name ?datatype ?floatkey ?floatval ?portval FROM <") + document_uri + "> WHERE {\n" + patch_uri + " ingen:port ?port .\n" "?port a ?type ;\n" @@ -223,7 +223,7 @@ Loader::load(const Glib::ustring& filename, /* Load connections */ // FIXME: path? - query = RDFQuery(Glib::ustring( + query = RDFQuery(*_namespaces, Glib::ustring( "SELECT DISTINCT ?srcnode ?src ?dstnode ?dst FROM <") + document_uri + "> WHERE {\n" + "?srcnoderef ingen:port ?srcref .\n" "?dstnoderef ingen:port ?dstref .\n" diff --git a/src/libs/client/Loader.h b/src/libs/client/Loader.h index bca385aa..d252520d 100644 --- a/src/libs/client/Loader.h +++ b/src/libs/client/Loader.h @@ -20,7 +20,7 @@ #include <glibmm/ustring.h> #include "raul/SharedPtr.h" #include "raul/Path.h" -#include "Namespaces.h" +#include "raul/Namespaces.h" #include "ObjectModel.h" namespace Ingen { diff --git a/src/libs/client/Makefile.am b/src/libs/client/Makefile.am index c2bf662b..b0cd1122 100644 --- a/src/libs/client/Makefile.am +++ b/src/libs/client/Makefile.am @@ -28,10 +28,6 @@ libingenclient_la_SOURCES = \ PatchModel.h \ PatchModel.cpp \ PluginModel.h \ - RDFQuery.h \ - RDFQuery.cpp \ - Namespaces.h \ - Namespaces.cpp \ Serializer.h \ Serializer.cpp \ Loader.h \ diff --git a/src/libs/client/Namespaces.cpp b/src/libs/client/Namespaces.cpp deleted file mode 100644 index 005cce61..00000000 --- a/src/libs/client/Namespaces.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "Namespaces.h" - -namespace Ingen { -namespace Client { - - -/** Create a prefixed qname from @a uri, if possible. - * - * If @a uri can not be qualified with the namespaces currently in this - * Namespaces, @a uri will be returned unmodified. - */ -string -Namespaces::qualify(string uri) -{ - for (std::map<string,string>::iterator i = _namespaces.begin(); i != _namespaces.end(); ++i) { - size_t ns_len = i->second.length(); - - if (uri.substr(0, ns_len) == i->second) - return i->first + ":" + uri.substr(ns_len); - } - - return uri; -} - - -} // namespace Client -} // namespace Ingen diff --git a/src/libs/client/Namespaces.h b/src/libs/client/Namespaces.h deleted file mode 100644 index 100f4e9a..00000000 --- a/src/libs/client/Namespaces.h +++ /dev/null @@ -1,44 +0,0 @@ -/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef NAMESPACES_H -#define NAMESPACES_H - -#include <map> -#include <string> -using std::string; - -namespace Ingen { -namespace Client { - - -/** Collection of RDF namespaces with prefixes. - */ -class Namespaces { -public: - void add(string prefix, string uri) { _namespaces[prefix] = uri; } - - string qualify(string uri); - -private: - std::map<string, string> _namespaces; ///< (prefix, URI) -}; - - -} // namespace Client -} // namespace Ingen - -#endif // NAMESPACES_H diff --git a/src/libs/client/RDFQuery.cpp b/src/libs/client/RDFQuery.cpp deleted file mode 100644 index 196868b8..00000000 --- a/src/libs/client/RDFQuery.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <iostream> -#include <cassert> -#include <rasqal.h> -#include "RDFQuery.h" - -#include <iostream> -using std::cerr; using std::endl; - -namespace Ingen { -namespace Client { - - -RDFQuery::Results -RDFQuery::run(const Glib::ustring base_uri_str) const -{ - Results result; - - rasqal_init(); - - rasqal_query *rq = rasqal_new_query("sparql", NULL); - - raptor_uri* base_uri = NULL; - if (base_uri_str != "") - base_uri = raptor_new_uri((const unsigned char*)base_uri_str.c_str()); - rasqal_query_prepare(rq, (unsigned char*)_query.c_str(), base_uri); - - rasqal_query_results* results = rasqal_query_execute(rq); - assert(results); - - while (!rasqal_query_results_finished(results)) { - - Bindings bindings; - - for (int i=0; i < rasqal_query_results_get_bindings_count(results); i++) { - const unsigned char* rname = rasqal_query_results_get_binding_name(results, i); - rasqal_literal* rvalue = rasqal_query_results_get_binding_value(results, i); - Glib::ustring name((const char*)rname); - - const unsigned char* str = rasqal_literal_as_string(rvalue); - - if (str) { - Glib::ustring value((const char*)str); - bindings.insert(std::make_pair(name, value)); - } - } - - result.push_back(bindings); - rasqal_query_results_next(results); - } - - rasqal_free_query_results(results); - rasqal_free_query(rq); - - if (base_uri) - raptor_free_uri(base_uri); - - rasqal_finish(); - - return result; -} - - -} // namespace Client -} // namespace Ingen diff --git a/src/libs/client/RDFQuery.h b/src/libs/client/RDFQuery.h deleted file mode 100644 index 065664e9..00000000 --- a/src/libs/client/RDFQuery.h +++ /dev/null @@ -1,62 +0,0 @@ -/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef RDFQUERY_H -#define RDFQUERY_H - -#include <map> -#include <list> -#include <glibmm/ustring.h> - -namespace Ingen { -namespace Client { - - -/** Pretty wrapper for a SPARQL query. - * - * Automatically handles things like prepending prefixes, etc. Ingen specific. - */ -class RDFQuery { -public: - typedef std::map<Glib::ustring, Glib::ustring> Bindings; - typedef std::list<Bindings> Results; - - RDFQuery(Glib::ustring query) - { - const char* const _prefix_header = - "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" - "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n" - "PREFIX ingen: <http://codeson.net/ns/ingen#>\n" - "PREFIX lv2: <http://lv2plug.in/ontology#>\n"; - - _query = _prefix_header + query; - } - - Results run(const Glib::ustring base_uri) const; - - Glib::ustring string() const { return _query; }; - -private: - - Glib::ustring _query; -}; - - -} // namespace Client -} // namespace Ingen - -#endif // RDFQUERY_H - |