SlideShare a Scribd company logo
Processing OWL Ontologies using Java
Jena Ontology API

Raji GHAWI

30/03/2010
Outline



What is Jena ?
Reading an Existing Ontology







Classes
Properties
Individuals

Creating a New Ontology




30/03/2010

Classes
Properties
Individuales

2
What is Jena ?


Jena is a Java framework



for building Semantic Web applications
includes









30/03/2010

an RDF API
reading and writing RDF in RDF/XML, N3 and N-Triples
an OWL API
in-memory and persistent storage
SPARQL query engine

http://jena.sourceforge.net/

3
Example Ontology

Person
name
age
email

Professor

Student

Class

studentNumber

subClassOf
Object property

taughtBy

teach

Datatype property

enrolledIn
hasModule

Module
moduleName

30/03/2010

Diploma
diplomaName

4
Outline



What is Jena ?
Reading an Existing Ontology







Classes
Properties
Individuals

Creating a New Ontology




30/03/2010

Classes
Properties
Individuales

5
Create Ontology Model


Jena provides an ontology model that allows to specify:




Ontology language
Storage model
Inference mode

OntModel model = ModelFactory.createOntologyModel();



default settings:




30/03/2010

OWL-Full language
in-memory storage
RDFS inference

6
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);

OntModelSpec

Language profile

Storage model

Reasoner

OWL_MEM

OWL full

in-memory

none

OWL_MEM_TRANS_INF

OWL full

in-memory

transitive class-hierarchy inference

OWL_MEM_RULE_INF

OWL full

in-memory

rule-based reasoner with OWL rules

OWL_MEM_MICRO_RULE_INF

OWL full

in-memory

optimised rule-based reasoner with OWL rules

OWL_MEM_MINI_RULE_INF

OWL full

in-memory

rule-based reasoner with subset of OWL rules

OWL_DL_MEM

OWL DL

in-memory

none

OWL_DL_MEM_RDFS_INF

OWL DL

in-memory

rule reasoner with RDFS-level entailment-rules

OWL_DL_MEM_TRANS_INF

OWL DL

in-memory

transitive class-hierarchy inference

OWL_DL_MEM_RULE_INF

OWL DL

in-memory

rule-based reasoner with OWL rules

OWL_LITE_MEM

OWL Lite

in-memory

none

OWL_LITE_MEM_TRANS_INF

OWL Lite

in-memory

transitive class-hierarchy inference

OWL_LITE_MEM_RDFS_INF

OWL Lite

in-memory

rule reasoner with RDFS-level entailment-rules

OWL_LITE_MEM_RULES_INF

OWL Lite

in-memory

rule-based reasoner with OWL rules

DAML_MEM

DAML+OIL

in-memory

none

DAML_MEM_TRANS_INF

DAML+OIL

in-memory

transitive class-hierarchy inference

DAML_MEM_RDFS_INF

DAML+OIL

in-memory

rule reasoner with RDFS-level entailment-rules

DAML_MEM_RULE_INF

DAML+OIL

in-memory

rule-based reasoner with DAML rules

RDFS_MEM

RDFS

in-memory

none

RDFS_MEM_TRANS_INF

RDFS

in-memory

transitive class-hierarchy inference

RDFS_MEM_RDFS_INF

RDFS

in-memory

rule reasoner with RDFS-level entailment-rules

30/03/2010

7
Read a File into Ontology Model
String fileName = "univ.owl";
try {
File file = new File(fileName);
FileReader reader = new FileReader(file);
OntModel model = ModelFactory
.createOntologyModel(OntModelSpec.OWL_DL_MEM);
model.read(reader,null);
model.write(System.out,"RDF/XML-ABBREV");
} catch (Exception e) {
e.printStackTrace();
}

30/03/2010

8
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Retrieve Ontology Classes
Iterator classIter = model.listClasses();
while (classIter.hasNext()) {
OntClass ontClass = (OntClass) classIter.next();
String uri = ontClass.getURI();
if(uri != null)
System.out.println(uri);
}



We can also use ontClass.getLocalName() to get the class name only.
If a class has no name (e.g. a restriction class), then ontClass.getURI()
returns null.
http://www.something.com/myontology#Professor
http://www.something.com/myontology#Module
http://www.something.com/myontology#Diploma
http://www.something.com/myontology#Person
http://www.something.com/myontology#Student

30/03/2010

output

9
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Retrieve a Specified Class


A specifed class is called by its URI

String classURI = "http://www.something.com/myontology#Professor";
OntClass professor = model.getOntClass(classURI );
// ...



If we know the class name only, we can get its URI by concatenating the
ontology URI with the class name:

ClassURI = OntologyURI + ‘#’ + ClassName

30/03/2010

10
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Get the Ontology URI
String ontologyURI = null;
Iterator iter = model.listOntologies();
if(iter.hasNext()){
Ontology onto = (Ontology) iter.next();
ontologyURI = onto.getURI();
System.out.println("Ontology URI = "+ontologyURI);
}

String className = "Professor";
String classURI = ontologyURI+"#"+className;
OntClass professor = model.getOntClass(classURI );

30/03/2010

11
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Class Hierarchy
OntClass student = model.getOntClass(uri+"#Student");
System.out.println(student.getSuperClass());
System.out.println(student.getSubClass());
http://www.something.com/myontology#Person
null

OntClass person = model.getOntClass(uri+"#Person");
System.out.println(person.getSuperClass());
System.out.println(person.getSubClass());
null
http://www.something.com/myontology#Professor

30/03/2010

