SPARQL Kit Issue

Hi everyone,

as you will see from the question, I am just beginning to learn about graph databases. I am trying to go through the SPARQL Kit, but as soon as I start writing queries I get nothing.

If I write the return all query like below, I get the results.

SELECT *

WHERE{
?s ?p ?0 .
}

However, any other query does not work, including those from the kit. I am not sure what I am doing wrong, so any help is welcome.

Thanks!

The default namespace is not set correctly for this kit. We're sorry for any confusion that this has caused!

To work through this kit with minimal changes, please navigate to the Databases hub, Namespace tab, change the IRI for the blank prefix from http://api.stardog.com/ to http://stardog.com/tutorial/, and save the change.

The tutorial queries should run as expected.

1 Like

Thank you for the quick response Laura :slight_smile:
Would it be an issue to elaborate a bit further on the issue, what does the default namespace actually do? Just so I can undestand what is going on behind the scenes, it could help in the future.

Sure!

Stardog uses namespaces to help reduce the text needed in each query. Namespaces can be considered variables and are pairs of prefixes and IRIs. The prefix is a variable for the full IRI.

So instead of writing,

SELECT ?album
WHERE {
   ?album rdf:type <http://stardog.com/tutorial/Album> .
}

You can use a namespace so that you don't have to write out http://stardog.com/tutorial/ every time. Stardog includes a few common namespaces by default for each database.

Query when the namespace is defined:

SELECT ?album
WHERE {
   ?album rdf:type :Album .
}

Stardog will replace : (the blank prefix) with the full IRI from the namespace pair, http://stardog.com/tutorial/.

Alternatively, prefixes can be defined in the same tab in the workspace above your query.

@prefix : <http://stardog.com/tutorial/> .

SELECT ?album
WHERE {
   ?album rdf:type :Album .
}

The issue with the kit is that the namespace with the blank prefix was set to http://api.stardog.com/ instead of http://stardog.com/tutorial/. Therefore when you running the query:

SELECT ?album
WHERE {
   ?album rdf:type :Album .
}

It was interpreted as

SELECT ?album
WHERE {
   ?album rdf:type <http://api.stardog.com/Album> .
}

And since there are no instances of http://api.stardog.com/Album (only instances of http://stardog.com/tutorial/Album) no results were being returned.

This training also might be helpful for understanding some of the fundamentals of RDF and SPARQL.

1 Like

Hello,
I completed the "Getting Started...Learn SPARQL" using the Beatles and music DB's. Now, I'm trying to apply my learning to the Customer 360 Knowledge Kit. I made the namespace change recommended above, but I'm still getting zero results from a basic Select Profile. I would expect a list of customers from this query:


What am I missing?
Thx,
Jim

Hi Jim,

:Profile (or more accurately, http://stardog.com/tutorial/Profile) doesn't refer to anything in this demo kit. The query you're looking for is:

prefix acme: <http://acme.com/> 

select * 
{
    ?s a acme:ProfileId ;
}

To avoid having to type out the acme prefix every time, you can add it to the namespaces tab like Laura mentioned above for the default prefix.

I'm sure you're wondering how you could've figured this out yourself. When I looked into it, I ran a simple SELECT * { ?s ?p ?o } LIMIT 10. I got lucky [1], and the first results were all of the form:
http://acme.com/profile_id_1 rdf:type http://acme.com/ProfileId

I figured this was what I was looking for, so I tried to see if this could get me results on Kathy Escobar, who's searched for in the first and third gifs of the kit page.

select * 
{
    ?s a acme:ProfileId ;
       acme:fullName "Kathy Escobar" .
}

This gave me the result http://acme.com/profile_id_19, which is the same IRI we see in those gifs.

Let me know if that answers your question.

Best,
Steve

[1] Obviously you can't always expect to get lucky when searching this way. In most real world situations, you have access to the data that went into the database, so you can search through the data directly to find the IRI you were looking for.

Thanks, @StevePlace; fixing the prefix and using ProfileId resulted in a list of IRIs.
What's the difference between ProfileId and Profile?

I started with Profile, as it seemed to be the node containing customers. I saw Profile in Explorer both in the Query Builder and the schema:

Profile is a class, which is why you see it in Explorer. ProfileId is the unique identifier for each of the instances of the Profile class.

Seeing the Models tab of Studio might help. You can see ProfileId above studio:label and that rdfs:label is equal to Profile.

Best,
Steve