/** Create a new LilvNode from `node`, or return NULL if impossible */ LilvNode* lilv_node_new_from_node(LilvWorld* world, const SordNode* node) { if (!node) { return NULL; } LilvNode* result = NULL; SordNode* datatype_uri = NULL; LilvNodeType type = LILV_VALUE_STRING; size_t len = 0; switch (sord_node_get_type(node)) { case SORD_URI: result = (LilvNode*)malloc(sizeof(LilvNode)); result->world = (LilvWorld*)world; result->type = LILV_VALUE_URI; result->node = sord_node_copy(node); break; case SORD_BLANK: result = (LilvNode*)malloc(sizeof(LilvNode)); result->world = (LilvWorld*)world; result->type = LILV_VALUE_BLANK; result->node = sord_node_copy(node); break; case SORD_LITERAL: datatype_uri = sord_node_get_datatype(node); if (datatype_uri) { if (sord_node_equals(datatype_uri, world->uris.xsd_boolean)) type = LILV_VALUE_BOOL; else if (sord_node_equals(datatype_uri, world->uris.xsd_decimal) || sord_node_equals(datatype_uri, world->uris.xsd_double)) type = LILV_VALUE_FLOAT; else if (sord_node_equals(datatype_uri, world->uris.xsd_integer)) type = LILV_VALUE_INT; else if (sord_node_equals(datatype_uri, world->uris.xsd_base64Binary)) type = LILV_VALUE_BLOB; else LILV_ERRORF("Unknown datatype `%s'\n", sord_node_get_string(datatype_uri)); } result = lilv_node_new( world, type, (const char*)sord_node_get_string_counted(node, &len)); lilv_node_set_numerics_from_string(result, len); break; } return result; }
static SordNode* sord_insert_node(SordWorld* world, const SordNode* key, bool copy) { SordNode* node = NULL; ZixStatus st = zix_hash_insert(world->nodes, key, (const void**)&node); switch (st) { case ZIX_STATUS_EXISTS: ++node->refs; break; case ZIX_STATUS_SUCCESS: assert(node->refs == 1); if (copy) { node->node.buf = sord_strndup(node->node.buf, node->node.n_bytes); } if (node->node.type == SERD_LITERAL) { node->meta.lit.datatype = sord_node_copy(node->meta.lit.datatype); } return node; default: assert(!node); error(world, SERD_ERR_INTERNAL, "error inserting node `%s'\n", key->node.buf); } if (!copy) { // Free the buffer we would have copied if a new node was created free((uint8_t*)key->node.buf); } return node; }
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 LilvNode* lilv_node_duplicate(const LilvNode* val) { if (!val) { return NULL; } LilvNode* result = (LilvNode*)malloc(sizeof(LilvNode)); result->world = val->world; result->node = sord_node_copy(val->node); result->val = val->val; result->type = val->type; return result; }
SordNode* sord_get(SordModel* model, const SordNode* s, const SordNode* p, const SordNode* o, const SordNode* g) { if ((bool)s + (bool)p + (bool)o != 2) { return NULL; } SordIter* i = sord_search(model, s, p, o, g); SordNode* ret = NULL; if (!s) { ret = sord_node_copy(sord_iter_get_node(i, SORD_SUBJECT)); } else if (!p) { ret = sord_node_copy(sord_iter_get_node(i, SORD_PREDICATE)); } else if (!o) { ret = sord_node_copy(sord_iter_get_node(i, SORD_OBJECT)); } sord_iter_free(i); return ret; }