summaryrefslogtreecommitdiffstats
path: root/src/query.c
diff options
context:
space:
mode:
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;
+}