Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use FILTER on graph in SPARQL query

Tags:

filter

sparql

I have thousands of quads/triples in knowledgebase Allegro Graph. I am using the following SPARQL query to find out the specific graph from knowledge base

SELECT ?subject ?predicate ?object ?graph
FROM Named <http://www.abc.com/xyz/abc123graphname>
WHERE {GRAPH ?graph
   {?subject ?predicate ?object .}}

This shows all quads that has graph name = http://www.abc.com/xyz/abc123graphname. But now I want to use FILTER to show only those quads that has graph name start with abc*.

such as

<http://www.abc.com/xyz/abc123graphname>
<http://www.abc.com/xyz/abc425graphname>
<http://www.abc.com/xyz/abc324graphname>

Please note that I have many graph names in my knowledge base such as

<http://www.abc.com/xyz/abc123graphname>
<http://www.abc.com/xyz/abc425graphname>
<http://www.abc.com/xyz/abc324graphname>
<http://www.abc.com/xyz/xyz123graphname>
<http://www.abc.com/xyz/samplegraphname>
<http://www.abc.com/xyz/vibergraphname>

Many Thanks in advance

like image 767
user3356568 Avatar asked Dec 18 '25 01:12

user3356568


1 Answers

You can filter on the graph name with some variation on:

   { GRAPH ?graph    {?subject ?predicate ?object .}
     FILTER( contains(str(?graph), "abc") )
   }

or use a different string test. Note the str(...).

like image 170
AndyS Avatar answered Dec 22 '25 15:12

AndyS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!