Semweb4j/rdfs/step1

From semanticweb.org

Jump to:navigation, search

Up | Previous lesson | Next step

Contents

[edit] Step 1: Overview

[edit] using default namespaces in RDF2Go

some namespace constants:

Java ObjectURI value
RDF.RDF_NShttp://www.w3.org/1999/02/22-rdf-syntax-ns#
RDFS.RDFS_NShttp://www.w3.org/2000/01/rdf-schema#
OWL.OWL_NShttp://www.w3.org/2002/07/owl#
XSD.XSD_NShttp://www.w3.org/2001/XMLSchema#
RDF.subjecthttp://www.w3.org/1999/02/22-rdf-syntax-ns#subject
RDF.Statementhttp://www.w3.org/1999/02/22-rdf-syntax-ns#Statement
RDFS.subClassOfhttp://www.w3.org/2000/01/rdf-schema#subClassOf
RDFS.Classhttp://www.w3.org/2000/01/rdf-schema#Class
OWL.Classhttp://www.w3.org/2002/07/owl#Class
OWL.maxCardinalityhttp://www.w3.org/2002/07/owl#maxCardinality
XSD._booleanhttp://www.w3.org/2001/XMLSchema#boolean
XSD._nonNegativeIntegerhttp://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.nonedisable reasoning explicitly
Reasoning.owlit's not yet decided which owl to use (Full, DL, Light)
Reasoning.rdfsAndOwl an experimental mix of some basic owl & rdfs concepts
Reasoning.rdfsnot 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
Navigation
services
Toolbox