12
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Class Hierarchy
Iterator supIter = person.listSuperClasses();
while (supIter.hasNext()) {
OntClass sup = (OntClass) supIter.next();
System.out.println(sup);
}
System.out.println("----------------");
Iterator subIter = person.listSubClasses();
while (subIter.hasNext()) {
OntClass sub = (OntClass) subIter.next();
System.out.println(sub);
}
---------------http://www.something.com/myontology#Professor
http://www.something.com/myontology#Student

30/03/2010

13
Reading an Existing Ontology

Creating a New Ontology

Classes

Properties

Individuales

Class Hierarchy
true

direct sub-classes

false

all sub-classes (default)

true

direct super-classes

false

all super-classes (default)

listSubClasses(boolean)

listSuperClasses(boolean)

A

B, C

->

B, C, D

D.listSuperClasses(true)

->

C

C
D

30/03/2010

->

A.listSubClasses(false)

B

A.listSubClasses(true)

D.listSuperClasses(false) ->

C, A

14
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Class Hierarchy
<OntClass>.isHierarchyRoot()


This function returns true if this class is the root of the class
hierarchy in the model:



this class has owl:Thing as a direct super-class,
or it has no declared super-classes
owl:Thing

Professor

Person

30/03/2010

Module

Diploma

Student

15
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Intersection / Union / Complement
if(ontClass.isIntersectionClass()){
IntersectionClass intersection = ontClass.asIntersectionClass();
RDFList operands = intersection.getOperands();
for (int i = 0; i < operands.size(); i++) {
RDFNode rdfNode = operands.get(i);
...
}
} else if(ontClass.isUnionClass()){
UnionClass union = ontClass.asUnionClass();
RDFList operands = union.getOperands();
...
} else if(ontClass.isComplementClass()){
ComplementClass compl = ontClass.asComplementClass();
RDFList operands = compl.getOperands();
...
}

30/03/2010

16
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Retrieve the Properties of a Specified Class
OntClass student = model.getOntClass(uri+"#Student");
Iterator propIter = student.listDeclaredProperties();
while (propIter.hasNext()) {
OntProperty property = (OntProperty) propIter.next();
System.out.println(property.getLocalName());
}
output

studentNumber
age
personName
enrolledIn
email

true

directly associated properties

false

all properties (direct + inhereted)

listDeclaredProperties(boolean)
(default)
30/03/2010

17
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Property Types


1

Two ways to know whether a property is datatype property or
object property:
if(property.isObjectProperty()){
// ... this is an object property
} else if (property.isDatatypeProperty()){
// ... this is an datatype property
}

property.isFunctionalProperty();
property.isSymmetricProperty();
property.isTransitiveProperty();
property.isInverseOf(anotherProperty);

30/03/2010

18
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Property Types


Two ways to know whether a property is datatype property or
object property:
Resource propertyType = property.getRDFType();
System.out.println(propertyType);

2

if(propertyType.equals(OWL.DatatypeProperty)){
// ... this is an datatype property
} else if(propertyType.equals(OWL.ObjectProperty)){
// ... this is an object property
}

http://www.w3.org/2002/07/owl#DatatypeProperty
http://www.w3.org/2002/07/owl#DatatypeProperty
http://www.w3.org/2002/07/owl#DatatypeProperty
http://www.w3.org/2002/07/owl#ObjectProperty
http://www.w3.org/2002/07/owl#DatatypeProperty

30/03/2010

output

19
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Property Domain and Range
String propertyName = property.getLocalName();
String dom = "";
String rng = "";
if(property.getDomain()!=null)
dom = property.getDomain().getLocalName();
if(property.getRange()!=null)
rng = property.getRange().getLocalName();
System.out.println(propertyName +": t("+dom+") t -> ("+rng+") ");
listDeclaredProperties(boolean);

true

studentNumber:
enrolledIn:

(Student)
(Student)

false

studentNumber:
age:
personName:
enrolledIn:
email:

(Student)
(Person)
(Person)
(Student)
(Person)

30/03/2010

-> (string)
-> (Diploma)
->
->
->
->
->

output

(string)
(int)
(string)
(Diploma)
(string)
20
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Datatype Properties


list all datatype properties in the model:

Iterator iter = model.listDatatypeProperties();
while (iter.hasNext()) {
DatatypeProperty prop = (DatatypeProperty) iter.next();
String propName = prop.getLocalName();
String dom = "";
String rng = "";
if(prop.getDomain()!=null)
dom = prop.getDomain().getLocalName();
if(prop.getRange()!=null)
rng = prop.getRange().getLocalName();
System.out.println(propName +": t("+dom+") t -> ("+rng+") ");
}
diplomaName:
studentNumber:
moduleName:
age:
personName:
email:
30/03/2010

(Diploma)
(Student)
(Module)
(Person)
(Person)
(Person)

-> (string)
-> (string)
-> (string)
-> (int)
-> (string)
-> (string)

output

21
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Object Properties


list all object properties in the model:

Iterator iter = model.listObjectProperties();
while (iter.hasNext()) {
ObjectProperty prop = (ObjectProperty) iter.next();
String propName = prop.getLocalName();
String dom = "";
String rng = "";
if(prop.getDomain()!=null)
dom = prop.getDomain().getLocalName();
if(prop.getRange()!=null)
rng = prop.getRange().getLocalName();
System.out.println(propName +": t("+dom+") t -> ("+rng+") ");
}
enrolledIn:
hasModule:
taughtBy:
teach:

(Student) -> (Diploma)
(Diploma) -> (Module)
(Module) -> (Professor)
(Professor) -> (Module)

