diff options
author | David Robillard <d@drobilla.net> | 2011-01-30 21:27:39 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-01-30 21:27:39 +0000 |
commit | 23ef7a21c277ba5e864748d8e61ff3e20054758f (patch) | |
tree | 1f2b2fae3e84b48b0fd2739b6f5a3dba5ed80c35 /src | |
parent | 2c17ab25b34cdada738182daf72607eaa2d3673e (diff) | |
download | lilv-23ef7a21c277ba5e864748d8e61ff3e20054758f.tar.gz lilv-23ef7a21c277ba5e864748d8e61ff3e20054758f.tar.bz2 lilv-23ef7a21c277ba5e864748d8e61ff3e20054758f.zip |
Add blank node type for value, to allow the user to 'join' statement
queries on blank node values with the simple get_value functions.
Remove use of SPARQL from lv2_inspect.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2874 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/plugin.c | 12 | ||||
-rw-r--r-- | src/slv2_internal.h | 1 | ||||
-rw-r--r-- | src/value.c | 26 |
3 files changed, 35 insertions, 4 deletions
diff --git a/src/plugin.c b/src/plugin.c index 45177e1..a7e211e 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -522,8 +522,8 @@ slv2_plugin_get_value_for_subject(SLV2Plugin p, SLV2Value subject, SLV2Value predicate) { - if ( ! slv2_value_is_uri(subject)) { - SLV2_ERROR("Subject is not a URI\n"); + if ( ! slv2_value_is_uri(subject) && ! slv2_value_is_blank(subject)) { + SLV2_ERROR("Subject is not a resource\n"); return NULL; } if ( ! slv2_value_is_uri(predicate)) { @@ -531,9 +531,15 @@ slv2_plugin_get_value_for_subject(SLV2Plugin p, return NULL; } + librdf_node* subject_node = (slv2_value_is_uri(subject)) + ? librdf_new_node_from_uri( + p->world->world, subject->val.uri_val) + : librdf_new_node_from_blank_identifier( + p->world->world, (const uint8_t*)slv2_value_as_blank(subject)); + return slv2_plugin_query_node( p, - librdf_new_node_from_uri(p->world->world, subject->val.uri_val), + subject_node, librdf_new_node_from_uri(p->world->world, predicate->val.uri_val)); } diff --git a/src/slv2_internal.h b/src/slv2_internal.h index 08d223f..af748bb 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -242,6 +242,7 @@ typedef enum _SLV2ValueType { SLV2_VALUE_STRING, SLV2_VALUE_INT, SLV2_VALUE_FLOAT, + SLV2_VALUE_BLANK } SLV2ValueType; struct _SLV2Value { diff --git a/src/value.c b/src/value.c index d9e8a9c..819e5fe 100644 --- a/src/value.c +++ b/src/value.c @@ -37,6 +37,7 @@ slv2_value_set_numerics_from_string(SLV2Value val) switch (val->type) { case SLV2_VALUE_URI: + case SLV2_VALUE_BLANK: case SLV2_VALUE_QNAME_UNUSED: case SLV2_VALUE_STRING: break; @@ -79,6 +80,7 @@ slv2_value_new(SLV2World world, SLV2ValueType type, const char* str) val->str_val = (char*)librdf_uri_as_string(val->val.uri_val); break; case SLV2_VALUE_QNAME_UNUSED: + case SLV2_VALUE_BLANK: case SLV2_VALUE_STRING: case SLV2_VALUE_INT: case SLV2_VALUE_FLOAT: @@ -117,6 +119,7 @@ slv2_value_new_librdf_node(SLV2World world, librdf_node* node) result = slv2_value_new(world, type, (const char*)librdf_node_get_literal_value(node)); switch (result->type) { case SLV2_VALUE_URI: + case SLV2_VALUE_BLANK: case SLV2_VALUE_STRING: case SLV2_VALUE_QNAME_UNUSED: break; @@ -126,7 +129,7 @@ slv2_value_new_librdf_node(SLV2World world, librdf_node* node) } break; case LIBRDF_NODE_TYPE_BLANK: - type = SLV2_VALUE_STRING; + type = SLV2_VALUE_BLANK; result = slv2_value_new(world, type, (const char*)librdf_node_get_blank_identifier(node)); break; case LIBRDF_NODE_TYPE_UNKNOWN: @@ -236,6 +239,7 @@ slv2_value_equals(SLV2Value value, SLV2Value other) switch (value->type) { case SLV2_VALUE_URI: return (librdf_uri_equals(value->val.uri_val, other->val.uri_val) != 0); + case SLV2_VALUE_BLANK: case SLV2_VALUE_STRING: case SLV2_VALUE_QNAME_UNUSED: return ! strcmp(value->str_val, other->str_val); @@ -262,6 +266,11 @@ slv2_value_get_turtle_token(SLV2Value value) result = calloc(len, 1); snprintf(result, len, "<%s>", value->str_val); break; + case SLV2_VALUE_BLANK: + len = strlen(value->str_val) + 3; + result = calloc(len, 1); + snprintf(result, len, "_:%s", value->str_val); + break; case SLV2_VALUE_STRING: case SLV2_VALUE_QNAME_UNUSED: result = strdup(value->str_val); @@ -318,6 +327,21 @@ slv2_value_as_librdf_uri(SLV2Value value) bool +slv2_value_is_blank(SLV2Value value) +{ + return (value && value->type == SLV2_VALUE_BLANK); +} + + +const char* +slv2_value_as_blank(SLV2Value value) +{ + assert(slv2_value_is_blank(value)); + return value->str_val; +} + + +bool slv2_value_is_literal(SLV2Value value) { // No blank nodes |