Selecting multiple types

A bit rusty on this one.

SELECT * where {
    ?s rdf:type :Tea | :Coffee .
} 

Why do I get an error?

| in SPARQL only works for predicates and not other positions in triple patterns. You need to expand:

{ ?s rdf:type :Tea } union { ?s rdf:type :Coffee }

Cheers,
Pavel

yes - indeed - thank you

How do I do in one statement without union? Drink as a superclass - but how?

If :Drink is a super class, you can simply enable reasoning and query for ?s rdf:type :Drink. The server will automatically rewrite the query into a union to get all drinks from the database. Otherwise I don't think you can have a disjunction in either subject or object position without an explicit union.

Cheers,
Pavel

ok - that helps.

What is the statement for creating Drink as a superclass for Tea and Coffee?

P.S. sorry for asking trivial questions - haven't had coffee this morning :wink:

For that you use statements like :Tea rdfs:subClassOf :Drink.

You can find more information in this tutorial: RDF Graph Data Model | Stardog Documentation Latest

Cheers,
Pavel

I am also trying this example at RDF Schema - Wikipedia

@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex:   <http://example.org/> .
@prefix zoo:   <http://example.org/zoo/> .
ex:dog1	   rdf:type	    ex:animal .
ex:cat1	   rdf:type	    ex:cat .
ex:cat	   rdfs:subClassOf  ex:animal .
zoo:host   rdfs:range	    ex:animal .
ex:zoo1	   zoo:host	    ex:cat2 .

However getting the error:

MalformedQuery: Encountered " <LANGTAG> "@prefix "" at line 1, column 1.
Was expecting one of:
    <EOF> 
    ";" ...
    <HINT> .

What exactly do you do with this RDF snippet? It kind of looks like you're running it as a SPARQL query...

just trying to use it as an example for my knowledge graph that has not super classes yet.

BTW - beatles tutorial triple count is 28 - but this query returns zero rows:

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

Check the prefix for : if it's not set its given a default but it might be using something other than the Stardog default.

Yes, when a query returns 0 results, you should first check your IRIs, e.g. prefixes. But I was commenting on the previous problem since things like <HINT> in Stardog only exist in the SPARQL grammar, and not in the Turtle grammar. So make sure you treat that snippet as data, not as a query.

Cheers,
Pavel

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.