getInverse()
30/03/2010

→

output

(OntProperty)
22
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Other Types of Properties


Using the same way, we may list (iterate) other properties:

model.listFunctionalProperties()

model.listInverseFunctionalProperties()

model.listSymmetricProperties()

model.listTransitiveProperties()

30/03/2010

23
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Restrictions

if(ontClass.isRestriction()){
Restriction rest = ontClass.asRestriction();
OntProperty onProperty = rest.getOnProperty();
...
}

30/03/2010

24
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

AllValuesFrom / SomeValuesFrom

if(rest.isAllValuesFromRestriction()){
AllValuesFromRestriction avfr = rest.asAllValuesFromRestriction();
Resource avf = avfr.getAllValuesFrom();
...
}
if(rest.isSomeValuesFromRestriction()){
SomeValuesFromRestriction svfr = rest.asSomeValuesFromRestriction();
Resource svf = svfr.getSomeValuesFrom();
...
}

30/03/2010

25
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

HasValue

if(rest.isHasValueRestriction()){
HasValueRestriction hvr = rest.asHasValueRestriction();
RDFNode hv = hvr.getHasValue();
...
}

30/03/2010

26
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Cardinality / MinCardinality / MaxCardinality
if(rest.isCardinalityRestriction()){
CardinalityRestriction cr = rest.asCardinalityRestriction();
int card = cr.getCardinality();
...
}
if(rest.isMinCardinalityRestriction()){
MinCardinalityRestriction mcr = rest.asMinCardinalityRestriction();
int minCard = minCR.getMinCardinality();
...
}
if(rest.isMaxCardinalityRestriction()){
MaxCardinalityRestriction mcr = rest.asMaxCardinalityRestriction();
int maxCard = maxCR.getMaxCardinality();
...
}

30/03/2010

27
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Individuals


list all individuals in the model

Iterator individuals = model.listIndividuals();
while (individuals.hasNext()) {
Individual individual = (Individual) individuals.next();
...
}



list individuals of a specific class

Iterator iter = ontClass.listInstances();
while (iter.hasNext()) {
Individual individual = (Individual) iter.next();
...
}

30/03/2010

28
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Individuals


list properties and property values of an individual

Iterator props = individual.listProperties();
while (props.hasNext()) {
Property property = (Property) props.next();
RDFNode value = individual.getPropertyValue(property);
...
}



list values of a specific property of an individual

Iterator values = individual.listPropertyValues(property);
while (values.hasNext()) {
RDFNode value = values.next();
...
}

30/03/2010

29
Reading an Existing Ontology
Classes

Creating a New Ontology
Properties

Individuales

Individuals


get the class to which an individual belongs

Resource rdfType = individual.getRDFType();
OntClass ontClass = model.getOntClass(rdfType.getURI());



in recent versions of Jena

OntClass ontClass = individual.getOntClass();

30/03/2010

30
Outline



What is Jena ?
Reading an Existing Ontology







Classes
Properties
Individuals

Creating a New Ontology




30/03/2010

Classes
Properties
Individuales

31
Creating a New Ontology

Reading an Existing Ontology
Classes

Properties

Individuales

Create the ontology model
OntModel model =
ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);

String uriBase = "http://www.something.com/myontology";
model.createOntology(uriBase);

30/03/2010

32
Creating a New Ontology

Reading an Existing Ontology
Classes

Properties

Individuales

Create Classes
//create
OntClass
OntClass
OntClass
OntClass
OntClass

30/03/2010

classes
person = model.createClass(uriBase+"#Person");
module = model.createClass(uriBase+"#Module");
diploma = model.createClass(uriBase+"#Diploma");
student = model.createClass(uriBase+"#Student");
professor = model.createClass(uriBase+"#Professor");

33
Creating a New Ontology

Reading an Existing Ontology
Classes

Properties

Individuales

Set Sub-Classes

//set sub-classes
person.addSubClass(student);
person.addSubClass(professor);

30/03/2010

34
Creating a New Ontology

Reading an Existing Ontology
Classes

Properties

Individuales

Intersection / Union / Complement

RDFNode[] classes = new RDFNode[] {class1, class2, ...};
RDFList list = model.createList(classes);
IntersectionClass intersection =
model.createIntersectionClass(uri, list);
UnionClass union = model.createUnionClass(uri, list);
ComplementClass compl =
model.createComplementClass(uri, resource);

30/03/2010

35
Creating a New Ontology

Reading an Existing Ontology
Classes

Properties

Individuales

Create Datatype Properties

//create datatype properties
DatatypeProperty personName =
model.createDatatypeProperty(uriBase+"#personName");
personName.setDomain(person);
personName.setRange(XSD.xstring);
DatatypeProperty age = model.createDatatypeProperty(uriBase+"#age");
age.setDomain(person);
age.setRange(XSD.integer);
//

... ...

30/03/2010

36
Creating a New Ontology

Reading an Existing Ontology
Classes

Properties

Individuales

Create Object Properties
//create object properties
ObjectProperty teach = model.createObjectProperty(uriBase+"#teach");
teach.setDomain(professor);
teach.setRange(module);
ObjectProperty taughtBy =
model.createObjectProperty(uriBase+"#taughtBy");
taughtBy.setDomain(module);
taughtBy.setRange(professor);
ObjectProperty enrolledIn =
model.createObjectProperty(uriBase+"#enrolledIn");
enrolledIn.setDomain(student);
enrolledIn.setRange(diploma);
// ... ...
30/03/2010

37
Creating a New Ontology

Reading an Existing Ontology
Classes

Properties

Individuales

