You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Diogo FC Patrao <dj...@gmail.com> on 2013/04/12 23:12:25 UTC

BIND and custom functions on SPARQL

Hello all,

I'm trying to run a SPARQL query specifiying a custom function (that does
date arithmetics). On ARQ 2.8.8, the following code worked perfectly:

PREFIX : <http://www.cipe.accamargo.org.br/ontologias/h2tc.owl#>
PREFIX xmls: <http://www.w3.org/2001/XMLSchema#>

select  * {

SERVICE <http://0.0.0.0:2023/sparql> {
                :patient1 :hasDocument ?docX .

                ?docX :documentType "PRESCRIPTION" .
                ?docX :documentDateOfCreation ?docDateX .
               FILTER ( xmls:date(?docDateX) >
:xmls:date(<java:dateadd.lib.pkgfor.arq.DateaddLibForARQ>("2012-03-22",
"-P30D")) )

        }
}
limit 10

However, when specifying this function using arq 2.10.1-snapshot (4/3)
(recompiled the library and updated cp), it complains :

18:00:53 WARN  Loader               :: Class not found:
dateadd.lib.pkgfor.arq.DateaddLibForARQ
18:00:53 WARN  exec                 :: URI
<java:dateadd.lib.pkgfor.arq.DateaddLibForARQ> has no registered function
factory


I could get the query working that way:

select  * {

 SERVICE <http://0.0.0.0:2023/sparql> {
                :patient1 :hasDocument ?docX .

                ?docX :documentType "PRESCRIPTION" .
                ?docX :documentDateOfCreation ?docDateX .
        BIND( <java:dateadd.lib.pkgfor.arq.DateaddLibForARQ>("2012-03-22",
"-P30D") as ?teste )

        FILTER ( ?docDateX >  ?teste )

        }
}
limit 10


Thanks a lot!


--
diogo patrão

Re: BIND and custom functions on SPARQL

Posted by Andy Seaborne <an...@apache.org>.
On 14/04/13 12:32, Diogo FC Patrao wrote:
> Hi Andy!
>
>
>> Nowadays ARQ supports date/duration arithmetic (not ARQ 2.8.8)
>>
>> "2012-03-22"^^xsd:date + "-P30D"^^xsd:duration
>>     ==>
>> "2012-02-21"^^xsd:date
>>
>> You may not need the custom function.
>>
>
> That's awesome! In which version was it available? From what I see, it
> doesn't work on jena-arq-2.9.0.

2.9.0 was several releases ago - this is quite recent.

It's in 2.10.0.

>> The use of a custom functions inside SERVICE isn't ideal.
>>
>
> That's a thing I do for limiting the number of results the service returns,
> as there's tens of million triples per service, ARQ would need lots of
> memory (for me, 16G or more) to join results. And, as the services are
> based on D2R, which is using ARQ 2.9.0, I still need the custom functions =/

I see - yes - necessary.

	Andy

 >
