LilvUI* lilv_ui_new(LilvWorld* world, LilvNode* uri, LilvNode* type_uri, LilvNode* binary_uri) { assert(uri); assert(type_uri); assert(binary_uri); LilvUI* ui = (LilvUI*)malloc(sizeof(LilvUI)); ui->world = world; ui->uri = uri; ui->binary_uri = binary_uri; // FIXME: kludge char* bundle = lilv_strdup(lilv_node_as_string(ui->binary_uri)); char* last_slash = strrchr(bundle, '/') + 1; *last_slash = '\0'; ui->bundle_uri = lilv_new_uri(world, bundle); free(bundle); ui->classes = lilv_nodes_new(); zix_tree_insert((ZixTree*)ui->classes, type_uri, NULL); return ui; }
LilvPort* lilv_port_new(LilvWorld* world, const SordNode* node, uint32_t index, const char* symbol) { LilvPort* port = (LilvPort*)malloc(sizeof(LilvPort)); port->node = sord_node_copy(node); port->index = index; port->symbol = lilv_node_new(world, LILV_VALUE_STRING, symbol); port->classes = lilv_nodes_new(); return port; }
LILV_API LilvNodes* lilv_ui_get_supported_features(const LilvUI* ui) { LilvNodes* optional = lilv_ui_get_optional_features(ui); LilvNodes* required = lilv_ui_get_required_features(ui); LilvNodes* result = lilv_nodes_new(); LILV_FOREACH(nodes, i, optional) zix_tree_insert((ZixTree*)result, lilv_node_duplicate(lilv_nodes_get(optional, i)), NULL); LILV_FOREACH(nodes, i, required) zix_tree_insert((ZixTree*)result, lilv_node_duplicate(lilv_nodes_get(required, i)), NULL); lilv_nodes_free(optional); lilv_nodes_free(required); return result; }
LilvNodes* lilv_nodes_from_stream_objects(LilvWorld* world, SordIter* stream, SordQuadIndex field) { if (sord_iter_end(stream)) { sord_iter_free(stream); return NULL; } else if (world->opt.filter_language) { return lilv_nodes_from_stream_objects_i18n(world, stream, field); } else { LilvNodes* values = lilv_nodes_new(); FOREACH_MATCH(stream) { const SordNode* value = sord_iter_get_node(stream, field); LilvNode* node = lilv_node_new_from_node(world, value); if (node) { zix_tree_insert((ZixTree*)values, node, NULL); } } sord_iter_free(stream); return values; } }
static LilvNodes* lilv_nodes_from_stream_objects_i18n(LilvWorld* world, SordIter* stream, SordQuadIndex field) { LilvNodes* values = lilv_nodes_new(); const SordNode* nolang = NULL; // Untranslated value const SordNode* partial = NULL; // Partial language match char* syslang = lilv_get_lang(); FOREACH_MATCH(stream) { const SordNode* value = sord_iter_get_node(stream, field); if (sord_node_get_type(value) == SORD_LITERAL) { const char* lang = sord_node_get_language(value); LilvLangMatch lm = LILV_LANG_MATCH_NONE; if (lang) { lm = (syslang) ? lilv_lang_matches(lang, syslang) : LILV_LANG_MATCH_PARTIAL; } else { nolang = value; if (!syslang) { lm = LILV_LANG_MATCH_EXACT; } } if (lm == LILV_LANG_MATCH_EXACT) { // Exact language match, add to results zix_tree_insert((ZixTree*)values, lilv_node_new_from_node(world, value), NULL); } else if (lm == LILV_LANG_MATCH_PARTIAL) { // Partial language match, save in case we find no exact partial = value; } } else { zix_tree_insert((ZixTree*)values, lilv_node_new_from_node(world, value), NULL); } } sord_iter_free(stream); free(syslang); if (lilv_nodes_size(values) > 0) { return values; } const SordNode* best = nolang; if (syslang && partial) { // Partial language match for system language best = partial; } else if (!best) { // No languages matches at all, and no untranslated value // Use any value, if possible best = partial; } if (best) { zix_tree_insert( (ZixTree*)values, lilv_node_new_from_node(world, best), NULL); } else { // No matches whatsoever lilv_nodes_free(values); values = NULL; } return values; }