datatypes on literals?

已查看 13 次
跳至第一个未读帖子

Bruce

未读,
2009年8月3日 15:09:392009/8/3
收件人 rdfalchemy-dev
Am a little confused:

Is there some way for me to assign a datatype (say xsd:date or
xsd:datetime) to a literal?

Bruce

Cory Dodt

未读,
2009年8月3日 15:12:412009/8/3
收件人 rdfalch...@googlegroups.com
I haven't found one, also interested to hear this.  In particular I'd like to assign my own datatypes to literals, e.g. dice expressions:

:monster :hitDice "2d10"^^http://goonmill.org/2007/dice.n3#DiceExpression;
--
_____________________

Philip Cooper

未读,
2009年8月3日 17:49:592009/8/3
收件人 rdfalch...@googlegroups.com
You can create a literal with any datatype you wish:

  from rdfalchemy import Literal, Namespace
  a = Literal('thing_1',datatype=OV.thing)


a can now be the right hand side of an assignment to a rdfSingle descriptor and all should work fine

Cory: in the case of xsd:date or xsd:datetime, you can already assign a date or datetime instance (from the datetime module) and 
rdfalchemy will place the correct xsd:dateTime or xsd:date datatype on it in the triplestore.

You can look at my page on CustomizingLiterals [1] for a bit more info.  Look at what was done to allow the correct handling of the Decimal class type.
That and the source for Literal [2] should help you to see that a couple of lines will get "automatic" assignment of datatype to work.

Your two other options are to handle it inside a custom descriptor (more code more power less resuability) or just create a Literal by hand (as stated above)

--
Phil

回复全部
回复作者
转发
0 个新帖子