[redland-dev] newbie question: constructing a literal with datatype using Python bindings

Sean Boisen sean at logos.com
Thu Feb 14 19:29:34 GMT 2008


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



More information about the redland-dev mailing list