Inverse-of / Functional


set inverse properties

// set inverse properties
teach.setInverseOf(taughtBy);



set functional properties

// set functional properties
enrolledIn.setRDFType(OWL.FunctionalProperty);

30/03/2010

38
Creating a New Ontology

Reading an Existing Ontology
Classes

Properties

Individuales

Restrictions
usually, null

usually, a class

SomeValuesFromRestriction svfr =
model.createSomeValuesFromRestriction(uri, property, resource);
AllValuesFromRestriction avfr =
model.createAllValuesFromRestriction(uri, property, resource);
HasValueRestriction hvr =
model.createHasValueRestriction(uri, property, rdfNode);
CardinalityRestriction cr =
model.createCardinalityRestriction(uri, property, int);
MinCardinalityRestriction min_cr =
model.createMinCardinalityRestriction(uri, property, int);
MaxCardinalityRestriction max_cr =
model.createMaxCardinalityRestriction(uri, property, int);
30/03/2010

39
Creating a New Ontology

Reading an Existing Ontology
Classes

Properties

Individuales

Individuales


create an individual
Individual indv = ontClass.createIndividual(uri);

or
Individual indv = model.createIndividual(uri, ontClass);



set a property value of an individual
indv.setPropertyValue(property, rdfNode);

30/03/2010

40
Write Ontology Model


write the model to standard output

// write out the model
model.write(System.out,"RDF/XML-ABBREV");



save the model to a string

StringWriter sw = new StringWriter();
model.write(sw, "RDF/XML-ABBREV");
String owlCode = sw.toString();

30/03/2010

41
Save the Model to a File

File file = new File(filePath);
try{
FileWriter fw = new FileWriter(file);
fw.write(owlCode);
fw.close();
} catch(FileNotFoundException fnfe){
fnfe.printStackTrace();
} catch(IOException ioe){
ioe.printStackTrace();
}

30/03/2010

42
References


Jena Ontology API




http://jena.sourceforge.net/ontology/index.html

RDFS and OWL Reasoning Capabilities:


http://www-ksl.stanford.edu/software/jtp/doc/owl-reasoning.html

30/03/2010

43

More Related Content

What's hot (20)

PPTX
Java and SPARQL
Raji Ghawi
 
PDF
Spring Data JPA from 0-100 in 60 minutes
VMware Tanzu
 
PDF
Json in Postgres - the Roadmap
EDB
 
ODP
Introduction to Apache solr
Knoldus Inc.
 
PPTX
Model Your Application Domain, Not Your JSON Structures
Markus Lanthaler
 
PPTX
Reactjs
Neha Sharma
 
PDF
ES2015 / ES6: Basics of modern Javascript
Wojciech Dzikowski
 
PPTX
React workshop
Imran Sayed
 
PPTX
Hibernate ppt
Aneega
 
PPSX
Collections - Lists, Sets
Hitesh-Java
 
PPTX
React js
Oswald Campesato
 
PPTX
Introduction à spring boot
Antoine Rey
 
PPTX
Raster data in GeoServer and GeoTools: Achievements, issues and future devel...
GeoSolutions
 
PDF
Découverte de Elastic search
JEMLI Fathi
 
PPTX
Java database connectivity with MySql
Dhyey Dattani
 
PPTX
Graph database
Achintya Kumar
 
PDF
Spring Data JPA
Knoldus Inc.
 
PPTX
Avro introduction
Nanda8904648951
 
PPS
Jdbc architecture and driver types ppt
kamal kotecha
 
PDF
Spring Framework
NexThoughts Technologies
 
Java and SPARQL
Raji Ghawi
 
Spring Data JPA from 0-100 in 60 minutes
VMware Tanzu
 
Json in Postgres - the Roadmap
EDB
 
Introduction to Apache solr
Knoldus Inc.
 
Model Your Application Domain, Not Your JSON Structures
Markus Lanthaler
 
Reactjs
Neha Sharma
 
ES2015 / ES6: Basics of modern Javascript
Wojciech Dzikowski
 
React workshop
Imran Sayed
 
Hibernate ppt
Aneega
 
Collections - Lists, Sets
Hitesh-Java
 
Introduction à spring boot
Antoine Rey
 
Raster data in GeoServer and GeoTools: Achievements, issues and future devel...
GeoSolutions
 
Découverte de Elastic search
JEMLI Fathi
 
Java database connectivity with MySql
Dhyey Dattani
 
Graph database
Achintya Kumar
 
Spring Data JPA
Knoldus Inc.
 
Avro introduction
Nanda8904648951
 
Jdbc architecture and driver types ppt
kamal kotecha
 
Spring Framework
NexThoughts Technologies
 

Viewers also liked (6)

PDF
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
kgrandis
 
PDF
Face Recognition with OpenCV and scikit-learn
Shiqiao Du
 
PPTX
Face Recognition using OpenCV
Vasile Chelban
 
PDF
Semantic Web - Ontology 101
Luigi De Russis
 
PDF
Introduction to OpenCV (with Java)
Luigi De Russis
 
PDF
Introduction to OpenCV 3.x (with Java)
Luigi De Russis
 
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
kgrandis
 
Face Recognition with OpenCV and scikit-learn
Shiqiao Du
 
Face Recognition using OpenCV
Vasile Chelban
 
Semantic Web - Ontology 101
Luigi De Russis
 
Introduction to OpenCV (with Java)
Luigi De Russis
 
Introduction to OpenCV 3.x (with Java)
Luigi De Russis
 
Ad

Similar to Java and OWL (20)

