summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am6
-rw-r--r--src/Namespaces.cpp43
-rw-r--r--src/RDFModel.cpp262
-rw-r--r--src/RDFNode.cpp187
-rw-r--r--src/RDFQuery.cpp89
-rw-r--r--src/RDFWorld.cpp104
6 files changed, 0 insertions, 691 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 95f9bdc..e3d24b1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,17 +5,11 @@ lib_LTLIBRARIES = libraul.la
libraul_la_SOURCES = \
Maid.cpp \
- Namespaces.cpp \
Path.cpp \
- RDFWorld.cpp \
SMFReader.cpp \
SMFWriter.cpp \
Thread.cpp
-if WITH_REDLAND
-libraul_la_SOURCES += RDFModel.cpp RDFNode.cpp RDFQuery.cpp
-endif
-
if WITH_JACK
libraul_la_SOURCES += JackDriver.cpp
endif
diff --git a/src/Namespaces.cpp b/src/Namespaces.cpp
deleted file mode 100644
index 3236824..0000000
--- a/src/Namespaces.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-/* This file is part of Raul.
- * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
- *
- * Raul 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.
- *
- * Raul 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 <raul/Namespaces.hpp>
-
-namespace Raul {
-
-
-/** 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.
- */
-std::string
-Namespaces::qualify(std::string uri) const
-{
- for (const_iterator i = begin(); i != 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 Raul
-
diff --git a/src/RDFModel.cpp b/src/RDFModel.cpp
deleted file mode 100644
index 95f6d68..0000000
--- a/src/RDFModel.cpp
+++ /dev/null
@@ -1,262 +0,0 @@
-/* This file is part of Raul.
- * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
- *
- * Raul 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.
- *
- * Raul 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 <sstream>
-#include <raul/RDFWorld.hpp>
-#include <raul/RDFModel.hpp>
-#include <raul/RDFNode.hpp>
-#include <raul/AtomRedland.hpp>
-
-#define U(x) ((const unsigned char*)(x))
-
-using namespace std;
-
-namespace Raul {
-namespace RDF {
-
-
-//static const char* const RDF_LANG = "rdfxml-abbrev";
-static const char* const RDF_LANG = "turtle";
-
-
-/** Create an empty in-memory RDF model.
- */
-Model::Model(RDF::World& world)
- : _world(world)
- , _serialiser(NULL)
-{
- Glib::Mutex::Lock lock(world.mutex());
- _storage = librdf_new_storage(_world.world(), "hashes", NULL, "hash-type='memory'");
- _model = librdf_new_model(_world.world(), _storage, NULL);
-}
-
-
-/** Load a model from a URI (local file or remote).
- */
-Model::Model(World& world, const Glib::ustring& data_uri, Glib::ustring base_uri)
- : _world(world)
- , _serialiser(NULL)
-{
- Glib::Mutex::Lock lock(world.mutex());
- _storage = librdf_new_storage(_world.world(), "hashes", NULL, "hash-type='memory'");
- _model = librdf_new_model(_world.world(), _storage, NULL);
-
- set_base_uri(base_uri);
-
- librdf_uri* uri = librdf_new_uri(world.world(), (const unsigned char*)data_uri.c_str());
-
- if (uri) {
- librdf_parser* parser = librdf_new_parser(world.world(), "guess", NULL, NULL);
- librdf_parser_parse_into_model(parser, uri, _base.get_uri(), _model);
- librdf_free_parser(parser);
- } else {
- cerr << "Unable to create URI " << data_uri << endl;
- }
-
- if (uri)
- librdf_free_uri(uri);
-
- /*cout << endl << "Loaded model from " << data_uri << ":" << endl;
- serialize_to_file_handle(stdout);
- cout << endl << endl;*/
-}
-
-
-Model::~Model()
-{
- Glib::Mutex::Lock lock(_world.mutex());
-
- if (_serialiser)
- librdf_free_serializer(_serialiser);
-
- librdf_free_model(_model);
- librdf_free_storage(_storage);
-}
-
-
-void
-Model::set_base_uri(const Glib::ustring& uri)
-{
- if (uri == "")
- return;
-
- _base = Node(_world, Node::RESOURCE, uri);
-}
-
-
-void
-Model::setup_prefixes()
-{
- assert(_serialiser);
-
- for (Namespaces::const_iterator i = _world.prefixes().begin(); i != _world.prefixes().end(); ++i) {
- librdf_serializer_set_namespace(_serialiser,
- librdf_new_uri(_world.world(), U(i->second.c_str())), i->first.c_str());
- }
-}
-
-
-/** Begin a serialization to a C file handle.
- *
- * This must be called before any write methods.
- */
-void
-Model::serialise_to_file_handle(FILE* fd)
-{
- Glib::Mutex::Lock lock(_world.mutex());
-
- _serialiser = librdf_new_serializer(_world.world(), RDF_LANG, NULL, NULL);
- setup_prefixes();
- librdf_serializer_serialize_model_to_file_handle(_serialiser, fd, NULL, _model);
- librdf_free_serializer(_serialiser);
- _serialiser = NULL;
-}
-
-
-/** Begin a serialization to a file.
- *
- * \a uri must be a local (file://) URI.
- *
- * This must be called before any write methods.
- */
-void
-Model::serialise_to_file(const Glib::ustring& uri_str)
-{
- Glib::Mutex::Lock lock(_world.mutex());
-
- librdf_uri* uri = librdf_new_uri(_world.world(), (const unsigned char*)uri_str.c_str());
- if (uri && librdf_uri_is_file_uri(uri)) {
- _serialiser = librdf_new_serializer(_world.world(), RDF_LANG, NULL, NULL);
- setup_prefixes();
- librdf_serializer_serialize_model_to_file(_serialiser, librdf_uri_to_filename(uri), uri, _model);
- librdf_free_serializer(_serialiser);
- _serialiser = NULL;
- }
- librdf_free_uri(uri);
-}
-
-
-/** Begin a serialization to a string.
- *
- * This must be called before any write methods.
- *
- * The results of the serialization will be returned by the finish() method after
- * the desired objects have been serialized.
- */
-string
-Model::serialise_to_string()
-{
- Glib::Mutex::Lock lock(_world.mutex());
-
- _serialiser = librdf_new_serializer(_world.world(), RDF_LANG, NULL, NULL);
- setup_prefixes();
-
- unsigned char* c_str
- = librdf_serializer_serialize_model_to_string(_serialiser, NULL, _model);
-
- string result((const char*)c_str);
- free(c_str);
-
- librdf_free_serializer(_serialiser);
- _serialiser = NULL;
-
- return result;
-}
-
-
-void
-Model::add_statement(const Node& subject,
- const Node& predicate,
- const Node& object)
-{
- Glib::Mutex::Lock lock(_world.mutex());
-
- assert(subject.get_node());
- assert(predicate.get_node());
- assert(object.get_node());
-
- librdf_statement* triple = librdf_new_statement_from_nodes(_world.world(),
- subject.get_node(), predicate.get_node(), object.get_node());
-
- librdf_model_add_statement(_model, triple);
-}
-
-
-void
-Model::add_statement(const Node& subject,
- const string& predicate_id,
- const Node& object)
-{
- Glib::Mutex::Lock lock(_world.mutex());
-
- const string predicate_uri = _world.expand_uri(predicate_id);
- librdf_node* predicate = librdf_new_node_from_uri_string(_world.world(),
- (const unsigned char*)predicate_uri.c_str());
-
- librdf_statement* triple = librdf_new_statement_from_nodes(_world.world(),
- subject.get_node(), predicate, object.get_node());
-
- librdf_model_add_statement(_model, triple);
-}
-
-
-void
-Model::add_statement(const Node& subject,
- const Node& predicate,
- const Atom& object)
-{
- Glib::Mutex::Lock lock(_world.mutex());
-
- librdf_node* atom_node = AtomRedland::atom_to_rdf_node(_world.world(), object);
-
- if (atom_node) {
- librdf_statement* triple = librdf_new_statement_from_nodes(_world.world(),
- subject.get_node(), predicate.get_node(), atom_node);
- librdf_model_add_statement(_model, triple);
- } else {
- cerr << "WARNING: Unable to add statement (unserializable Atom)" << endl;
- }
-}
-
-
-void
-Model::add_statement(const Node& subject,
- const string& predicate_id,
- const Atom& object)
-{
- Glib::Mutex::Lock lock(_world.mutex());
-
- const string predicate_uri = _world.expand_uri(predicate_id);
- librdf_node* predicate = librdf_new_node_from_uri_string(_world.world(),
- (const unsigned char*)predicate_uri.c_str());
-
- librdf_node* atom_node = AtomRedland::atom_to_rdf_node(_world.world(), object);
-
- if (atom_node) {
- librdf_statement* triple = librdf_new_statement_from_nodes(_world.world(),
- subject.get_node(), predicate, atom_node);
- librdf_model_add_statement(_model, triple);
- } else {
- cerr << "WARNING: Unable to add statement (unserializable Atom)" << endl;
- }
-}
-
-
-
-} // namespace RDF
-} // namespace Raul
-
diff --git a/src/RDFNode.cpp b/src/RDFNode.cpp
deleted file mode 100644
index 4bc1fbb..0000000
--- a/src/RDFNode.cpp
+++ /dev/null
@@ -1,187 +0,0 @@
-/* This file is part of Raul.
- * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
- *
- * Raul 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.
- *
- * Raul 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 <string>
-#include <iostream>
-#include <raul/RDFWorld.hpp>
-#include <raul/RDFNode.hpp>
-
-using namespace std;
-
-namespace Raul {
-namespace RDF {
-
-
-Node::Node(World& world, Type type, const std::string& s)
- : _world(&world)
-{
- Glib::Mutex::Lock lock(world.mutex(), Glib::TRY_LOCK);
-
- if (type == RESOURCE) {
- const string uri = world.expand_uri(s);
- _node = librdf_new_node_from_uri_string(world.world(), (const unsigned char*)uri.c_str());
- } else if (type == LITERAL) {
- _node = librdf_new_node_from_literal(world.world(), (const unsigned char*)s.c_str(), NULL, 0);
- } else if (type == BLANK) {
- _node = librdf_new_node_from_blank_identifier(world.world(), (const unsigned char*)s.c_str());
- } else {
- _node = NULL;
- }
-
- assert(this->type() == type);
- assert(_world);
-}
-
-
-Node::Node(World& world)
- : _world(&world)
-{
- Glib::Mutex::Lock lock(world.mutex(), Glib::TRY_LOCK);
- _node = librdf_new_node(world.world());
- assert(_world);
-}
-
-
-Node::Node(World& world, librdf_node* node)
- : _world(&world)
-{
- Glib::Mutex::Lock lock(world.mutex(), Glib::TRY_LOCK);
- _node = librdf_new_node_from_node(node);
- assert(_world);
-}
-
-
-Node::Node(const Node& other)
- : _world(other.world())
- , _node(NULL)
-{
- if (_world) {
- Glib::Mutex::Lock lock(_world->mutex(), Glib::TRY_LOCK);
- _node = (other._node ? librdf_new_node_from_node(other._node) : NULL);
- }
-
- assert(to_string() == other.to_string());
-}
-
-
-Node::~Node()
-{
- if (_world) {
- Glib::Mutex::Lock lock(_world->mutex(), Glib::TRY_LOCK);
- if (_node)
- librdf_free_node(_node);
- }
-}
-
-
-string
-Node::to_string() const
-{
- const Type type = this->type();
- if (type == RESOURCE) {
- assert(librdf_node_get_uri(_node));
- return string((const char*)librdf_uri_as_string(librdf_node_get_uri(_node)));
- } else if (type == LITERAL) {
- return string((const char*)librdf_node_get_literal_value(_node));
- } else if (type == BLANK) {
- return string((const char*)librdf_node_get_blank_identifier(_node));
- } else {
- return "";
- }
-}
-
-
-string
-Node::to_quoted_uri_string() const
-{
- assert(type() == RESOURCE);
- assert(librdf_node_get_uri(_node));
- string str = "<";
- str.append((const char*)librdf_uri_as_string(librdf_node_get_uri(_node)));
- str.append(">");
- return str;
-}
-
-
-bool
-Node::is_int() const
-{
- if (_node && librdf_node_get_type(_node) == LIBRDF_NODE_TYPE_LITERAL) {
- librdf_uri* datatype_uri = librdf_node_get_literal_value_datatype_uri(_node);
- if (datatype_uri && !strcmp((const char*)librdf_uri_as_string(datatype_uri),
- "http://www.w3.org/2001/XMLSchema#integer"))
- return true;
- }
- return false;
-}
-
-
-int
-Node::to_int() const
-{
- assert(is_int());
- return strtol((const char*)librdf_node_get_literal_value(_node), NULL, 10);
-}
-
-
-bool
-Node::is_float() const
-{
- if (_node && librdf_node_get_type(_node) == LIBRDF_NODE_TYPE_LITERAL) {
- librdf_uri* datatype_uri = librdf_node_get_literal_value_datatype_uri(_node);
- if (datatype_uri && !strcmp((const char*)librdf_uri_as_string(datatype_uri),
- "http://www.w3.org/2001/XMLSchema#decimal"))
- return true;
- }
- return false;
-}
-
-
-float
-Node::to_float() const
-{
- assert(is_float());
- return strtod((const char*)librdf_node_get_literal_value(_node), NULL);
-}
-
-bool
-Node::is_bool() const
-{
- if (_node && librdf_node_get_type(_node) == LIBRDF_NODE_TYPE_LITERAL) {
- librdf_uri* datatype_uri = librdf_node_get_literal_value_datatype_uri(_node);
- if (datatype_uri && !strcmp((const char*)librdf_uri_as_string(datatype_uri),
- "http://www.w3.org/2001/XMLSchema#boolean"))
- return true;
- }
- return false;
-}
-
-
-float
-Node::to_bool() const
-{
- assert(is_bool());
- if (!strcmp((const char*)librdf_node_get_literal_value(_node), "true"))
- return true;
- else
- return false;
-}
-
-
-} // namespace RDF
-} // namespace Raul
-
diff --git a/src/RDFQuery.cpp b/src/RDFQuery.cpp
deleted file mode 100644
index 41aa918..0000000
--- a/src/RDFQuery.cpp
+++ /dev/null
@@ -1,89 +0,0 @@
-/* This file is part of Raul.
- * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
- *
- * Raul 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.
- *
- * Raul 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 <raul/RDFQuery.hpp>
-#include <raul/RDFModel.hpp>
-
-using namespace std;
-
-namespace Raul {
-namespace RDF {
-
-
-Query::Results
-Query::run(World& world, Model& model, const Glib::ustring base_uri_str) const
-{
- Glib::Mutex::Lock lock(world.mutex());
-
- //cout << "\n**************** QUERY *******************\n";
- //cout << _query << endl;
- //cout << "******************************************\n\n";
-
- Results result;
-
- librdf_uri* base_uri = NULL;
- if (base_uri_str != "")
- base_uri = librdf_new_uri(world.world(),
- (const unsigned char*)base_uri_str.c_str());
-
- librdf_query* q = librdf_new_query(world.world(), "sparql",
- NULL, (unsigned char*)_query.c_str(), base_uri);
-
- if (!q) {
- cerr << "Unable to create query:" << endl << _query << endl;
- return result; /* Return an empty Results */
- }
-
- librdf_query_results* results = librdf_query_execute(q, model._model);
-
- if (!results) {
- cerr << "Failed query:" << endl << _query << endl;
- return result; /* Return an empty Results */
- }
-
- while (!librdf_query_results_finished(results)) {
-
- Bindings bindings;
-
- for (int i=0; i < librdf_query_results_get_bindings_count(results); i++) {
- const char* name = (char*)librdf_query_results_get_binding_name(results, i);
- librdf_node* value = librdf_query_results_get_binding_value(results, i);
-
- if (name && value)
- bindings.insert(std::make_pair(std::string(name), Node(world, value)));
- }
-
- result.push_back(bindings);
- librdf_query_results_next(results);
- }
-
- librdf_free_query_results(results);
- librdf_free_query(q);
-
- if (base_uri)
- librdf_free_uri(base_uri);
-
- return result;
-}
-
-
-} // namespace RDF
-} // namespace Raul
-
diff --git a/src/RDFWorld.cpp b/src/RDFWorld.cpp
deleted file mode 100644
index 5420274..0000000
--- a/src/RDFWorld.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-/* This file is part of Raul.
- * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
- *
- * Raul 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.
- *
- * Raul 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 <sstream>
-#include <raul/RDFWorld.hpp>
-#include <raul/RDFNode.hpp>
-#include <raul/AtomRedland.hpp>
-
-#define U(x) ((const unsigned char*)(x))
-
-using namespace std;
-
-namespace Raul {
-namespace RDF {
-
-
-//static const char* const RDF_LANG = "rdfxml-abbrev";
-static const char* const RDF_LANG = "turtle";
-
-
-/** Create an empty in-memory RDF model.
- */
-World::World()
- : _next_blank_id(1)
-{
- _world = librdf_new_world();
- assert(_world);
- librdf_world_open(_world);
-
- add_prefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
-}
-
-
-World::~World()
-{
- Glib::Mutex::Lock lock(_mutex);
- librdf_free_world(_world);
-}
-
-
-void
-World::add_prefix(const string& prefix, const string& uri)
-{
- _prefixes[prefix] = uri;
-}
-
-
-/** Expands the prefix of URI, if the prefix is registered.
- */
-string
-World::expand_uri(const string& uri) const
-{
- if (uri.find(":") == string::npos)
- return uri;
-
- for (Namespaces::const_iterator i = _prefixes.begin(); i != _prefixes.end(); ++i)
- if (uri.substr(0, i->first.length()+1) == i->first + ":")
- return i->second + uri.substr(i->first.length()+1);
-
- return uri;
-}
-
-
-/** Opposite of expand_uri
- */
-string
-World::qualify(const string& uri) const
-{
- return _prefixes.qualify(uri);
-}
-
-
-Node
-World::blank_id(const string base_name)
-{
- std::ostringstream ss;
- ss << "b" << _next_blank_id++;
-
- if (base_name != "")
- ss << "_" << base_name;
-
- Node result = Node(*this, Node::BLANK, ss.str());
- assert(result.to_string() == ss.str());
- return result;
-}
-
-
-} // namespace RDF
-} // namespace Raul
-