3 Replies Latest reply on Aug 5, 2011 5:13 PM by alwu-Oracle

    Binding string values in SPARQL

    880359
      I'm having a problem implementing a bind parameter for a SPARQL query using the Jena Adapter. The examples provided in the documentation imply that all of the bound parameters will be URIs, either provided, or results of a subquery. I would like to be able to bind a string as a parameter to the orardf:textContains function.

      The existing SPARQL looks like so:

      PREFIX ORACLE_SEM_FS_NS:<http://oracle.com/semtech#timeout=5,BEST_EFFORT_QUERY=t,DEGREE=8>
      PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
      PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
      PREFIX orardf:<http://xmlns.oracle.com/rdf/>
      PREFIX ORACLE_SEM_HT_NS:<http://oracle.com/semtech#leading(?v,t2,t3,t0,t1)>
      select ?s ?l ?pl ?v
      where {
      ?s ?p ?v .
      ?s grantfile#grantFileLabel ?l .
      ?p rdfs:subPropertyOf grants-base:gmsDataProperty .
      ?p grants-base:propDisplayLabel ?pl .
      filter( orardf:textContains( ?v, "*<SEARCH_PATTERN>*" ))
      }

      Is there anyway to setup this query to BIND the *<SEARCH_PATTERN>* using PREFIX or some other way.
        • 1. Re: Binding string values in SPARQL
          alwu-Oracle
          Hi,

          Does this help?

          PREFIX orardf: <http://xmlns.oracle.com/rdf/>
          PREFIX dc: <http://purl.org/dc/elements/1.1/>
          PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
          PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
          PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
          PREFIX owl: <http://www.w3.org/2000/07/owl#>
          PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
          PREFIX ouext: <http://oracle.com/semtech/jena-adaptor/ext/user-def-function#>
          PREFIX oext: <http://oracle.com/semtech/jena-adaptor/ext/function#>
          PREFIX ORACLE_SEM_FS_NS:<http://oracle.com/semtech#timeout=5,BEST_EFFORT_QUERY=t,DEGREE=8>
          PREFIX ORACLE_SEM_UEAP_NS: <http://oracle.com/semtech#CONTAINS(V$_PREFIX%2C%3F)%3E0%20%0A>
          PREFIX ORACLE_SEM_UEPJ_NS: <http://oracle.com/semtech#V$_PREFIX>
          PREFIX ORACLE_SEM_UEBV_NS: <http://oracle.com/semtech#%25hello%25>
          select ?s ?l ?pl ?v
          where {
          ?s ?p ?v .
          ?s grantfile#grantFileLabel ?l .
          ?p rdfs:subPropertyOf grants-base:gmsDataProperty .
          ?p grants-base:propDisplayLabel ?pl .
          }

          The additional predicate (AP) is contains(v$_prefix,?)>0
          and for the bind value, I put in '%hello%' as an example.

          Cheers,

          Zhe Wu
          • 2. Re: Binding string values in SPARQL
            880359
            Zhe,
            Thanks for getting back to me. Maybe it is because I don't quite understand what you have done but that doesn't seem to have worked, at least not the way I expect.

            A bit more background. The Knowledge Base is about 40 million triples in 11g r2.0.2. We have a Java front end that is allowing users to search the knowledge base by entering text strings. We interact with the store using the Jena Adapter (v2.6.2 of Jena).

            The current query, provided above, actually works quite well most of the time, but it appears that there is some sort of caching being done that I had hoped the binds would help. The first time a query is executed it may timeout, or may return only a handfull of results. If I run it again immediately, it will return the whole result set as if there were no timeouts. Here are a couple of examples with times:

            First Test: Search for "Urban"
            RUN 1:
            PREFIX ORACLE_SEM_FS_NS:<http://oracle.com/semtech#timeout=5,BEST_EFFORT_QUERY=t,DEGREE=8> PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX grants-base:<http://grants.ojp.usdoj.gov/ontology/common/grants-base#> PREFIX orardf:<http://xmlns.oracle.com/rdf/> PREFIX ORACLE_SEM_HT_NS:<http://oracle.com/semtech#leading(?v,t2,t3,t0,t1)> select ?s ?l ?pl ?v where {
            ?s ?p ?v . ?s <http://grants.ojp.usdoj.gov/ontology/gms/grantfile#grantFileLabel> ?l . ?p rdfs:subPropertyOf grants-base:gmsDataProperty . ?p grants-base:propDisplayLabel ?pl . filter( orardf:textContains( ?v, "Urban" ))}
            DEBUG[2011-08-05 09:05:49,498] - [service:debugQuery:202] - ( 0 processed in 0:00:32.578)

            RUN 2:
            Query is same as Above
            DEBUG[2011-08-05 09:08:30,872] - [service:debugQuery:202] - ( 532 processed in 0:00:04.265)

            RUN 3:
            Query is same as Above
            DEBUG[2011-08-05 09:09:23,262] - [service:debugQuery:202] - ( 532 processed in 0:00:01.250)

            Second Test: Search for "Juvenile"
            RUN 1:
            DEBUG[2011-08-05 09:16:22,588] - [service:debugQuery:202] - ( 0 processed in 0:00:06.078)

            RUN 2:
            DEBUG[2011-08-05 09:18:01,072] - [service:debugQuery:202] - ( 1 processed in 0:00:52.172)

            RUN 3:
            DEBUG[2011-08-05 09:19:21,602] - [service:debugQuery:202] - ( 1001 processed in 0:00:57.999)

            RUN 4:
            DEBUG[2011-08-05 09:20:03,477] - [service:debugQuery:202] - ( 1001 processed in 0:00:07.031)


            The problem is that each different search seems to have the same/similar problems. If I change the search criteria, the first search is slow, the subsequent ones are quite fast. Am I barking up the wrong tree with parameter binding? Is there some other way that I can do it?

            As a side note, I'm going to write a second post regarding the fact that the BEQ/Timeout doesn't seem to behave consistently.

            Regards,
            J.P.
            • 3. Re: Binding string values in SPARQL
              alwu-Oracle
              Hi J.P.

              It is very likely that a brand new SQL query runs slower (sometimes a lot slower) for the first time than subsequent runs. Parsing time is shorter for subsequent runs. More importantly, less I/Os (because data have already been brought into memory after the first run) can contribute to a faster execution. The latter does not have much to do with the parameter binding.

              We can continue the inconsistent timeout discussion in the other thread you started.

              Thanks,

              Zhe Wu
              1 person found this helpful