SPARQL - Restricting Result Resource to Certain Namespace(s) -
is there standard way of restricting results of sparql query belong specific namespace.
short answer - no there no standard direct way this
long answer - yes can limited form of string functions , filter
clause. function use depends on version of sparql engine supports.
sparql 1.1 solution
almost implementations these days support sparql 1.1 , can use strstarts()
function so:
filter(strstarts(str(?var), "http://example.org/ns#"))
this preferred approach , should relatively efficient because simple string matching.
sparql 1.0 solution
if stuck using implementation supports sparql 1.0 can still uses regular expressions via regex()
function slower:
filter(regex(str(?var), "^http://example\\.org/ns#"))
regular expressions , meta-characters
note regular expression have escape meta-character .
otherwise match character e.g. http://examplexorg/ns#foo
considered valid match.
as \
escape character both regular expressions , sparql strings has double escaped here in order regular expression have \.
in , treat .
literal character.
recommendation
if can use sparql 1.1 because using simpler string functions more performant , avoids need worry escaping meta-characters have when using regex
Comments
Post a Comment