PPTX
Jarrar: OWL -Web Ontology Language
Mustafa Jarrar
 
PDF
Jarrar: OWL (Web Ontology Language)
Mustafa Jarrar
 
PDF
eureka09
tutorialsruby
 
PDF
eureka09
tutorialsruby
 
PPT
Web ontology language (owl)
Ameer Sameer
 
PPT
OWL briefing
Frank van Harmelen
 
PDF
OWL Web Ontology Language Overview
Igor Myroshnichenko
 
PPTX
Semantic web Technology
Abdelrahman Ibrahim
 
PPTX
SWT Lecture Session 8 - Inference in jena
Mariano Rodriguez-Muro
 
PPT
Intro to OWL & Ontology
Narni Rajesh
 
PPT
Jena framework
Marakana Inc.
 
PPT
Rinke Owl Uml 20040428
Rinke Hoekstra
 
PPT
Semantic web
tariq1352
 
PDF
Rdf data-model-and-storage
灿辉 葛
 
PPT
RDF and OWL
Rachel Lovinger
 
PPTX
OBA: An Ontology-Based Framework for Creating REST APIs for Knowledge Graphs
dgarijo
 
PPT
Establishing a Bridge from Graph-based Modeling Languages to Ontology Languages
Tobias Walter
 
PDF
OWL 2 Overview
Emiliano Reynares
 
PPT
sw owl
abdollahtaghipour
 
PPTX
Semantic DEX Components
David Price
 
Jarrar: OWL -Web Ontology Language
Mustafa Jarrar
 
Jarrar: OWL (Web Ontology Language)
Mustafa Jarrar
 
eureka09
tutorialsruby
 
eureka09
tutorialsruby
 
Web ontology language (owl)
Ameer Sameer
 
OWL briefing
Frank van Harmelen
 
OWL Web Ontology Language Overview
Igor Myroshnichenko
 
Semantic web Technology
Abdelrahman Ibrahim
 
SWT Lecture Session 8 - Inference in jena
Mariano Rodriguez-Muro
 
Intro to OWL & Ontology
Narni Rajesh
 
Jena framework
Marakana Inc.
 
Rinke Owl Uml 20040428
Rinke Hoekstra
 
Semantic web
tariq1352
 
Rdf data-model-and-storage
灿辉 葛
 
RDF and OWL
Rachel Lovinger
 
OBA: An Ontology-Based Framework for Creating REST APIs for Knowledge Graphs
dgarijo
 
Establishing a Bridge from Graph-based Modeling Languages to Ontology Languages
Tobias Walter
 
OWL 2 Overview
Emiliano Reynares
 
Semantic DEX Components
David Price
 
Ad

More from Raji Ghawi (11)

PPTX
Database Programming Techniques
Raji Ghawi
 
PPTX
Java and XML Schema
Raji Ghawi
 
PPTX
Java and XML
Raji Ghawi
 
PPTX
SPARQL
Raji Ghawi
 
PPTX
XQuery
Raji Ghawi
 
PPTX
XPath
Raji Ghawi
 
PPT
Ontology-based Cooperation of Information Systems
Raji Ghawi
 
PPT
OWSCIS: Ontology and Web Service based Cooperation of Information Sources
Raji Ghawi
 
PPT
Coopération des Systèmes d'Informations basée sur les Ontologies
Raji Ghawi
 
PPT
Building Ontologies from Multiple Information Sources
Raji Ghawi
 
PPT
Database-to-Ontology Mapping Generation for Semantic Interoperability
Raji Ghawi
 
Database Programming Techniques
Raji Ghawi
 
Java and XML Schema
Raji Ghawi
 
Java and XML
Raji Ghawi
 
SPARQL
Raji Ghawi
 
XQuery
Raji Ghawi
 
XPath
Raji Ghawi
 
Ontology-based Cooperation of Information Systems
Raji Ghawi
 
OWSCIS: Ontology and Web Service based Cooperation of Information Sources
Raji Ghawi
 
Coopération des Systèmes d'Informations basée sur les Ontologies
Raji Ghawi
 
Building Ontologies from Multiple Information Sources
Raji Ghawi
 
Database-to-Ontology Mapping Generation for Semantic Interoperability
Raji Ghawi
 

Recently uploaded (20)

PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 

