Objects instances(World* world, const URISet& types) { LilvNode* rdf_type = lilv_new_uri( world->lilv_world(), LILV_NS_RDF "type"); Objects result; for (const auto& t : types) { LilvNode* type = lilv_new_uri(world->lilv_world(), t.c_str()); LilvNodes* objects = lilv_world_find_nodes( world->lilv_world(), NULL, rdf_type, type); LILV_FOREACH(nodes, o, objects) { const LilvNode* object = lilv_nodes_get(objects, o); if (!lilv_node_is_uri(object)) { continue; } const std::string label = RDFS::label(world, object); result.insert( std::make_pair(label, Raul::URI(lilv_node_as_string(object)))); } lilv_node_free(type); } lilv_node_free(rdf_type); return result; }
LILV_API const char* lilv_node_as_uri(const LilvNode* value) { return (lilv_node_is_uri(value) ? (const char*)sord_node_get_string(value->node) : NULL); }
LILV_API char* lilv_node_get_path(const LilvNode* value, char** hostname) { if (lilv_node_is_uri(value)) { return lilv_file_uri_parse(lilv_node_as_uri(value), hostname); } return NULL; }
URISet properties(World* world, SPtr<const Client::ObjectModel> model) { URISet properties; URISet types = RDFS::types(world, model); LilvNode* rdf_type = lilv_new_uri(world->lilv_world(), LILV_NS_RDF "type"); LilvNode* rdf_Property = lilv_new_uri(world->lilv_world(), LILV_NS_RDF "Property"); LilvNode* rdfs_domain = lilv_new_uri(world->lilv_world(), LILV_NS_RDFS "domain"); LilvNodes* props = lilv_world_find_nodes( world->lilv_world(), NULL, rdf_type, rdf_Property); LILV_FOREACH(nodes, p, props) { const LilvNode* prop = lilv_nodes_get(props, p); if (lilv_node_is_uri(prop)) { LilvNodes* domains = lilv_world_find_nodes( world->lilv_world(), prop, rdfs_domain, NULL); unsigned n_matching_domains = 0; LILV_FOREACH(nodes, d, domains) { const LilvNode* domain_node = lilv_nodes_get(domains, d); if (!lilv_node_is_uri(domain_node)) { // TODO: Blank node domains (e.g. unions) continue; } const Raul::URI domain(lilv_node_as_uri(domain_node)); if (types.count(domain)) { ++n_matching_domains; } } if (lilv_nodes_size(domains) == 0 || ( n_matching_domains > 0 && n_matching_domains == lilv_nodes_size(domains))) { properties.insert(Raul::URI(lilv_node_as_uri(prop))); } lilv_nodes_free(domains); } } lilv_node_free(rdfs_domain); lilv_node_free(rdf_Property); lilv_node_free(rdf_type); return properties; }
LILV_API LilvState* lilv_state_new_from_world(LilvWorld* world, const LV2_URID_Map* map, const LilvNode* node) { if (!lilv_node_is_uri(node) && !lilv_node_is_blank(node)) { LILV_ERRORF("Subject `%s' is not a URI or blank node.\n", lilv_node_as_string(node)); return NULL; } LilvState* state = new_state_from_model( world, map, world->model, node->node, NULL); return state; }
LILV_API LilvState* lilv_state_new_from_file(LilvWorld* world, const LV2_URID_Map* map, const LilvNode* subject, const char* path) { if (subject && !lilv_node_is_uri(subject) && !lilv_node_is_blank(subject)) { LILV_ERRORF("Subject `%s' is not a URI or blank node.\n", lilv_node_as_string(subject)); return NULL; } uint8_t* abs_path = (uint8_t*)lilv_path_absolute(path); SerdNode node = serd_node_new_file_uri(abs_path, NULL, NULL, 0); SerdEnv* env = serd_env_new(&node); SordModel* model = sord_new(world->world, SORD_SPO, false); SerdReader* reader = sord_new_reader(model, env, SERD_TURTLE, NULL); serd_reader_read_file(reader, node.buf); SordNode* subject_node = (subject) ? subject->node : sord_node_from_serd_node(world->world, env, &node, NULL, NULL); char* dirname = lilv_dirname(path); char* real_path = lilv_realpath(dirname); LilvState* state = new_state_from_model( world, map, model, subject_node, real_path); free(dirname); free(real_path); serd_node_free(&node); free(abs_path); serd_reader_free(reader); sord_free(model); serd_env_free(env); return state; }