Semweb4j/rdfs/step1
From semanticweb.org
Up | Previous lesson | Next step
Contents |
[edit] Step 1: Overview
[edit] using default namespaces in RDF2Go
some namespace constants:
| Java Object | URI value |
|---|---|
| RDF.RDF_NS | http://www.w3.org/1999/02/22-rdf-syntax-ns# |
| RDFS.RDFS_NS | http://www.w3.org/2000/01/rdf-schema# |
| OWL.OWL_NS | http://www.w3.org/2002/07/owl# |
| XSD.XSD_NS | http://www.w3.org/2001/XMLSchema# |
| RDF.subject | http://www.w3.org/1999/02/22-rdf-syntax-ns#subject |
| RDF.Statement | http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement |
| RDFS.subClassOf | http://www.w3.org/2000/01/rdf-schema#subClassOf |
| RDFS.Class | http://www.w3.org/2000/01/rdf-schema#Class |
| OWL.Class | http://www.w3.org/2002/07/owl#Class |
| OWL.maxCardinality | http://www.w3.org/2002/07/owl#maxCardinality |
| XSD._boolean | http://www.w3.org/2001/XMLSchema#boolean |
| XSD._nonNegativeInteger | http://www.w3.org/2001/XMLSchema#nonNegativeInteger |
The underscore "_" used in the XSD class is necessary because some Java type names are keywords.
To use a namespace, e.g. OWL, you need to
import org.ontoware.rdf2go.vocabulary.OWL;
[edit] Enabling reasoning
Model model; Reasoning reasoning; reasoning = ...; model = modelFactory.createModel(reasoning); model.open();
with reasoning being one of
| Reasoning.none | disable reasoning explicitly |
| Reasoning.owl | it's not yet decided which owl to use (Full, DL, Light) |
| Reasoning.rdfsAndOwl | an experimental mix of some basic owl & rdfs concepts |
| Reasoning.rdfs | not 100% as defined by RDF Semantics but works better |
[edit] Using reasoning
To use reasoning, just query a model with reasoning enabled. As example, we will test RDFS' subClassOf transitivity. Don't be confused with the fact that in RDFS, every Class is subClassOf itself.
URI A = model.createURI("urn:A");
URI B = model.createURI("urn:B");
URI C = model.createURI("urn:C");
model.addStatement(B, RDFS.subClassOf, A);
model.addStatement(C, RDFS.subClassOf, B);
now let's see who is a superclass of C:
System.out.println("All superclasses of "+C+":");
ClosableIterator<? extends Statement> it = model.findStatements(C, RDFS.subClassOf, Variable.ANY);
while (it.hasNext()) {
System.out.println(it.next().getObject());
}
it.close();
[edit] output
All superclasses of urn:C: urn:B urn:C urn:A