Java and OWL

  • 1. Processing OWL Ontologies using Java Jena Ontology API Raji GHAWI 30/03/2010
  • 2. Outline   What is Jena ? Reading an Existing Ontology     Classes Properties Individuals Creating a New Ontology    30/03/2010 Classes Properties Individuales 2
  • 3. What is Jena ?  Jena is a Java framework   for building Semantic Web applications includes       30/03/2010 an RDF API reading and writing RDF in RDF/XML, N3 and N-Triples an OWL API in-memory and persistent storage SPARQL query engine http://jena.sourceforge.net/ 3
  • 5. Outline   What is Jena ? Reading an Existing Ontology     Classes Properties Individuals Creating a New Ontology    30/03/2010 Classes Properties Individuales 5
  • 6. Create Ontology Model  Jena provides an ontology model that allows to specify:    Ontology language Storage model Inference mode OntModel model = ModelFactory.createOntologyModel();  default settings:    30/03/2010 OWL-Full language in-memory storage RDFS inference 6
  • 7. OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM); OntModelSpec Language profile Storage model Reasoner OWL_MEM OWL full in-memory none OWL_MEM_TRANS_INF OWL full in-memory transitive class-hierarchy inference OWL_MEM_RULE_INF OWL full in-memory rule-based reasoner with OWL rules OWL_MEM_MICRO_RULE_INF OWL full in-memory optimised rule-based reasoner with OWL rules OWL_MEM_MINI_RULE_INF OWL full in-memory rule-based reasoner with subset of OWL rules OWL_DL_MEM OWL DL in-memory none OWL_DL_MEM_RDFS_INF OWL DL in-memory rule reasoner with RDFS-level entailment-rules OWL_DL_MEM_TRANS_INF OWL DL in-memory transitive class-hierarchy inference OWL_DL_MEM_RULE_INF OWL DL in-memory rule-based reasoner with OWL rules OWL_LITE_MEM OWL Lite in-memory none OWL_LITE_MEM_TRANS_INF OWL Lite in-memory transitive class-hierarchy inference OWL_LITE_MEM_RDFS_INF OWL Lite in-memory rule reasoner with RDFS-level entailment-rules OWL_LITE_MEM_RULES_INF OWL Lite in-memory rule-based reasoner with OWL rules DAML_MEM DAML+OIL in-memory none DAML_MEM_TRANS_INF DAML+OIL in-memory transitive class-hierarchy inference DAML_MEM_RDFS_INF DAML+OIL in-memory rule reasoner with RDFS-level entailment-rules DAML_MEM_RULE_INF DAML+OIL in-memory rule-based reasoner with DAML rules RDFS_MEM RDFS in-memory none RDFS_MEM_TRANS_INF RDFS in-memory transitive class-hierarchy inference RDFS_MEM_RDFS_INF RDFS in-memory rule reasoner with RDFS-level entailment-rules 30/03/2010 7
  • 8. Read a File into Ontology Model String fileName = "univ.owl"; try { File file = new File(fileName); FileReader reader = new FileReader(file); OntModel model = ModelFactory .createOntologyModel(OntModelSpec.OWL_DL_MEM); model.read(reader,null); model.write(System.out,"RDF/XML-ABBREV"); } catch (Exception e) { e.printStackTrace(); } 30/03/2010 8
  • 9. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Retrieve Ontology Classes Iterator classIter = model.listClasses(); while (classIter.hasNext()) { OntClass ontClass = (OntClass) classIter.next(); String uri = ontClass.getURI(); if(uri != null) System.out.println(uri); }   We can also use ontClass.getLocalName() to get the class name only. If a class has no name (e.g. a restriction class), then ontClass.getURI() returns null. http://www.something.com/myontology#Professor http://www.something.com/myontology#Module http://www.something.com/myontology#Diploma http://www.something.com/myontology#Person http://www.something.com/myontology#Student 30/03/2010 output 9
  • 10. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Retrieve a Specified Class  A specifed class is called by its URI String classURI = "http://www.something.com/myontology#Professor"; OntClass professor = model.getOntClass(classURI ); // ...  If we know the class name only, we can get its URI by concatenating the ontology URI with the class name: ClassURI = OntologyURI + ‘#’ + ClassName 30/03/2010 10
  • 11. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Get the Ontology URI String ontologyURI = null; Iterator iter = model.listOntologies(); if(iter.hasNext()){ Ontology onto = (Ontology) iter.next(); ontologyURI = onto.getURI(); System.out.println("Ontology URI = "+ontologyURI); } String className = "Professor"; String classURI = ontologyURI+"#"+className; OntClass professor = model.getOntClass(classURI ); 30/03/2010 11
  • 12. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Class Hierarchy OntClass student = model.getOntClass(uri+"#Student"); System.out.println(student.getSuperClass()); System.out.println(student.getSubClass()); http://www.something.com/myontology#Person null OntClass person = model.getOntClass(uri+"#Person"); System.out.println(person.getSuperClass()); System.out.println(person.getSubClass()); null http://www.something.com/myontology#Professor 30/03/2010 12
  • 13. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Class Hierarchy Iterator supIter = person.listSuperClasses(); while (supIter.hasNext()) { OntClass sup = (OntClass) supIter.next(); System.out.println(sup); } System.out.println("----------------"); Iterator subIter = person.listSubClasses(); while (subIter.hasNext()) { OntClass sub = (OntClass) subIter.next(); System.out.println(sub); } ---------------http://www.something.com/myontology#Professor http://www.something.com/myontology#Student 30/03/2010 13
  • 14. Reading an Existing Ontology Creating a New Ontology Classes Properties Individuales Class Hierarchy true direct sub-classes false all sub-classes (default) true direct super-classes false all super-classes (default) listSubClasses(boolean) listSuperClasses(boolean) A B, C -> B, C, D D.listSuperClasses(true) -> C C D 30/03/2010 -> A.listSubClasses(false) B A.listSubClasses(true) D.listSuperClasses(false) -> C, A 14
  • 15. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Class Hierarchy <OntClass>.isHierarchyRoot()  This function returns true if this class is the root of the class hierarchy in the model:   this class has owl:Thing as a direct super-class, or it has no declared super-classes owl:Thing Professor Person 30/03/2010 Module Diploma Student 15
  • 16. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Intersection / Union / Complement if(ontClass.isIntersectionClass()){ IntersectionClass intersection = ontClass.asIntersectionClass(); RDFList operands = intersection.getOperands(); for (int i = 0; i < operands.size(); i++) { RDFNode rdfNode = operands.get(i); ... } } else if(ontClass.isUnionClass()){ UnionClass union = ontClass.asUnionClass(); RDFList operands = union.getOperands(); ... } else if(ontClass.isComplementClass()){ ComplementClass compl = ontClass.asComplementClass(); RDFList operands = compl.getOperands(); ... } 30/03/2010 16
  • 17. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Retrieve the Properties of a Specified Class OntClass student = model.getOntClass(uri+"#Student"); Iterator propIter = student.listDeclaredProperties(); while (propIter.hasNext()) { OntProperty property = (OntProperty) propIter.next(); System.out.println(property.getLocalName()); } output studentNumber age personName enrolledIn email true directly associated properties false all properties (direct + inhereted) listDeclaredProperties(boolean) (default) 30/03/2010 17
  • 18. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Property Types  1 Two ways to know whether a property is datatype property or object property: if(property.isObjectProperty()){ // ... this is an object property } else if (property.isDatatypeProperty()){ // ... this is an datatype property } property.isFunctionalProperty(); property.isSymmetricProperty(); property.isTransitiveProperty(); property.isInverseOf(anotherProperty); 30/03/2010 18
  • 19. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Property Types  Two ways to know whether a property is datatype property or object property: Resource propertyType = property.getRDFType(); System.out.println(propertyType); 2 if(propertyType.equals(OWL.DatatypeProperty)){ // ... this is an datatype property } else if(propertyType.equals(OWL.ObjectProperty)){ // ... this is an object property } http://www.w3.org/2002/07/owl#DatatypeProperty http://www.w3.org/2002/07/owl#DatatypeProperty http://www.w3.org/2002/07/owl#DatatypeProperty http://www.w3.org/2002/07/owl#ObjectProperty http://www.w3.org/2002/07/owl#DatatypeProperty 30/03/2010 output 19
  • 20. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Property Domain and Range String propertyName = property.getLocalName(); String dom = ""; String rng = ""; if(property.getDomain()!=null) dom = property.getDomain().getLocalName(); if(property.getRange()!=null) rng = property.getRange().getLocalName(); System.out.println(propertyName +": t("+dom+") t -> ("+rng+") "); listDeclaredProperties(boolean); true studentNumber: enrolledIn: (Student) (Student) false studentNumber: age: personName: enrolledIn: email: (Student) (Person) (Person) (Student) (Person) 30/03/2010 -> (string) -> (Diploma) -> -> -> -> -> output (string) (int) (string) (Diploma) (string) 20
  • 21. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Datatype Properties  list all datatype properties in the model: Iterator iter = model.listDatatypeProperties(); while (iter.hasNext()) { DatatypeProperty prop = (DatatypeProperty) iter.next(); String propName = prop.getLocalName(); String dom = ""; String rng = ""; if(prop.getDomain()!=null) dom = prop.getDomain().getLocalName(); if(prop.getRange()!=null) rng = prop.getRange().getLocalName(); System.out.println(propName +": t("+dom+") t -> ("+rng+") "); } diplomaName: studentNumber: moduleName: age: personName: email: 30/03/2010 (Diploma) (Student) (Module) (Person) (Person) (Person) -> (string) -> (string) -> (string) -> (int) -> (string) -> (string) output 21
  • 22. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Object Properties  list all object properties in the model: Iterator iter = model.listObjectProperties(); while (iter.hasNext()) { ObjectProperty prop = (ObjectProperty) iter.next(); String propName = prop.getLocalName(); String dom = ""; String rng = ""; if(prop.getDomain()!=null) dom = prop.getDomain().getLocalName(); if(prop.getRange()!=null) rng = prop.getRange().getLocalName(); System.out.println(propName +": t("+dom+") t -> ("+rng+") "); } enrolledIn: hasModule: taughtBy: teach: (Student) -> (Diploma) (Diploma) -> (Module) (Module) -> (Professor) (Professor) -> (Module) getInverse() 30/03/2010 → output (OntProperty) 22
  • 23. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Other Types of Properties  Using the same way, we may list (iterate) other properties: model.listFunctionalProperties() model.listInverseFunctionalProperties() model.listSymmetricProperties() model.listTransitiveProperties() 30/03/2010 23
  • 24. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Restrictions if(ontClass.isRestriction()){ Restriction rest = ontClass.asRestriction(); OntProperty onProperty = rest.getOnProperty(); ... } 30/03/2010 24
  • 25. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales AllValuesFrom / SomeValuesFrom if(rest.isAllValuesFromRestriction()){ AllValuesFromRestriction avfr = rest.asAllValuesFromRestriction(); Resource avf = avfr.getAllValuesFrom(); ... } if(rest.isSomeValuesFromRestriction()){ SomeValuesFromRestriction svfr = rest.asSomeValuesFromRestriction(); Resource svf = svfr.getSomeValuesFrom(); ... } 30/03/2010 25
  • 26. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales HasValue if(rest.isHasValueRestriction()){ HasValueRestriction hvr = rest.asHasValueRestriction(); RDFNode hv = hvr.getHasValue(); ... } 30/03/2010 26
  • 27. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Cardinality / MinCardinality / MaxCardinality if(rest.isCardinalityRestriction()){ CardinalityRestriction cr = rest.asCardinalityRestriction(); int card = cr.getCardinality(); ... } if(rest.isMinCardinalityRestriction()){ MinCardinalityRestriction mcr = rest.asMinCardinalityRestriction(); int minCard = minCR.getMinCardinality(); ... } if(rest.isMaxCardinalityRestriction()){ MaxCardinalityRestriction mcr = rest.asMaxCardinalityRestriction(); int maxCard = maxCR.getMaxCardinality(); ... } 30/03/2010 27
  • 28. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Individuals  list all individuals in the model Iterator individuals = model.listIndividuals(); while (individuals.hasNext()) { Individual individual = (Individual) individuals.next(); ... }  list individuals of a specific class Iterator iter = ontClass.listInstances(); while (iter.hasNext()) { Individual individual = (Individual) iter.next(); ... } 30/03/2010 28
  • 29. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Individuals  list properties and property values of an individual Iterator props = individual.listProperties(); while (props.hasNext()) { Property property = (Property) props.next(); RDFNode value = individual.getPropertyValue(property); ... }  list values of a specific property of an individual Iterator values = individual.listPropertyValues(property); while (values.hasNext()) { RDFNode value = values.next(); ... } 30/03/2010 29
  • 30. Reading an Existing Ontology Classes Creating a New Ontology Properties Individuales Individuals  get the class to which an individual belongs Resource rdfType = individual.getRDFType(); OntClass ontClass = model.getOntClass(rdfType.getURI());  in recent versions of Jena OntClass ontClass = individual.getOntClass(); 30/03/2010 30
  • 31. Outline   What is Jena ? Reading an Existing Ontology     Classes Properties Individuals Creating a New Ontology    30/03/2010 Classes Properties Individuales 31
  • 32. Creating a New Ontology Reading an Existing Ontology Classes Properties Individuales Create the ontology model OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM); String uriBase = "http://www.something.com/myontology"; model.createOntology(uriBase); 30/03/2010 32
  • 33. Creating a New Ontology Reading an Existing Ontology Classes Properties Individuales Create Classes //create OntClass OntClass OntClass OntClass OntClass 30/03/2010 classes person = model.createClass(uriBase+"#Person"); module = model.createClass(uriBase+"#Module"); diploma = model.createClass(uriBase+"#Diploma"); student = model.createClass(uriBase+"#Student"); professor = model.createClass(uriBase+"#Professor"); 33
  • 34. Creating a New Ontology Reading an Existing Ontology Classes Properties Individuales Set Sub-Classes //set sub-classes person.addSubClass(student); person.addSubClass(professor); 30/03/2010 34
  • 35. Creating a New Ontology Reading an Existing Ontology Classes Properties Individuales Intersection / Union / Complement RDFNode[] classes = new RDFNode[] {class1, class2, ...}; RDFList list = model.createList(classes); IntersectionClass intersection = model.createIntersectionClass(uri, list); UnionClass union = model.createUnionClass(uri, list); ComplementClass compl = model.createComplementClass(uri, resource); 30/03/2010 35
  • 36. Creating a New Ontology Reading an Existing Ontology Classes Properties Individuales Create Datatype Properties //create datatype properties DatatypeProperty personName = model.createDatatypeProperty(uriBase+"#personName"); personName.setDomain(person); personName.setRange(XSD.xstring); DatatypeProperty age = model.createDatatypeProperty(uriBase+"#age"); age.setDomain(person); age.setRange(XSD.integer); // ... ... 30/03/2010 36
  • 37. Creating a New Ontology Reading an Existing Ontology Classes Properties Individuales Create Object Properties //create object properties ObjectProperty teach = model.createObjectProperty(uriBase+"#teach"); teach.setDomain(professor); teach.setRange(module); ObjectProperty taughtBy = model.createObjectProperty(uriBase+"#taughtBy"); taughtBy.setDomain(module); taughtBy.setRange(professor); ObjectProperty enrolledIn = model.createObjectProperty(uriBase+"#enrolledIn"); enrolledIn.setDomain(student); enrolledIn.setRange(diploma); // ... ... 30/03/2010 37
  • 38. Creating a New Ontology Reading an Existing Ontology Classes Properties Individuales Inverse-of / Functional  set inverse properties // set inverse properties teach.setInverseOf(taughtBy);  set functional properties // set functional properties enrolledIn.setRDFType(OWL.FunctionalProperty); 30/03/2010 38
  • 39. Creating a New Ontology Reading an Existing Ontology Classes Properties Individuales Restrictions usually, null usually, a class SomeValuesFromRestriction svfr = model.createSomeValuesFromRestriction(uri, property, resource); AllValuesFromRestriction avfr = model.createAllValuesFromRestriction(uri, property, resource); HasValueRestriction hvr = model.createHasValueRestriction(uri, property, rdfNode); CardinalityRestriction cr = model.createCardinalityRestriction(uri, property, int); MinCardinalityRestriction min_cr = model.createMinCardinalityRestriction(uri, property, int); MaxCardinalityRestriction max_cr = model.createMaxCardinalityRestriction(uri, property, int); 30/03/2010 39
  • 40. Creating a New Ontology Reading an Existing Ontology Classes Properties Individuales Individuales  create an individual Individual indv = ontClass.createIndividual(uri); or Individual indv = model.createIndividual(uri, ontClass);  set a property value of an individual indv.setPropertyValue(property, rdfNode); 30/03/2010 40
  • 41. Write Ontology Model  write the model to standard output // write out the model model.write(System.out,"RDF/XML-ABBREV");  save the model to a string StringWriter sw = new StringWriter(); model.write(sw, "RDF/XML-ABBREV"); String owlCode = sw.toString(); 30/03/2010 41
  • 42. Save the Model to a File File file = new File(filePath); try{ FileWriter fw = new FileWriter(file); fw.write(owlCode); fw.close(); } catch(FileNotFoundException fnfe){ fnfe.printStackTrace(); } catch(IOException ioe){ ioe.printStackTrace(); } 30/03/2010 42
  • 43. References  Jena Ontology API   http://jena.sourceforge.net/ontology/index.html RDFS and OWL Reasoning Capabilities:  http://www-ksl.stanford.edu/software/jtp/doc/owl-reasoning.html 30/03/2010 43