How to filter by BlankNode id

安稳与你 提交于 2020-06-27 17:07:12

问题


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) ?

回答1:


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

See the blank-nodes 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).



来源:https://stackoverflow.com/questions/55440728/how-to-filter-by-blanknode-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!