databasesparqlrdftriplestoreblazegraph

How to filter IRI correctly in Blazegraph RDF?


How can I make a proper SPARQL query to filter out entities using their IRI? Currently, I am getting empty set when I try to filter by IRI.

I am using Blazegraph DB and I run this SPARQL query:

SELECT ?y ?p ?g
WHERE
> { ?y ?p ?g .
FILTER regex(?g, "Svet", "i") }


The result is the following: Result filter by Object

But when I run the query on the same data by subject:

SELECT ?y ?p ?g
WHERE
{ ?y ?p ?g .
  FILTER regex(?y, "www", "i") }

I get an empty result: Result filter by Subject


Solution

  • From SPARQL 1.1:

    17.4.3.14 REGEX

    xsd:boolean REGEX(string literal text, simple literal pattern)
    xsd:boolean REGEX(string literal text, simple literal pattern, simple literal flags)

    17.4.2.5 str

    simple literal STR(literal ltrl)
    simple literal STR(IRI rsrc)
    

    Returns the lexical form of ltrl (a literal); returns the codepoint representation of rsrc (an IRI). This is useful for examining parts of an IRI, for instance, the host-name.

    In Blazegraph, there is a query hint which is equivalent of always using str():

    hint:Query hint:regexMatchNonString true .
    

    There is also a system property which is equivalent of always using this query hint:

    -Dcom.bigdata.rdf.sparql.ast.QueryHints.regexMatchNonString=true