3

I'm trying to run this query in the SPARQL playground on GraphDB.

select * where { 
    ?s content:value ?value .
    FILTER REGEX(str(?value), "_:x1697BD364N0abcdd866d54")
} 

?value are BNodes

I'm trying to filter all values where the BNode ID is: _:x1697BD364N0abcdd866d54

I've tried a few different ways to filter by the ID:

  1. FILTER REGEX(str(?value), "#bnode-id")
  2. FILTER (?value), "#bnode-id")

but none was a success.

Questions:

  1. How would you filter based on a bnode id?
  2. Is it possible to STR(bnode) ?
ueeieiie
  • 1,412
  • 2
  • 15
  • 42

1 Answers1

4
  1. How would you filter based on a bnode id label?

See the tag info. In short, one can't rely on blank node labels in SPARQL queries:

There need not be any relation between a label _:a in the result set and a blank node in the data graph with the same label.

An application writer should not expect blank node labels in a query to refer to a particular blank node in the data.

If it is hard to distinguish blank nodes by their properties etc. in SPARQL, one can use GraphDB's internal resource identifiers.

PREFIX ent: <http://www.ontotext.com/owlim/entity#>
SELECT * {
    ?s content:value ?value .
    ?s ent:id ?id .
    FILTER (?id = 424242)
}

or

PREFIX ent: <http://www.ontotext.com/owlim/entity#>
SELECT * {
    ?s content:value ?value 
    BIND (ent:id(?s) AS ?id)
    FILTER (?id = 424242)
}

  1. Is it possible to STR(bnode)?

No. From 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).

Community
  • 1
  • 1
Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
  • That's nice I was looking for a way to filter by bnode id, because I was looking for a specific id which I had. The GraphDB identifier is not a number which can help me here. but anyway, thats a nice trick :) – ueeieiie Mar 31 '19 at 21:41
  • Do you have these blank node labels in your RDF file you want to import? These labels will change after importing. – Stanislav Kralin Mar 31 '19 at 22:04
  • @ueeiieu isn't it possible to identify the blank node by some of its properties? – UninformedUser Apr 01 '19 at 13:46
  • @AKSW It is possible. My questions was mostly theoretical. I wanted to know why can I get the Blanknode ID – ueeieiie Apr 01 '19 at 14:04