diff options
author | David Robillard <d@drobilla.net> | 2010-11-07 18:48:33 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-11-07 18:48:33 +0000 |
commit | b2a6a6bc73951de0f3ef8507879b5c3613d13795 (patch) | |
tree | ba01de0718d6e817d58c514f094a58565fc282bb | |
parent | 3751974508aaaefb21460b0d92d9edc132db66ab (diff) | |
download | lilv-b2a6a6bc73951de0f3ef8507879b5c3613d13795.tar.gz lilv-b2a6a6bc73951de0f3ef8507879b5c3613d13795.tar.bz2 lilv-b2a6a6bc73951de0f3ef8507879b5c3613d13795.zip |
Don't use SPARQL for slv2_plugin_get_value_for_subject.
Use slv2_plugin_get_value_for_subject to implement slv2_plugin_get_value (don't duplicate code).
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2669 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | src/plugin.c | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/src/plugin.c b/src/plugin.c index 9faced8..226c138 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -426,32 +426,7 @@ SLV2Values slv2_plugin_get_value(SLV2Plugin p, SLV2Value predicate) { - // <plugin> <predicate> ?value - librdf_stream* results = slv2_plugin_find_statements( - p, - librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val), - librdf_new_node_from_uri(p->world->world, predicate->val.uri_val), - NULL); - - if (librdf_stream_end(results)) { - librdf_free_stream(results); - return NULL; - } - - SLV2Values result = slv2_values_new(); - while (!librdf_stream_end(results)) { - librdf_statement* s = librdf_stream_get_object(results); - librdf_node* value_node = librdf_statement_get_object(s); - - SLV2Value value = slv2_value_new_librdf_node(p->world, value_node); - if (value) - raptor_sequence_push(result, value); - - librdf_stream_next(results); - } - - librdf_free_stream(results); - return result; + return slv2_plugin_get_value_for_subject(p, p->plugin_uri, predicate); } @@ -499,21 +474,36 @@ slv2_plugin_get_value_for_subject(SLV2Plugin p, SLV2_ERROR("Subject is not a URI\n"); return NULL; } + if ( ! slv2_value_is_uri(predicate)) { + SLV2_ERROR("Subject is not a URI\n"); + return NULL; + } - char* subject_token = slv2_value_get_turtle_token(subject); + // <subject> <predicate> ?value + librdf_stream* results = slv2_plugin_find_statements( + p, + librdf_new_node_from_uri(p->world->world, subject->val.uri_val), + librdf_new_node_from_uri(p->world->world, predicate->val.uri_val), + NULL); - /* Hack around broken RASQAL, full URI predicates don't work :/ */ - char* query = slv2_strjoin( - "PREFIX slv2predicate: <", slv2_value_as_string(predicate), ">\n", - "SELECT DISTINCT ?value WHERE {\n", - subject_token, " slv2predicate: ?value .\n" - "}\n", NULL); + if (librdf_stream_end(results)) { + librdf_free_stream(results); + return NULL; + } - SLV2Values result = slv2_plugin_query_variable(p, query, 0); + SLV2Values result = slv2_values_new(); + while (!librdf_stream_end(results)) { + librdf_statement* s = librdf_stream_get_object(results); + librdf_node* value_node = librdf_statement_get_object(s); - free(query); - free(subject_token); + SLV2Value value = slv2_value_new_librdf_node(p->world, value_node); + if (value) + raptor_sequence_push(result, value); + librdf_stream_next(results); + } + + librdf_free_stream(results); return result; } |