> I agree that it isn't ideal, as I need to add to the CP of the endpoints.
> And, as it's a different ARQ, I ended up with two versions of this
> functions, each compiled against one jena version!
>
> Thanks!
>
> dfcp
>
>
>>
>>
>>          Andy
>>
>>
>>
>>
>> On 12/04/13 22:12, Diogo FC Patrao wrote:
>>
>>> Hello all,
>>>
>>> I'm trying to run a SPARQL query specifiying a custom function (that does
>>> date arithmetics). On ARQ 2.8.8, the following code worked perfectly:
>>>
>>> PREFIX : <http://www.cipe.accamargo.**org.br/ontologias/h2tc.owl#<http://www.cipe.accamargo.org.br/ontologias/h2tc.owl#>
>>>>
>>> PREFIX xmls: <http://www.w3.org/2001/**XMLSchema#<http://www.w3.org/2001/XMLSchema#>
>>>>
>>>
>>> select  * {
>>>
>>> SERVICE <http://0.0.0.0:2023/sparql> {
>>>                   :patient1 :hasDocument ?docX .
>>>
>>>                   ?docX :documentType "PRESCRIPTION" .
>>>                   ?docX :documentDateOfCreation ?docDateX .
>>>                  FILTER ( xmls:date(?docDateX) >
>>> :xmls:date(<java:dateadd.lib.**pkgfor.arq.DateaddLibForARQ>("**
>>> 2012-03-22",
>>> "-P30D")) )
>>>
>>>           }
>>> }
>>> limit 10
>>>
>>> However, when specifying this function using arq 2.10.1-snapshot (4/3)
>>> (recompiled the library and updated cp), it complains :
>>>
>>> 18:00:53 WARN  Loader               :: Class not found:
>>> dateadd.lib.pkgfor.arq.**DateaddLibForARQ
>>> 18:00:53 WARN  exec                 :: URI
>>> <java:dateadd.lib.pkgfor.arq.**DateaddLibForARQ> has no registered
>>> function
>>> factory
>>>
>>>
>>> I could get the query working that way:
>>>
>>> select  * {
>>>
>>>    SERVICE <http://0.0.0.0:2023/sparql> {
>>>                   :patient1 :hasDocument ?docX .
>>>
>>>                   ?docX :documentType "PRESCRIPTION" .
>>>                   ?docX :documentDateOfCreation ?docDateX .
>>>           BIND( <java:dateadd.lib.pkgfor.arq.**
>>> DateaddLibForARQ>("2012-03-22"**,
>>> "-P30D") as ?teste )
>>>
>>>           FILTER ( ?docDateX >  ?teste )
>>>
>>>           }
>>> }
>>> limit 10
>>>
>>>
>>> Thanks a lot!
>>>
>>>
>>> --
>>> diogo patrão
>>>
>>>
>>
>


Re: BIND and custom functions on SPARQL

Posted by Diogo FC Patrao <dj...@gmail.com>.
Hi Andy!


> Nowadays ARQ supports date/duration arithmetic (not ARQ 2.8.8)
>
> "2012-03-22"^^xsd:date + "-P30D"^^xsd:duration
>    ==>
> "2012-02-21"^^xsd:date
>
> You may not need the custom function.
>

That's awesome! In which version was it available? From what I see, it
doesn't work on jena-arq-2.9.0.


> The use of a custom functions inside SERVICE isn't ideal.
>

That's a thing I do for limiting the number of results the service returns,
as there's tens of million triples per service, ARQ would need lots of
memory (for me, 16G or more) to join results. And, as the services are
based on D2R, which is using ARQ 2.9.0, I still need the custom functions =/

I agree that it isn't ideal, as I need to add to the CP of the endpoints.
And, as it's a different ARQ, I ended up with two versions of this
functions, each compiled against one jena version!

Thanks!

dfcp


>
>
>         Andy
>
>
>
>
> On 12/04/13 22:12, Diogo FC Patrao wrote:
>
>> Hello all,
>>
>> I'm trying to run a SPARQL query specifiying a custom function (that does
>> date arithmetics). On ARQ 2.8.8, the following code worked perfectly:
>>
>> PREFIX : <http://www.cipe.accamargo.**org.br/ontologias/h2tc.owl#<http://www.cipe.accamargo.org.br/ontologias/h2tc.owl#>
>> >
>> PREFIX xmls: <http://www.w3.org/2001/**XMLSchema#<http://www.w3.org/2001/XMLSchema#>
>> >
>>
>> select  * {
>>
>> SERVICE <http://0.0.0.0:2023/sparql> {
>>                  :patient1 :hasDocument ?docX .
>>
>>                  ?docX :documentType "PRESCRIPTION" .
>>                  ?docX :documentDateOfCreation ?docDateX .
>>                 FILTER ( xmls:date(?docDateX) >
>> :xmls:date(<java:dateadd.lib.**pkgfor.arq.DateaddLibForARQ>("**
>> 2012-03-22",
>> "-P30D")) )
>>
>>          }
>> }
>> limit 10
>>
>> However, when specifying this function using arq 2.10.1-snapshot (4/3)
>> (recompiled the library and updated cp), it complains :
>>
>> 18:00:53 WARN  Loader               :: Class not found:
>> dateadd.lib.pkgfor.arq.**DateaddLibForARQ
>> 18:00:53 WARN  exec                 :: URI
>> <java:dateadd.lib.pkgfor.arq.**DateaddLibForARQ> has no registered
>> function
>> factory
>>
>>
>> I could get the query working that way:
>>
>> select  * {
>>
>>   SERVICE <http://0.0.0.0:2023/sparql> {
>>                  :patient1 :hasDocument ?docX .
>>
>>                  ?docX :documentType "PRESCRIPTION" .
>>                  ?docX :documentDateOfCreation ?docDateX .
>>          BIND( <java:dateadd.lib.pkgfor.arq.**
>> DateaddLibForARQ>("2012-03-22"**,
>> "-P30D") as ?teste )
>>
>>          FILTER ( ?docDateX >  ?teste )
>>
>>          }
>> }
>> limit 10
>>
>>
>> Thanks a lot!
>>
>>
>> --
>> diogo patrão
>>
>>
>

