2 Replies Latest reply: Nov 29, 2011 3:28 PM by 366556 RSS

    SPARQL IN CLAUSE

    880207
      Hi,

      I want to use only SPARQL Query where i have to search within Triples for either of the input values. I mean similar to SQL's IN Clause.

      SQL - select * from employee where empid IN ('1','2','3');

      I want looking for a pure SPARQL query similar to above one.

      Thanks and Regards,
      Manish H
        • 1. Re: SPARQL IN CLAUSE
          366556
          Here's the way I handled this:

          SELECT x, o, y
          FROM TABLE(sem_MATCH(
          '{?x ?o ?y .
          filter ( ?x = v1:123 || v1:222 || v1:333 )
          }
          ',
          sem_Models('M1'),
          null,
          sem_Aliases (sem_Alias('v1', 'http://blah/a#')),
          null
          ))
          • 2. Re: SPARQL IN CLAUSE
            Matperry-Oracle
            Hi,

            SPARQL 1.1 supports an IN clause:
            http://www.w3.org/TR/2011/WD-sparql11-query-20110512/#func-in
            This SPARQL 1.1 feature is available in the latest Jena Adapter.

            For SEM_MATCH, you will need to use the SPARQL 1.0 approach of multiple expressions OR'ed together:
            filter ( ?x = v1:123 || ?x = v1:222 || ?x = v1:333 )

            There is a slight problem with the suggested filter (?x = v1:123 || v1:222 || v1:333 ) approach.
            This filter becomes ( (?x = v1:123) || EBV(v1:222) || EBV(v1:333) ), where EBV is SPARQL effective boolean value:
            http://www.w3.org/TR/rdf-sparql-query/#ebv
            This means that ?x is only compared with v1:123, as EBV tests on a URI will never evaluate to TRUE.

            Hope this helps,
            Matt