Re: Retrieving all classes

2009/8/14 On Lee <onlee2000@hotmail.com>:
> I am reading “A Semantic Web Primer, Second Edition” book. One of the
> examples (page 105) is
>
>
>
> PREFIX rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>
> PREFIX rdfs:    <http://www.w3.org/2000/01/rdf-schema#>
>
>
>
>  SELECT  ?c
>
>   WHERE {  ?c rdf:type rdfs:Class .  }
>
>
>
> It says that it will retrieve all classes.
>
>
>
> But when I executed it on Jena 2.6.0. It returned nothing. What did I do
> wrong? I’d appreciate any help/pointer.

It's hard to tell without seeing the data you're querying, but a
likely explanation is that there really aren't any resources of
rdf:type rdfs:Class there. SPARQL doesn't do any inferencing itself,
so for them to be picked up by the query such statements need to be
declared as instances in the data, e.g.

foaf:Person rdf:type rdfs:Class .
etc.

Alternately, if your instance data contains statements from which
inferences can be draw, e.g.

<#me> rdf:type foaf:Person .

you could use a model with inferencing support, see:

http://jena.sourceforge.net/inference/

(in this example from the RDFS axiom:

rdf:type rdfs:range rdfs:Class .

plus the RDFS rule:

aaa rdfs:range xxx .
uuu aaa vvv .
=>
vvv rdf:type xxx .
)

(btw, it's often convenient to load the vocabularies used alongside
instance data into a local store, kind of making it self-documenting,
additionally if you do have an inferencing model, giving you a load
more derived information).

Cheers,
Danny.

-- 
http://danny.ayers.name

Received on Sunday, 16 August 2009 12:37:45 UTC