diff options
-rw-r--r-- | slv2/value.h | 21 | ||||
-rw-r--r-- | src/plugin.c | 12 | ||||
-rw-r--r-- | src/slv2_internal.h | 1 | ||||
-rw-r--r-- | src/value.c | 26 | ||||
-rw-r--r-- | utils/lv2_inspect.c | 46 | ||||
-rw-r--r-- | wscript | 5 |
6 files changed, 72 insertions, 39 deletions
diff --git a/slv2/value.h b/slv2/value.h index fcb3143..86be450 100644 --- a/slv2/value.h +++ b/slv2/value.h @@ -124,6 +124,27 @@ const char* slv2_value_as_uri(SLV2Value value); +/** Return whether the value is a blank node (resource with no URI). + * + * Time = O(1) + */ +SLV2_API +bool +slv2_value_is_blank(SLV2Value value); + + +/** Return this value as a blank node identifier, e.g. "genid03". + * + * Valid to call only if slv2_value_is_blank(\a value) returns true. + * Returned value is owned by \a value and must not be freed by caller. + * + * Time = O(1) + */ +SLV2_API +const char* +slv2_value_as_blank(SLV2Value value); + + /** Return whether this value is a literal (i.e. not a URI). * * Returns true if \a value is a string or numeric value. 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 diff --git a/utils/lv2_inspect.c b/utils/lv2_inspect.c index d6b8948..b8a5c57 100644 --- a/utils/lv2_inspect.c +++ b/utils/lv2_inspect.c @@ -28,6 +28,8 @@ SLV2Value event_class = NULL; SLV2Value control_class = NULL; SLV2Value in_group_pred = NULL; SLV2Value role_pred = NULL; +SLV2Value preset_pred = NULL; +SLV2Value title_pred = NULL; void print_group(SLV2Plugin p, SLV2Value group, SLV2Value type, SLV2Value symbol) @@ -236,41 +238,19 @@ print_plugin(SLV2Plugin p) /* Presets */ - SLV2Results presets = slv2_plugin_query_sparql(p, "\ -PREFIX lv2p: <http://lv2plug.in/ns/ext/presets#> \ -PREFIX dc: <http://dublincore.org/documents/dcmi-namespace/> \ -SELECT ?name WHERE { <> lv2p:hasPreset ?preset . ?preset dc:title ?name }"); - if (!slv2_results_finished(presets)) + SLV2Values presets = slv2_plugin_get_value(p, preset_pred); + if (presets) printf("\tPresets: \n"); - for (; !slv2_results_finished(presets); slv2_results_next(presets)) { - SLV2Value name = slv2_results_get_binding_value(presets, 0); - printf("\t %s\n", slv2_value_as_string(name)); - slv2_value_free(name); - } - slv2_results_free(presets); - - - /* Groups */ - - SLV2Results groups = slv2_plugin_query_sparql(p, "\ -PREFIX pg: <http://lv2plug.in/ns/ext/port-groups#> \ -PREFIX dc: <http://dublincore.org/documents/dcmi-namespace/> \ -SELECT DISTINCT ?group ?type ?sym WHERE {\n" -" <> lv2:port ?port .\n" -" ?port pg:inGroup ?group .\n" -" ?group rdf:type ?type ;\n" -" lv2:symbol ?sym .\n" -"FILTER(?type != pg:Group)\n" -"}"); - for (; !slv2_results_finished(groups); slv2_results_next(groups)) { - SLV2Value group = slv2_results_get_binding_value(groups, 0); - SLV2Value type = slv2_results_get_binding_value(groups, 1); - SLV2Value symbol = slv2_results_get_binding_value(groups, 2); - print_group(p, group, type, symbol); + for (unsigned i=0; i < slv2_values_size(presets); ++i) { + SLV2Values titles = slv2_plugin_get_value_for_subject( + p, slv2_values_get_at(presets, i), title_pred); + if (titles) { + SLV2Value title = slv2_values_get_at(titles, 0); + printf("\t %s\n", slv2_value_as_string(title)); + } } - slv2_results_free(groups); - + /* Ports */ const uint32_t num_ports = slv2_plugin_get_num_ports(p); @@ -322,6 +302,8 @@ main(int argc, char** argv) control_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_CONTROL); in_group_pred = slv2_value_new_uri(world, "http://lv2plug.in/ns/ext/port-groups#inGroup"); role_pred = slv2_value_new_uri(world, "http://lv2plug.in/ns/ext/port-groups#role"); + preset_pred = slv2_value_new_uri(world, "http://lv2plug.in/ns/dev/presets#hasPreset"); + title_pred = slv2_value_new_uri(world, "http://dublincore.org/documents/dcmi-namespace/title"); if (argc != 2) { print_usage(); @@ -3,7 +3,7 @@ import autowaf import Options # Version of this package (even if built as a child) -SLV2_VERSION = '0.6.7' +SLV2_VERSION = '0.6.8' # Library version (UNIX style major, minor, micro) # major increment <=> incompatible changes @@ -28,8 +28,7 @@ SLV2_VERSION = '0.6.7' # 0.6.2 = 9,1,1 # 0.6.4 = 9,2,0 # 0.6.6 = 9,2,0 -# 0.6.7 = 9,2,1 -SLV2_LIB_VERSION = '9.2.1' +SLV2_LIB_VERSION = '9.3.0' # Variables for 'waf dist' APPNAME = 'slv2' |