Re: BIND and custom functions on SPARQL

Posted by Andy Seaborne <an...@apache.org>.
Nowadays ARQ supports date/duration arithmetic (not ARQ 2.8.8)

"2012-03-22"^^xsd:date + "-P30D"^^xsd:duration
    ==>
"2012-02-21"^^xsd:date

You may not need the custom function.

The values must be of the right datatype but you can cast:

xsd:date("2012-03-22") + xsd:duration("-P30D")

 > 18:00:53 WARN  Loader               :: Class not found:
 > dateadd.lib.pkgfor.arq.DateaddLibForARQ
 > 18:00:53 WARN  exec                 :: URI
 > <java:dateadd.lib.pkgfor.arq.DateaddLibForARQ> has no registered 
function factory

The implementation isn't on the classpath at runtime.  It's warning, not 
an error. The same check doesn't seem to be happening for BIND  - maybe 
we should make it the symmetrical.

The use of a custom functions inside SERVICE isn't ideal.

	Andy



On 12/04/13 22:12, Diogo FC Patrao wrote:
> Hello all,
>
> I'm trying to run a SPARQL query specifiying a custom function (that does
> date arithmetics). On ARQ 2.8.8, the following code worked perfectly:
>
> PREFIX : <http://www.cipe.accamargo.org.br/ontologias/h2tc.owl#>
> PREFIX xmls: <http://www.w3.org/2001/XMLSchema#>
>
> select  * {
>
> SERVICE <http://0.0.0.0:2023/sparql> {
>                  :patient1 :hasDocument ?docX .
>
>                  ?docX :documentType "PRESCRIPTION" .
>                  ?docX :documentDateOfCreation ?docDateX .
>                 FILTER ( xmls:date(?docDateX) >
> :xmls:date(<java:dateadd.lib.pkgfor.arq.DateaddLibForARQ>("2012-03-22",
> "-P30D")) )
>
>          }
> }
> limit 10
>
> However, when specifying this function using arq 2.10.1-snapshot (4/3)
> (recompiled the library and updated cp), it complains :
>
> 18:00:53 WARN  Loader               :: Class not found:
> dateadd.lib.pkgfor.arq.DateaddLibForARQ
> 18:00:53 WARN  exec                 :: URI
> <java:dateadd.lib.pkgfor.arq.DateaddLibForARQ> has no registered function
> factory
>
>
> I could get the query working that way:
>
> select  * {
>
>   SERVICE <http://0.0.0.0:2023/sparql> {
>                  :patient1 :hasDocument ?docX .
>
>                  ?docX :documentType "PRESCRIPTION" .
>                  ?docX :documentDateOfCreation ?docDateX .
>          BIND( <java:dateadd.lib.pkgfor.arq.DateaddLibForARQ>("2012-03-22",
> "-P30D") as ?teste )
>
>          FILTER ( ?docDateX >  ?teste )
>
>          }
> }
> limit 10
>
>
> Thanks a lot!
>
>
> --
> diogo patrão
>