SlideShare una empresa de Scribd logo
1 de 43
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

Más contenido relacionado

La actualidad más candente

Programming the Semantic Web
Programming the Semantic WebProgramming the Semantic Web
Programming the Semantic WebLuigi De Russis
 
Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps Hitesh-Java
 
Introduction to the Semantic Web
Introduction to the Semantic WebIntroduction to the Semantic Web
Introduction to the Semantic WebMarin Dimitrov
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architectureBishal Khanal
 
Introduction to HiveQL
Introduction to HiveQLIntroduction to HiveQL
Introduction to HiveQLkristinferrier
 
SQL on everything, in memory
SQL on everything, in memorySQL on everything, in memory
SQL on everything, in memoryJulian Hyde
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events WebStackAcademy
 
JSON-LD: JSON for Linked Data
JSON-LD: JSON for Linked DataJSON-LD: JSON for Linked Data
JSON-LD: JSON for Linked DataGregg Kellogg
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and ArraysWebStackAcademy
 
LinkML Intro July 2022.pptx PLEASE VIEW THIS ON ZENODO
LinkML Intro July 2022.pptx PLEASE VIEW THIS ON ZENODOLinkML Intro July 2022.pptx PLEASE VIEW THIS ON ZENODO
LinkML Intro July 2022.pptx PLEASE VIEW THIS ON ZENODOChris Mungall
 
javascript objects
javascript objectsjavascript objects
javascript objectsVijay Kalyan
 
Cost-based query optimization in Apache Hive
Cost-based query optimization in Apache HiveCost-based query optimization in Apache Hive
Cost-based query optimization in Apache HiveJulian Hyde
 

La actualidad más candente (20)

Programming the Semantic Web
Programming the Semantic WebProgramming the Semantic Web
Programming the Semantic Web
 
Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps
 
jQuery
jQueryjQuery
jQuery
 
MongoDB
MongoDBMongoDB
MongoDB
 
Introduction to the Semantic Web
Introduction to the Semantic WebIntroduction to the Semantic Web
Introduction to the Semantic Web
 
Html
HtmlHtml
Html
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
 
Introduction to HiveQL
Introduction to HiveQLIntroduction to HiveQL
Introduction to HiveQL
 
Odata
OdataOdata
Odata
 
SQL
SQL SQL
SQL
 
SQL on everything, in memory
SQL on everything, in memorySQL on everything, in memory
SQL on everything, in memory
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
JSON-LD: JSON for Linked Data
JSON-LD: JSON for Linked DataJSON-LD: JSON for Linked Data
JSON-LD: JSON for Linked Data
 
SPARQL Cheat Sheet
SPARQL Cheat SheetSPARQL Cheat Sheet
SPARQL Cheat Sheet
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
LinkML Intro July 2022.pptx PLEASE VIEW THIS ON ZENODO
LinkML Intro July 2022.pptx PLEASE VIEW THIS ON ZENODOLinkML Intro July 2022.pptx PLEASE VIEW THIS ON ZENODO
LinkML Intro July 2022.pptx PLEASE VIEW THIS ON ZENODO
 
Apache Spark 101
Apache Spark 101Apache Spark 101
Apache Spark 101
 
Javascript
JavascriptJavascript
Javascript
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
Cost-based query optimization in Apache Hive
Cost-based query optimization in Apache HiveCost-based query optimization in Apache Hive
Cost-based query optimization in Apache Hive
 

Destacado

PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel HordesPyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordeskgrandis
 
Face Recognition with OpenCV and scikit-learn
Face Recognition with OpenCV and scikit-learnFace Recognition with OpenCV and scikit-learn
Face Recognition with OpenCV and scikit-learnShiqiao Du
 
Face Recognition using OpenCV
Face Recognition using OpenCVFace Recognition using OpenCV
Face Recognition using OpenCVVasile Chelban
 
Semantic Web - Ontology 101
Semantic Web - Ontology 101Semantic Web - Ontology 101
Semantic Web - Ontology 101Luigi De Russis
 
Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Luigi De Russis
 
Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)Luigi De Russis
 

Destacado (6)

PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel HordesPyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
 
Face Recognition with OpenCV and scikit-learn
Face Recognition with OpenCV and scikit-learnFace Recognition with OpenCV and scikit-learn
Face Recognition with OpenCV and scikit-learn
 
Face Recognition using OpenCV
Face Recognition using OpenCVFace Recognition using OpenCV
Face Recognition using OpenCV
 
Semantic Web - Ontology 101
Semantic Web - Ontology 101Semantic Web - Ontology 101
Semantic Web - Ontology 101
 
Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)
 
Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)
 

Similar a Java and OWL

Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Javabackdoor
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#foreverredpb
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Getachew Ganfur
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming CourseDennis Chang
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer ProgrammingInocentshuja Ahmad
 
Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Uzair Salman
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)farhan amjad
 
