[redland-dev] failure in librdf_new_node_from_typed_literal
(was: Re: newbie question:
constructing a literal with datatype using Python bindings)
Sean Boisen
sean at logos.com
Mon Mar 3 18:20:17 GMT 2008
Sean Boisen <sean at ...> writes:
>
> I'm trying to construct a literal URI with datatype, e.g. something (in
> N-triples) like
> "true"^^<http://www.w3.org/2001/XMLSchema#boolean>
> The documentation is a bit terse on this point. I'm new to Redland, so
> please be gentle.
>
> Here's what I tried that _didn't_ work (parading my ignorance):
> # string argument to datatype as URI
> >>> rdfalse = RDF.Node(literal="false",
> datatype="http://www.w3.org/2001/XMLSchema#boolean")
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "C:\Python24\Lib\site-packages\RDF\RDF.py", line 302, in __init__
> args['literal'], xml_language, datatype._reduri)
> AttributeError: 'str' object has no attribute '_reduri'
>
> # Uri argument
> >>> rdfalse = RDF.Node(literal="false",
> datatype=RDF.Uri("http://www.w3.org/2001/XMLSchema#boolean"))
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "C:\Python24\Lib\site-packages\RDF\RDF.py", line 322, in __init__
> raise RedlandError("Node construction failed")
> RDF.RDF.RedlandError: 'Node construction failed'
>
> # maybe the datatype argument needs to be a Node with a URI?
> >>> xsdbool =
> RDF.Node(RDF.Uri("http://www.w3.org/2001/XMLSchema#boolean"))
> >>> rdfalse = RDF.Node(literal="false", datatype=xsdbool)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "C:\Python24\Lib\site-packages\RDF\RDF.py", line 302, in __init__
> args['literal'], xml_language, datatype._reduri)
> AttributeError: 'Node' object has no attribute '_reduri'
>
> # datatype arg as a literal Node?
> >>> xsdbool =
> RDF.Node(literal="http://www.w3.org/2001/XMLSchema#boolean")
> >>> xsdbool.is_literal()
> True
> >>> rdfalse = RDF.Node(literal="false", datatype=xsdbool)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "C:\Python24\Lib\site-packages\RDF\RDF.py", line 302, in __init__
> args['literal'], xml_language, datatype._reduri)
> AttributeError: 'Node' object has no attribute '_reduri'
>
> I've pawed around in the code a bit but not enough to really understand
> where this is going wrong, and I'm assuming it's something simple about
> the conceptual model that I just don't have right yet.
>
> This is on Windows Vista, Python 2.4, using the binaries and installer
> from http://download.librdf.org/binaries/win32/1.0.3/, RDF.py,v 1.116
> 2006-03-05 08:30:38 (in the unlikely event that matters).
>
> Sean
>
I've looked into the details a bit further, and either there's a bug lurking
here, or i'm really not getting it.
In the Python bindings, it looks like the right invocation should be:
>>> rdfalse = RDF.Node(literal="false",
datatype=RDF.Uri("http://www.w3.org/2001/XMLSchema#boolean"))
(because the argument to datatype has to have a _reduri property).
As evidenced below, this raises the "Node construction failed" error, because
the call to
self._node=Redland.librdf_new_node_from_typed_literal(_world._world,
args['literal'], xml_language, datatype._reduri)
returns None. That's as far as i'm able to penetrate, though, since i'm using
the binaries from http://download.librdf.org/binaries/win32/1.0.3/ (which looks
a couple of revs behind, but i don't have the proper kit to build more current
windows binaries: if somebody knows of one, please let me know and i'll give it
a try).
This example from the documentation similarly fails:
node5=RDF.Node(literal="<tag>content</tag>", is_wf_xml=1)
which makes me think there's something wrong with the binaries.
Can anybody shed some light on this? Do these forms work for others using Python?
Sean
More information about the redland-dev
mailing list