[redland] Node Type Returning incorrectly.
Dave Beckett
dave.beckett at bristol.ac.uk
Thu Sep 13 12:36:12 BST 2001
>>>Sameer Abhinkar said:
> Here is the problem description in brief.. with some
> parts of the source code.
>
> I have a statement which is of the format:
> {[file://home/sameer/ccppdef.rdf#genid2],[http://www.w3.org/1999/02/22-rdf-sy
ntax-ns#type],[http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag]}
> The above statement is stored in variable 'statement'
>
> I create three nodes out of it
> node_sub = librdf_statement_get_object(statement);
> node_pred = librdf_statement_get_pred(statement);
> node_obj = librdf_statement_get_obj(statement);
>
> int i = librdf_node_get_type(node_obj);
>
> i is returning LIBRDF_NODE_TYPE_RESOURCE(1) in lieu of
> LIBRDF_NODE_TYPE_BAG(4). Does anyone know why this
> could happen?
Yes - the answer is that I started to consider having special types
for containers but it turned on that this is a bad idea. the RDF
Core working group has recently removed containers as special-cases
in RDF, the rdf:Seq, rdf:Bag and rdf:Alt are just classes that can be
used like any ther node. I should remove the containers stuff from
that call; only LIBRDF_NODE_TYPE_RESOURCE and LIBRDF_NODE_TYPE_LITERAL
should be expected.
Hence, you will just get back a node type of
LIBRDF_NODE_TYPE_RESOURCE. If you want to find out what the RDF type
of a resource (container) is, you will have to make a query for the
rdf:type property of the resource ie ask for a statement matching:
[resource-URI, rdf:type, ?]
or in C API terms:
/* find the target (object) of the above statement */
n=librdf_model_get_target(model, node_sub, /* resource node */
LIBRDF_MS_type); /* rdf:type property */
and which point 'n' will be a new librdf_node objet of the type of
the resource or NULL on failure (no rdf:type property found). There
can be more than one type potentially, in which case you will have to
use librdf_model_get_targets and iterate along the sequence of
returned librdf_node objects.
There is code similar to the above in example4.c around
http://www.redland.opensource.ac.uk/lxr/source/example4.c#L421
> Thanks,
>
> Sameer Abhinkar
Dave
More information about the redland-dev
mailing list