Using named graph in SPARQL

Hi there,

Need help...
I have uploaded my data into a named graph - kt:master in Studio (Databases >> Load Data >> Load Data To: kt.master) and issued the following query:

SELECT ?s ?o ?p
FROM kt:master
WHERE {
?s ?o ?p
}

I am expecting all triples from the graph to be returned here but am getting the following error:
Failed to run query: com.complexible.stardog.plan.eval.ExecutionException: com.complexible.common.rdf.query.parser.sparql.ast.VisitorException: QName 'kt:master' uses an undefined prefix

What am I doing wrong?

Additionally, where can I define kt:master to be the default graph to use? I tried Properties >> reasoning.schema.graphs >> tag:kt:master, but no triple is returned.

Thanks in advance.

Hi,

in case you have not defined kt as a namespace for your DB (DB -> Namespaces -> Add -> Save) before uploading the data, the Named Graph IRI will be <kt:master> (since kt:master itself is not a valid IRI). Otherwise, it will use the prefix definition accordingly. For instance, if you add data to stardog:master it will be added to the graph with IRI <tag:stardog:api:master> because stardog is in the default namespaces.

Since in your case the error message indicates that there is no prefix definition for kt, the data was added to <kt:master>. As a result, you would simply need to change your FROM statement as follows: FROM <kt:master>.
Alternatively, you can always check and select the named graphs in your DB in the query editor using the dropdown menu next to the dropdown for selecting the DB.

Similar to the the FROM statement, the dropdown allows you to select over which named graph(s) the query will be executed. For instance, you can execute the query over all graphs in the DB when you select stardog:context:all. (Using FROM stardog:context:all in your query has the same effect).

Alternatively, you can always use the following query to get all named graphs in your DB:

SELECT ?g
WHERE {
    GRAPH ?g {}
}

I hope this helps!

Best regards
Lars

Thanks Lars for the advice/tip:)