Exemplo n.º 1
0
/* private */
SLV2Port
slv2_port_new(SLV2World world, uint32_t index, const char* symbol)
{
	struct _SLV2Port* port = malloc(sizeof(struct _SLV2Port));
	port->index = index;
	port->symbol = slv2_value_new(world, SLV2_VALUE_STRING, symbol);
	port->classes = slv2_values_new();
	//port->node_id = strdup(node_id);
	return port;
}
Exemplo n.º 2
0
/** Create a new SLV2Value from a librdf_node, or return NULL if impossible */
SLV2Value
slv2_value_from_librdf_node(SLV2World world, librdf_node* node)
{
	SLV2Value result = NULL;

	librdf_uri* datatype_uri = NULL;
	SLV2ValueType type = SLV2_VALUE_STRING;

	switch (librdf_node_get_type(node)) {
	case LIBRDF_NODE_TYPE_RESOURCE:
		type = SLV2_VALUE_URI;
		result = slv2_value_new_librdf_uri(world, librdf_node_get_uri(node));
		break;
	case LIBRDF_NODE_TYPE_LITERAL:
		datatype_uri = librdf_node_get_literal_value_datatype_uri(node);
		if (datatype_uri) {
			if (!strcmp((const char*)librdf_uri_as_string(datatype_uri),
						"http://www.w3.org/2001/XMLSchema#integer"))
				type = SLV2_VALUE_INT;
			else if (!strcmp((const char*)librdf_uri_as_string(datatype_uri),
						"http://www.w3.org/2001/XMLSchema#decimal"))
				type = SLV2_VALUE_FLOAT;
			else
				fprintf(stderr, "Unknown datatype %s\n", librdf_uri_as_string(datatype_uri));
		}
		result = slv2_value_new(world, type, (const char*)librdf_node_get_literal_value(node));
		break;
	case LIBRDF_NODE_TYPE_BLANK:
		type = SLV2_VALUE_STRING;
		result = slv2_value_new(world, type, (const char*)librdf_node_get_blank_identifier(node));
		break;
	case LIBRDF_NODE_TYPE_UNKNOWN:
	default:
		fprintf(stderr, "Unknown RDF node type %d\n", librdf_node_get_type(node));
		break;
	}

	return result;
}