From 824a8c52a42300b1622fad16d7211984a2d518d6 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 29 Jan 2011 21:15:28 +0000 Subject: Non-SPARQL version of slv2_plugin_get_value_by_qname_i18n. git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2858 a436a847-0d15-0410-975c-d299462d15a1 --- src/plugin.c | 56 ++++++++++++++++++++++++++++++++++++++++------------- src/slv2_internal.h | 4 ++-- src/util.c | 2 +- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index ffd2319..7fb6e35 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -519,11 +519,11 @@ SLV2Values slv2_plugin_get_value_by_qname(SLV2Plugin p, const char* predicate) { - char* predicate_uri = slv2_qname_expand(p, predicate); - SLV2Value predicate_value = slv2_value_new_uri(p->world, predicate_uri); - SLV2Values ret = slv2_plugin_get_value(p, predicate_value); - slv2_value_free(predicate_value); - free(predicate_uri); + char* pred_uri = slv2_qname_expand(p, predicate); + SLV2Value pred_value = slv2_value_new_uri(p->world, pred_uri); + SLV2Values ret = slv2_plugin_get_value(p, pred_value); + slv2_value_free(pred_value); + free(pred_uri); return ret; } @@ -532,16 +532,46 @@ SLV2Values slv2_plugin_get_value_by_qname_i18n(SLV2Plugin p, const char* predicate) { - char* query = slv2_strjoin( - "SELECT DISTINCT ?value WHERE { \n" - "<> ", predicate, " ?value . \n" - "FILTER(lang(?value) = \"", slv2_get_lang(), "\") \n" - "}\n", NULL); - - SLV2Values result = slv2_plugin_query_variable(p, query, 0); + char* pred_uri = slv2_qname_expand(p, predicate); + librdf_node* pred_node = librdf_new_node_from_uri_string(p->world->world, + (const uint8_t*)pred_uri); + SLV2Values result = slv2_values_new(); + librdf_node* nolang = NULL; + librdf_stream* results = slv2_plugin_find_statements( + p, + librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val), + pred_node, + NULL); + for (; !librdf_stream_end(results); librdf_stream_next(results)) { + librdf_statement* s = librdf_stream_get_object(results); + librdf_node* value = librdf_statement_get_object(s); + + const char* lang = librdf_node_get_literal_value_language(value); + if (lang) { + if (!strcmp(lang, slv2_get_lang())) { + raptor_sequence_push( + result, slv2_value_new_string( + p->world, (const char*)librdf_node_get_literal_value(value))); + } + } else { + nolang = value; + } + break; + } + librdf_free_stream(results); - free(query); + free(pred_uri); + if (slv2_values_size(result) == 0) { + if (nolang) { + raptor_sequence_push( + result, slv2_value_new_string( + p->world, (const char*)librdf_node_get_literal_value(nolang))); + } else { + slv2_values_free(result); + result = NULL; + } + } return result; } diff --git a/src/slv2_internal.h b/src/slv2_internal.h index 9ba8606..adf9e8b 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -268,8 +268,8 @@ struct _SLV2Results { /* ********* Utilities ********* */ -char* slv2_strjoin(const char* first, ...); -char* slv2_get_lang(); +char* slv2_strjoin(const char* first, ...); +const char* slv2_get_lang(); /* ********* Dynamic Manifest ********* */ diff --git a/src/util.c b/src/util.c index fbf9966..92811c8 100644 --- a/src/util.c +++ b/src/util.c @@ -63,7 +63,7 @@ slv2_uri_to_path(const char* uri) } -char* +const char* slv2_get_lang() { static char lang[32]; -- cgit v1.2.1