From bb7e9e97c5b89bcd646ac7bae6c7bf69ace9fc8a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 15 Feb 2011 21:31:51 +0000 Subject: Remove SPARQL query stuff from Redlandmm. git-svn-id: http://svn.drobilla.net/lad/trunk/machina@2951 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/Loader.cpp | 123 ++++++++++++++++++++++---------------------------- 1 file changed, 55 insertions(+), 68 deletions(-) (limited to 'src/engine') diff --git a/src/engine/Loader.cpp b/src/engine/Loader.cpp index 2698491..070615a 100644 --- a/src/engine/Loader.cpp +++ b/src/engine/Loader.cpp @@ -34,6 +34,9 @@ using namespace Raul; using namespace std; +#define NS_MACHINA "http://drobilla.net/ns/machina#" +#define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#" + namespace Machina { @@ -53,8 +56,6 @@ Loader::Loader(Redland::World& rdf_world) SharedPtr Loader::load(const Glib::ustring& uri) { - using Redland::Query; - using Redland::QueryResults; using Glib::ustring; SharedPtr machine; @@ -82,74 +83,62 @@ Loader::load(const Glib::ustring& uri) machine = SharedPtr(new Machine(TimeUnit::beats(MACHINA_PPQN))); - typedef std::map > Created; + typedef std::map > Created; Created created; Redland::Model model(_rdf_world, document_uri); - /* Get initial nodes */ + Redland::Node nil; - Query query = Query(_rdf_world, ustring( - "SELECT DISTINCT ?node ?duration WHERE {\n") + - machine_uri + " :initialNode ?node .\n" - "?node :duration ?duration .\n" - "}\n"); + Redland::Resource rdf_type(_rdf_world, NS_RDF "type"); + Redland::Resource machina_SelectorNode(_rdf_world, NS_MACHINA "initialNode"); + Redland::Resource machina_node(_rdf_world, NS_MACHINA "node"); + Redland::Resource machina_initialNode(_rdf_world, NS_MACHINA "initialNode"); + Redland::Resource machina_duration(_rdf_world, NS_MACHINA "duration"); + Redland::Resource machina_edge(_rdf_world, NS_MACHINA "edge"); + Redland::Resource machina_tail(_rdf_world, NS_MACHINA "tail"); + Redland::Resource machina_head(_rdf_world, NS_MACHINA "head"); + Redland::Resource machina_probability(_rdf_world, NS_MACHINA "probability"); - SharedPtr results = query.run(_rdf_world, model); + Redland::Node machine_node = Redland::Resource(_rdf_world, "."); - for (; !results->finished(); results->next()) { - const char* node_id = results->get("node"); + /* Get initial nodes */ + for (Redland::Iter i = model.find(machine_node, machina_initialNode, nil); + !i.end(); ++i) { + const Redland::Node& node_id = i.get_object(); + Redland::Iter d = model.find(node_id, machina_duration, nil); SharedPtr node( new Node( - TimeStamp(TimeUnit(TimeUnit::BEATS, MACHINA_PPQN), results->get("duration").to_float()), + TimeStamp(TimeUnit(TimeUnit::BEATS, MACHINA_PPQN), + d.get_object().to_float()), true)); + + Redland::Iter s = model.find(node_id, rdf_type, machina_SelectorNode); + if (!s.end()) { + node->set_selector(true); + } + machine->add_node(node); created[node_id] = node; } - /* Get remaining (non-initial) nodes */ - - query = Query(_rdf_world, ustring( - "SELECT DISTINCT ?node ?duration WHERE {\n") + - machine_uri + " :node ?node .\n" - "?node :duration ?duration .\n" - "}\n"); - - results = query.run(_rdf_world, model); - - for (; !results->finished(); results->next()) { - const char* node_id = results->get("node"); + for (Redland::Iter i = model.find(machine_node, machina_node, nil); + !i.end(); ++i) { + const Redland::Node& node_id = i.get_object(); + Redland::Iter d = model.find(node_id, machina_duration, nil); if (created.find(node_id) == created.end()) { SharedPtr node(new Node( - TimeStamp(TimeUnit(TimeUnit::BEATS, MACHINA_PPQN), results->get("duration").to_float()), + TimeStamp(TimeUnit(TimeUnit::BEATS, MACHINA_PPQN), + d.get_object().to_float()), false)); machine->add_node(node); created[node_id] = node; } } - - /* Find out which nodes are selectors */ - - query = Query(_rdf_world, ustring( - "SELECT DISTINCT ?node WHERE {\n") + - machine_uri + " :node ?node .\n" - "?node a :SelectorNode .\n" - "}\n"); - - results = query.run(_rdf_world, model); - - for (; !results->finished(); results->next()) { - const char* node_id = results->get("node"); - Created::iterator n = created.find(node_id); - if (n != created.end()) - n->second->set_selector(true); - else - cerr << "WARNING: Selector node " << node_id << " not found" << endl; - } - - +#if 0 + cerr << "FIXME: Load actions" << endl; /* Get note actions */ query = Query(_rdf_world, ustring( @@ -174,38 +163,36 @@ Loader::load(const Glib::ustring& uri) cerr << "WARNING: Found note for unknown states. Ignoring." << endl; } } - +#endif /* Get edges */ + for (Redland::Iter i = model.find(machine_node, machina_edge, nil); + !i.end(); ++i) { + Redland::Node edge = i.get_object(); + Redland::Iter t = model.find(edge, machina_tail, nil); + Redland::Iter h = model.find(edge, machina_head, nil); + Redland::Iter p = model.find(edge, machina_probability, nil); - query = Query(_rdf_world, ustring( - "SELECT DISTINCT ?edge ?src ?dst ?prob WHERE {\n" + - machine_uri + " :edge ?edge .\n" - "?edge :tail ?src ;\n" - " :head ?dst ;\n" - " :probability ?prob .\n }")); + Redland::Node tail = t.get_object(); + Redland::Node head = h.get_object(); + Redland::Node probability = p.get_object(); - results = query.run(_rdf_world, model); - - for (; !results->finished(); results->next()) { - const char* src_uri = results->get("src"); - const char* dst_uri = results->get("dst"); - float prob = results->get("prob").to_float(); + float prob = probability.to_float(); - Created::iterator src_i = created.find(src_uri); - Created::iterator dst_i = created.find(dst_uri); + Created::iterator tail_i = created.find(tail); + Created::iterator head_i = created.find(head); - if (src_i != created.end() && dst_i != created.end()) { - const SharedPtr src = src_i->second; - const SharedPtr dst = dst_i->second; + if (tail_i != created.end() && head_i != created.end()) { + const SharedPtr tail = tail_i->second; + const SharedPtr head = head_i->second; - SharedPtr edge(new Edge(src, dst)); + SharedPtr edge(new Edge(tail, head)); edge->set_probability(prob); - src->add_edge(edge); + tail->add_edge(edge); } else { cerr << "[Loader] WARNING: Ignored edge between unknown nodes " - << src_uri << " -> " << dst_uri << endl; + << tail << " -> " << head << endl; } } -- cgit v1.2.1