Inner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVAInner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVATech_MX
 
PPT OF JAWA (1).pdf
PPT OF JAWA (1).pdfPPT OF JAWA (1).pdf
PPT OF JAWA (1).pdfNitish Banga
 
Integrating a Domain Ontology Development Environment and an Ontology Search ...
Integrating a Domain Ontology Development Environment and an Ontology Search ...Integrating a Domain Ontology Development Environment and an Ontology Search ...
Integrating a Domain Ontology Development Environment and an Ontology Search ...Takeshi Morita
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingAmit Soni (CTFL)
 
Inheritance in Java.pdf
Inheritance in Java.pdfInheritance in Java.pdf
Inheritance in Java.pdfkumari36
 

Similar a Java and OWL (20)

Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
javaopps concepts
javaopps conceptsjavaopps concepts
javaopps concepts
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Design patterns(red)
Design patterns(red)Design patterns(red)
Design patterns(red)
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Java basics
Java basicsJava basics
Java basics
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
 
Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Inner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVAInner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVA
 
C# program structure
C# program structureC# program structure
C# program structure
 
PPT OF JAWA (1).pdf
PPT OF JAWA (1).pdfPPT OF JAWA (1).pdf
PPT OF JAWA (1).pdf
 
Python - object oriented
Python - object orientedPython - object oriented
Python - object oriented
 
Integrating a Domain Ontology Development Environment and an Ontology Search ...
Integrating a Domain Ontology Development Environment and an Ontology Search ...Integrating a Domain Ontology Development Environment and an Ontology Search ...
Integrating a Domain Ontology Development Environment and an Ontology Search ...
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Inheritance in Java.pdf
Inheritance in Java.pdfInheritance in Java.pdf
Inheritance in Java.pdf
 

Más de Raji Ghawi

Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming TechniquesRaji Ghawi
 
Java and XML Schema
Java and XML SchemaJava and XML Schema
Java and XML SchemaRaji Ghawi
 
Ontology-based Cooperation of Information Systems
Ontology-based Cooperation of Information SystemsOntology-based Cooperation of Information Systems
Ontology-based Cooperation of Information SystemsRaji Ghawi
 
OWSCIS: Ontology and Web Service based Cooperation of Information Sources
OWSCIS: Ontology and Web Service based Cooperation of Information SourcesOWSCIS: Ontology and Web Service based Cooperation of Information Sources
OWSCIS: Ontology and Web Service based Cooperation of Information SourcesRaji Ghawi
 
Coopération des Systèmes d'Informations basée sur les Ontologies
Coopération des Systèmes d'Informations basée sur les OntologiesCoopération des Systèmes d'Informations basée sur les Ontologies
Coopération des Systèmes d'Informations basée sur les OntologiesRaji Ghawi
 
Building Ontologies from Multiple Information Sources
Building Ontologies from Multiple Information SourcesBuilding Ontologies from Multiple Information Sources
Building Ontologies from Multiple Information SourcesRaji Ghawi
 
Database-to-Ontology Mapping Generation for Semantic Interoperability
Database-to-Ontology Mapping Generation for Semantic InteroperabilityDatabase-to-Ontology Mapping Generation for Semantic Interoperability
Database-to-Ontology Mapping Generation for Semantic InteroperabilityRaji Ghawi
 

Más de Raji Ghawi (11)

Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
 
Java and XML Schema
Java and XML SchemaJava and XML Schema
Java and XML Schema
 
Java and XML
Java and XMLJava and XML
Java and XML
 
SPARQL
SPARQLSPARQL
SPARQL
 
XQuery
XQueryXQuery
XQuery
 
XPath
XPathXPath
XPath
 
Ontology-based Cooperation of Information Systems
Ontology-based Cooperation of Information SystemsOntology-based Cooperation of Information Systems
Ontology-based Cooperation of Information Systems
 
OWSCIS: Ontology and Web Service based Cooperation of Information Sources
OWSCIS: Ontology and Web Service based Cooperation of Information SourcesOWSCIS: Ontology and Web Service based Cooperation of Information Sources
OWSCIS: Ontology and Web Service based Cooperation of Information Sources
 
Coopération des Systèmes d'Informations basée sur les Ontologies
Coopération des Systèmes d'Informations basée sur les OntologiesCoopération des Systèmes d'Informations basée sur les Ontologies
Coopération des Systèmes d'Informations basée sur les Ontologies
 
Building Ontologies from Multiple Information Sources
Building Ontologies from Multiple Information SourcesBuilding Ontologies from Multiple Information Sources
Building Ontologies from Multiple Information Sources
 
Database-to-Ontology Mapping Generation for Semantic Interoperability
Database-to-Ontology Mapping Generation for Semantic InteroperabilityDatabase-to-Ontology Mapping Generation for Semantic Interoperability
Database-to-Ontology Mapping Generation for Semantic Interoperability
 

Último

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Último (20)

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

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