summaryrefslogtreecommitdiffstats
path: root/src/query.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-01-30 03:59:36 +0000
committerDavid Robillard <d@drobilla.net>2011-01-30 03:59:36 +0000
commitaa524702008b30123be3044b45a526de84312cff (patch)
treedabc77655b4eced180ab4488c881c39c16cf48af /src/query.c
parent110e2b17943eadd4175cc9bf0cbb96e36789e5e5 (diff)
downloadlilv-aa524702008b30123be3044b45a526de84312cff.tar.gz
lilv-aa524702008b30123be3044b45a526de84312cff.tar.bz2
lilv-aa524702008b30123be3044b45a526de84312cff.zip
Non-SPARQL versions of slv2_port_get_value_by_qname, slv2_port_get_value_by_qname_i18n, and svn_port_get_value.
Gracefully handle invalid predicates in slv2_plugin_get_value_by_qname. 2 queries left... git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2866 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/query.c')
-rw-r--r--src/query.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/query.c b/src/query.c
index aebc87b..3fb0ce9 100644
--- a/src/query.c
+++ b/src/query.c
@@ -205,6 +205,7 @@ slv2_plugin_query_count(SLV2Plugin plugin,
return ret;
}
+
librdf_stream*
slv2_plugin_find_statements(SLV2Plugin plugin,
librdf_node* subject,
@@ -218,3 +219,44 @@ slv2_plugin_find_statements(SLV2Plugin plugin,
librdf_free_statement(q);
return results;
}
+
+
+SLV2Values
+slv2_values_from_stream_i18n(SLV2Plugin p,
+ librdf_stream* stream)
+{
+ SLV2Values values = slv2_values_new();
+ librdf_node* nolang = NULL;
+ for (; !librdf_stream_end(stream); librdf_stream_next(stream)) {
+ librdf_statement* s = librdf_stream_get_object(stream);
+ librdf_node* value = librdf_statement_get_object(s);
+ if (librdf_node_is_literal(value)) {
+ const char* lang = librdf_node_get_literal_value_language(value);
+ if (lang) {
+ if (!strcmp(lang, slv2_get_lang())) {
+ raptor_sequence_push(
+ values, slv2_value_new_string(
+ p->world, (const char*)librdf_node_get_literal_value(value)));
+ }
+ } else {
+ nolang = value;
+ }
+ }
+ break;
+ }
+ librdf_free_stream(stream);
+
+ if (slv2_values_size(values) == 0) {
+ // No value with a matching language, use untranslated default
+ if (nolang) {
+ raptor_sequence_push(
+ values, slv2_value_new_string(
+ p->world, (const char*)librdf_node_get_literal_value(nolang)));
+ } else {
+ slv2_values_free(values);
+ values = NULL;
+ }
+ }
+
+ return values;
+}