2. A Semantic Web framework
Jena API
ARQ/SPRQL
SDB/TDB
Inference
3.
4. Jena RDF API
// some definitions
String personURI = "http://somewhere/JohnSmith";
String givenName = "John";
String familyName = "Smith";
String fullName = givenName + " " + familyName;
// create an empty Model
Model model = ModelFactory.createDefaultModel();
// create the resource
// and add the properties cascading style
Resource johnSmith = model.createResource(personURI)
.addProperty(VCARD.FN, fullName)
.addProperty(VCARD.N,
model.createResource()
.addProperty(VCARD.Given, givenName)
.addProperty(VCARD.Family, familyName));
5. Jena Ontology API
// create the base model
String SOURCE = "http://www.eswc2006.org/technologies/ontology";
String NS = SOURCE + "#";
OntModel base = ModelFactory.createOntologyModel( OWL_MEM );
base.read( SOURCE, "RDF/XML" );
// create the reasoning model using the base
OntModel inf = ModelFactory.createOntologyModel( OWL_MEM_MICRO_RULE_INF, base );
// create a dummy paper for this example
OntClass paper = base.getOntClass( NS + "Paper" );
Individual p1 = base.createIndividual( NS + "paper1", paper );
// list the asserted types
for (Iterator i = p1.listRDFTypes(); i.hasNext(); ) {
System.out.println( p1.getURI() + " is asserted in class " + i.next() );
}
// list the inferred types
p1 = inf.getIndividual( NS + "paper1" );
for (Iterator i = p1.listRDFTypes(); i.hasNext(); ) {
System.out.println( p1.getURI() + " is inferred to be in class " + i.next() );
}
7. SDB
Store store = SDBFactory.connectStore("sdb.ttl") ;
Model model = SDBFactory.connectDefaultModel(store) ;
StmtIterator sIter = model.listStatements() ;
for ( ; sIter.hasNext() ; )
{
Statement stmt = sIter.nextStatement() ;
System.out.println(stmt) ;
}
sIter.close() ;
store.close() ;
8. TDB
TDB
// Direct way: Make a TDB-backed Jena model in the named directory.
String directory = "MyDatabases/DB1" ;
Model model = TDBFactory.createModel(directory) ;
...
model.close() ;
9. Inference
Model schema = FileManager.get().loadModel("file:data/owlDemoSchema.owl");
Model data = FileManager.get().loadModel("file:data/owlDemoData.rdf");
Reasoner reasoner = ReasonerRegistry.getOWLReasoner();reasoner =
reasoner.bindSchema(schema);InfModel infmodel =
ModelFactory.createInfModel(reasoner, data);