user3356568
user3356568

Reputation: 139

use FILTER on graph in SPARQL query

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

Upvotes: 3

Views: 1821

Answers (1)

AndyS
AndyS

Reputation: 16630

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(...).

Upvotes: 2

Related Questions