コード例 #1
0
ファイル: sord_validate.c プロジェクト: ViktorNova/Carla
static int
check_instances(SordModel* model, const URIs* uris)
{
	int       st = 0;
	SordIter* r = sord_search(
		model, NULL, uris->rdf_type, uris->owl_Restriction, NULL);
	for (; !sord_iter_end(r); sord_iter_next(r)) {
		const SordNode* restriction = sord_iter_get_node(r, SORD_SUBJECT);
		const SordNode* prop        = sord_get(
			model, restriction, uris->owl_onProperty, NULL, NULL);
		if (!prop) {
			continue;
		}

		SordIter* c = sord_search(
			model, NULL, uris->rdfs_subClassOf, restriction, NULL);
		for (; !sord_iter_end(c); sord_iter_next(c)) {
			const SordNode* klass = sord_iter_get_node(c, SORD_SUBJECT);
			check_class_instances(model, uris, restriction, klass);
		}
		sord_iter_free(c);
	}
	sord_iter_free(r);

	return st;
}
コード例 #2
0
ファイル: state.c プロジェクト: dmlloyd/Carla
LILV_API
LilvState*
lilv_state_new_from_string(LilvWorld*          world,
                           const LV2_URID_Map* map,
                           const char*         str)
{
	if (!str) {
		return NULL;
	}

	SerdNode    base   = SERD_NODE_NULL;
	SerdEnv*    env    = serd_env_new(&base);
	SordModel*  model  = sord_new(world->world, SORD_SPO|SORD_OPS, false);
	SerdReader* reader = sord_new_reader(model, env, SERD_TURTLE, NULL);

	set_prefixes(env);
	serd_reader_read_string(reader, USTR(str));

	SordNode* o = sord_new_uri(world->world, USTR(LV2_PRESETS__Preset));
	SordNode* s = sord_get(model, NULL, world->uris.rdf_a, o, NULL);

	LilvState* state = new_state_from_model(world, map, model, s, NULL);

	sord_node_free(world->world, s);
	sord_node_free(world->world, o);
	serd_reader_free(reader);
	sord_free(model);
	serd_env_free(env);

	return state;
}
コード例 #3
0
ファイル: sord_validate.c プロジェクト: ViktorNova/Carla
static int
check_instance(SordModel*      model,
               const URIs*     uris,
               const SordNode* restriction,
               const SordNode* instance)
{
	int st = 0;

	const SordNode* prop = sord_get(
		model, restriction, uris->owl_onProperty, NULL, NULL);
	if (!prop) {
		return 0;
	}

	const unsigned values = sord_count(model, instance, prop, NULL, NULL);

	// Check exact cardinality
	const SordNode* card = sord_get(
		model, restriction, uris->owl_cardinality, NULL, NULL);
	if (card) {
		const unsigned c = atoi((const char*)sord_node_get_string(card));
		if (values != c) {
			st = errorf("Property %s on %s has %u != %u values\n",
			            sord_node_get_string(prop),
			            sord_node_get_string(instance),
			            values, c);
		}
	}

	// Check minimum cardinality
	const SordNode* minCard = sord_get(
		model, restriction, uris->owl_minCardinality, NULL, NULL);
	if (minCard) {
		const unsigned m = atoi((const char*)sord_node_get_string(minCard));
		if (values < m) {
			st = errorf("Property %s on %s has %u < %u values\n",
			            sord_node_get_string(prop),
			            sord_node_get_string(instance),
			            values, m);
		}
	}

	// Check someValuesFrom
	SordIter* sf = sord_search(
		model, restriction, uris->owl_someValuesFrom, NULL, NULL);
	if (sf) {
		const SordNode* type = sord_iter_get_node(sf, SORD_OBJECT);
		SordIter* v     = sord_search(model, instance, prop, NULL, NULL);
		bool      found = false;
		for (; !sord_iter_end(v); sord_iter_next(v)) {
			const SordNode* value = sord_iter_get_node(v, SORD_OBJECT);
			if (check_type(model, uris, value, type)) {
				found = true;
				break;
			}
		}
		if (!found) {
			st = errorf("%s has no <%s> values of type <%s>\n",
			            sord_node_get_string(instance),
			            sord_node_get_string(prop),
			            sord_node_get_string(type));
		}
		sord_iter_free(v);
	}
	sord_iter_free(sf);

	return st;
}
コード例 #4
0
ファイル: state.c プロジェクト: dmlloyd/Carla
static LilvState*
new_state_from_model(LilvWorld*       world,
                     LV2_URID_Map*    map,
                     SordModel*       model,
                     const SordNode*  node,
                     const char*      dir)
{
	LilvState* const state = (LilvState*)malloc(sizeof(LilvState));
	memset(state, '\0', sizeof(LilvState));
	state->dir       = lilv_strdup(dir);
	state->atom_Path = map->map(map->handle, LV2_ATOM__Path);

	// Get the plugin URI this state applies to
	SordIter* i = sord_search(model, node, world->uris.lv2_appliesTo, 0, 0);
	if (i) {
		const SordNode* object = sord_iter_get_node(i, SORD_OBJECT);
		const SordNode* graph  = sord_iter_get_node(i, SORD_GRAPH);
		state->plugin_uri = lilv_node_new_from_node(world, object);
		if (!state->dir && graph) {
			state->dir = lilv_strdup((const char*)sord_node_get_string(graph));
		}
		sord_iter_free(i);
	} else if (sord_ask(model,
	                    node,
	                    world->uris.rdf_a,
	                    world->uris.lv2_Plugin, 0)) {
		// Loading plugin description as state (default state)
		state->plugin_uri = lilv_node_new_from_node(world, node);
	} else {
		LILV_ERRORF("State %s missing lv2:appliesTo property\n",
		            sord_node_get_string(node));
	}

	// Get the state label
	i = sord_search(model, node, world->uris.rdfs_label, NULL, NULL);
	if (i) {
		const SordNode* object = sord_iter_get_node(i, SORD_OBJECT);
		const SordNode* graph  = sord_iter_get_node(i, SORD_GRAPH);
		state->label = lilv_strdup((const char*)sord_node_get_string(object));
		if (!state->dir) {
			state->dir = lilv_strdup((const char*)sord_node_get_string(graph));
		}
		sord_iter_free(i);
	}

	Sratom*        sratom = sratom_new(map);
	SerdChunk      chunk  = { NULL, 0 };
	LV2_Atom_Forge forge;
	lv2_atom_forge_init(&forge, map);
	lv2_atom_forge_set_sink(
		&forge, sratom_forge_sink, sratom_forge_deref, &chunk);

	// Get port values
	SordIter* ports = sord_search(model, node, world->uris.lv2_port, 0, 0);
	FOREACH_MATCH(ports) {
		const SordNode* port = sord_iter_get_node(ports, SORD_OBJECT);

		SordNode* label  = sord_get(model, port, world->uris.rdfs_label, 0, 0);
		SordNode* symbol = sord_get(model, port, world->uris.lv2_symbol, 0, 0);
		SordNode* value  = sord_get(model, port, world->uris.pset_value, 0, 0);
		if (!value) {
			value = sord_get(model, port, world->uris.lv2_default, 0, 0);
		}
		if (!symbol) {
			LILV_ERRORF("State `%s' port missing symbol.\n",
			            sord_node_get_string(node));
		} else if (value) {
			chunk.len = 0;
			sratom_read(sratom, &forge, world->world, model, value);
			LV2_Atom* atom = (LV2_Atom*)chunk.buf;

			append_port_value(state,
			                  (const char*)sord_node_get_string(symbol),
			                  LV2_ATOM_BODY(atom), atom->size, atom->type);

			if (label) {
				lilv_state_set_label(state,
				                     (const char*)sord_node_get_string(label));
			}
		}
		sord_node_free(world->world, value);
		sord_node_free(world->world, symbol);
		sord_node_free(world->world, label);
	}
	sord_iter_free(ports);

	// Get properties
	SordNode* statep     = sord_new_uri(world->world, USTR(LV2_STATE__state));
	SordNode* state_node = sord_get(model, node, statep, NULL, NULL);
	if (state_node) {
		SordIter* props = sord_search(model, state_node, 0, 0, 0);
		FOREACH_MATCH(props) {
			const SordNode* p = sord_iter_get_node(props, SORD_PREDICATE);
			const SordNode* o = sord_iter_get_node(props, SORD_OBJECT);

			chunk.len = 0;
			lv2_atom_forge_set_sink(
				&forge, sratom_forge_sink, sratom_forge_deref, &chunk);

			sratom_read(sratom, &forge, world->world, model, o);
			LV2_Atom* atom  = (LV2_Atom*)chunk.buf;
			uint32_t  flags = LV2_STATE_IS_POD|LV2_STATE_IS_PORTABLE;
			Property  prop  = { NULL, 0, 0, 0, flags };

			prop.key   = map->map(map->handle, (const char*)sord_node_get_string(p));
			prop.type  = atom->type;
			prop.size  = atom->size;
			prop.value = malloc(atom->size);
			memcpy(prop.value, LV2_ATOM_BODY(atom), atom->size);
			if (atom->type == forge.Path) {
				prop.flags = LV2_STATE_IS_PORTABLE;
			}

			if (prop.value) {
				state->props = (Property*)realloc(
					state->props, (++state->num_props) * sizeof(Property));
				state->props[state->num_props - 1] = prop;
			}
		}
		sord_iter_free(props);
	}
	sord_node_free(world->world, state_node);
	sord_node_free(world->world, statep);

	free((void*)chunk.buf);
	sratom_free(sratom);

	qsort(state->props, state->num_props, sizeof(Property), property_cmp);
	qsort(state->values, state->num_values, sizeof(PortValue), value_cmp);

	return state;
}