Casting a dynamically built string to a dateTimeDuration

35 views
Skip to first unread message

Mark James

unread,
May 18, 2016, 2:42:37 AM5/18/16
to Stardog
Hi Guys,
I'm stuck on something that should in theory be quite simple. Hopefully i've just overlooked something obvious...

I'm building a duration dynamically based on other calculations but I'm having trouble casting it. I have no problems doing this with a static dayTimeDuration like below.

select *
where {
      BIND ("PT10H0M0S"^^xsd:dayTimeDuration as ?duration) 
}

But replacing this with any of the below breaks

      BIND ("10" as ?hours)
      BIND (concat("PT", ?hours, "H0M0S"^^xsd:dayTimeDuration) as ?duration2) 
      BIND (xsd:dayTimeDuration(concat("PT", ?hours, "H0M0S")) as ?duration3)

I get the error -
com.complexible.stardog.plan.eval.ExecutionException: Unknown function: http://www.w3.org/2001/XMLSchema#dayTimeDuration

Any ideas?

cheers
Mark

Zachary Whitley

unread,
May 18, 2016, 9:59:15 AM5/18/16
to Stardog
You can try using the swrb function to construct durations

select * where {
      BIND(10 as ?hours)
      BIND (swrlb:dayTimeDuration(0,?hours,0,0) as ?duration)
}

--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en
---
You received this message because you are subscribed to the Google Groups "Stardog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stardog+u...@clarkparsia.com.

Zachary Whitley

unread,
May 18, 2016, 10:12:48 AM5/18/16
to Stardog

Evren Sirin

unread,
May 18, 2016, 10:52:32 AM5/18/16
to Stardog
Right, casting to xsd:dayTimeDuration is not in the spec and
swrlb:dayTimeDuration is the best option. The other possibility is
using XQuery's multiply-dayTimeDuration that Stardog supports by
overloading the * operator. If you just have hours fields then you'd
have

SELECT * {
BIND(10 AS ?hours)
BIND(?hours * "PT1H"^^xsd:dayTimeDuration AS ?duration)
}

But if you have multiple fields for your duration then you'd need to
repeat this for each field and add them up which would be verbose:

SELECT * {
BIND(10 AS ?hours)
BIND(5 AS ?minutes)
BIND((?hours * "PT1H"^^xsd:dayTimeDuration) + (?minutes *
"PT1M"^^xsd:dayTimeDuration) AS ?duration)
}

Best,
Evren

On Wed, May 18, 2016 at 10:12 AM, Zachary Whitley

Mark James

unread,
May 18, 2016, 8:06:09 PM5/18/16
to sta...@clarkparsia.com
Guys,
Thanks for your assistance so far. Unfortunately I can't make either solution work yet.

1. Taking the overload approach returns a blank duration
SELECT * {
   BIND(10 AS ?hours)
   BIND(?hours * "PT1H"^^xsd:dayTimeDuration AS ?duration)
}

2. Using the swrlb approach does get me a duration. Which can't be overloaded (and use arithmentic operators), I assume because it's of type swrlb rather than xsd? I tried to use the function addDayTimeDurationToDateTime which I found here -http://www.daml.org/swrl/proposal/builtins.html but it didn't work.

select *
where {
BIND (swrlb:dayTimeDuration(0,4,0,0) as ?duration)
BIND (swrlb:addDayTimeDurationToDateTime(now(),?duration ) as ?dueDateTime)
}


I assume there is a swrlb function I can use?

cheers
Mark
Mark James | Smarta Systems Pty Ltd
+61 433 922 944mja...@smarta.io | smarta.io

Evren Sirin

unread,
May 18, 2016, 10:27:50 PM5/18/16
to Stardog
Ah, the multiplication example works the way I wrote it in 4.1 but not
earlier. In earlier versions overloading worked only if the left arg
is dayTimeDuration and the right arg is double. And for adding
duration to dateTime you can simply use the + operator (dateTime
should be the first arg). The following query work in 4.0.5 and 4.1:

prefix swrlb: <http://www.w3.org/2003/11/swrlb#>
select *
where {
BIND(10 AS ?hours)
BIND("PT1H"^^xsd:dayTimeDuration * xsd:double(?hours) AS ?duration)
BIND (now() + ?duration as ?dueDateTime)
}

Turns out there is a problem with the swrlb:dayTimeDuration
implementation in Stardog and it outputs a xsd:duration instead of a
xsd:dayTimeDuration which means it cannot be used in further
computations. We created a ticket for this (#2944) and will fix it in
an upcoming version.

Best,
Evren

Mark James

unread,
May 18, 2016, 10:51:29 PM5/18/16
to sta...@clarkparsia.com
Great, thanks for a solution Evren.

We'll probably upgrade to 4.1 in the coming weeks but until then I'll use your double workaround.

cheers
Mark
Reply all
Reply to author
Forward
0 new messages