Documente Academic
Documente Profesional
Documente Cultură
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 1 / 37
Motivation
From Ideas to Ontologies
Get Started
Motivation
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 2 / 37
Motivation
From Ideas to Ontologies
Get Started
Scenario
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 3 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
What is needed.
Java 8.
Java Editor.
OWL API 5.1.4.
Basic knowledge of Software Project Management and
Comprehension (SPMCF) system (Maven) and of a Distributed
Version Controm (DVC) system (GIT) is HIGHLY encouraged.
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 4 / 37
Motivation
From Ideas to Ontologies
Get Started
Maven POM
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 5 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 6 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 7 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 8 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Load an OWLOntology.
From File:
OWLOntology ontology;
ontology=manager.loadOntologyFromOntologyDocument(
new File(''ontology.owl''));
Remember to manage the exceptions
FileNotFoundException and
OWLOntologyCreationException.
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 9 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Load an OWLOntology.
From Web:
String iri=
''http://www.w3.org/2009/08/ontology.owl'';
IRI docIRI = IRI.create(iri);
OWLOntology ontology =
manager.loadOntologyFromOntologyDocument(docIRI);
Remember to manage the exception
OWLOntologyCreationException.
JAVA OWL-API
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 11 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 12 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 13 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 14 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 15 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 16 / 37
Motivation
From Ideas to Ontologies
Get Started
Java Labdas
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 17 / 37
Motivation
From Ideas to Ontologies
Get Started
Java Labdas
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 18 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 19 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Creating entities
Creating Classes
OWLClass person = df.getOWLClass(IOR+ ''#Person'');
OWLDeclarationAxiom da = df.getOWLDeclarationAxiom(
person);
ChangeApplied ca=o.add(da);
or
manager.addAxiom(ontology, da);
ChangeApplied is used to check the change.
Getting axioms and logical axioms:
ontology.axioms();
ontology.logicalAxioms();
manager.remove(axiom) removes the axiom.
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 20 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Creating entities
Creating Properties
OWLObjectProperty r = df.getOWLObjectProperty(IOR +
''#R'');
OWLDataProperty p= df.getOWLDataProperty(IOR+ ''#P'');
Creating Individuals
OWLIndividual i= df.getOWLNamedIndividual(IOR+ ''#I '');
o.add(df.getOWLDeclarationAxiom( (OWLEntity) i));
Class assertions
df.getOWLClassAssertionAxiom(classexpr, ind);
Creating Annotations
OWLAnnotation c= df.getOWLAnnotation(
df.getRDFSComment(), df.getOWLLiteral(''c'', ''en ''));
OWLAxiom a = df.getOWLAnnotationAssertionAxiom(
p.getIRI(), c);
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 21 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Creating subclasses
OWLSubClassOfAxiom sca=df.getOWLSubClassOfAxiom(sub,
sup);
Creating subproperty
OWLSubObjectPropertyOfAxiom
sop=df.getOWLSubObjectPropertyOfAxiom(sub, sup);
Domain restriction
df.getOWLObjectPropertyDomainAxiom(prop, class);
Data range restriction
df.getOWLDataPropertyRangeAxiom(p,
df.getStringOWLDatatype());
OWLDataRange rg= df.getOWLDataOneOf(
df.getOWLLiteral(''a''), df.getOWLLiteral(''b''));
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 22 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Restrictions
OWLSubClassOfAxiom ax = df.getOWLSubClassOfAxiom(
df.getOWLObjectSomeValuesFrom(R, A),
df.getOWLObjectSomeValuesFrom(S, B));
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 23 / 37
Motivation
From Ideas to Ontologies
Get Started
JAVA OWL-API
Exploring ontology
o.axioms()
Several options admitted.
o.axioms(AxiomtType T).
o.getLogicalAxioms().
Only logical axioms.
Axioms managing, more control
AddAxiom ac = new AddAxiom(o, axiom);
ac.isAxiomChange, isAddAxiom ...
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 24 / 37
Motivation
From Ideas to Ontologies
Get Started
Hermit Reasoner.
Configuration config= new Configuration();
Reasoner reasoner= new Reasoner(config, ontology);
reasoner.classifyClasses();
reasoner.classifyDataProperties();
reasoner.classifyObjectProperties();
System.out.println(reasoner.isConsistent());
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 25 / 37
Motivation
From Ideas to Ontologies
Get Started
Pellet Reasoner can be used with the last version of OWL API
via an open-source fork of the project called ''openllet-pellint''
OpenlletReasoner reasoner = OpenlletReasonerFac-
tory.getInstance().createReasoner(ontology);
System.out.println(reasonerP.isConsistent());
reasoner.getKB().realize();
reasoner.getKB().printClassTree();
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 26 / 37
Motivation
From Ideas to Ontologies
Get Started
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 27 / 37
Motivation
From Ideas to Ontologies
Get Started
Hermit Reasoner:
Configuration configuration = new Configuration();
...
ReasonerFactory rf = new ReasonerFactory();
OWLReasoner reasoner = rf.createReasoner(ontology,
configuration);
List <InferredAxiomGenerator <? extends OWLAxiom>>
generators = new ArrayList <>();
generators.add...
List <InferredIndividualAxiomGenerator <? extends
OWLIndividualAxiom >>individualAxioms =
new ArrayList <>();
generators.addAll(individualAxioms);
InferredOntologyGenerator iog = ...
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 28 / 37
Motivation
From Ideas to Ontologies
Get Started
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 29 / 37
Motivation
From Ideas to Ontologies
Get Started
JENA
JENA
OntModel m = ModelFactory.createOntologyModel(
OntModelSpec.OWL MEM, null);
OntDocumentManager dm = m.getDocumentManager();
FileManager fm=dm.getFileManager();
OntClass students = m.createClass( unictIRI + ''Students '');
ObjectProperty attendsCourse = m.createObjectProperty(
unictIRI + ''attendsCourse'');
DatatypeProperty hasSurname = m.createDatatypeProperty(
unictIRI + ''hasSurname'');
attendsLecture.addRange(courses);
Individual webreasoning= m.createIndividual(unictIRI +
''webreasoning'', courses);
m.add(dfsantamaria, hasSurname,
ResourceFactory.createStringLiteral(''Santamaria''));
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 30 / 37
Motivation
From Ideas to Ontologies
Get Started
JENA
JENA
SomeValuesFromRestriction gst =
m.createSomeValuesFromRestriction(
null, attendsCourse, courses);
OntClass goodStudent= m.createClass(unictIRI +
''goodStudent'');
goodStudents.addSuperClass(gst);
goodStudents.addSuperClass(students);
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 31 / 37
Motivation
From Ideas to Ontologies
Get Started
JENA
SPARQL Query
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create
(query, m);
ResultSet rs = qexec.execSelect() ;
while(rs.hasNext()){
QuerySolution qs = rs.nextSolution();
...
RDFNode nodeRes = qs.get(variableName);
...
String s=nodeRes.asLiteral().toString();
}
Resource z = (Resource) qs.getResource(variableName);
Resource z = nodeRes.asResource();
SPARQL Update
UpdateAction.parseExecute(updateQ, model);
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 32 / 37
Motivation
From Ideas to Ontologies
Get Started
SPARQL Query
Evaluating SPARQL queries in OWL-API is not
straightforward.
The SPARQL is very firmly rooted in RDF (as Jena API).
OWL-API is OWL-centric.
OWL can be serialized using RDF since OWL builds on top of
the (revised) RDF specifications, so it’s feasible to create a
wrapper layer over an RDF graph.
At the time of writing, Jena supports only OWL 1.1.
At the time of writing, there is no SPARQL implementation
over OWL-API.
The structural (OWL) and graph (Jena) model do not coexist.
How vs What.
From the structural model (under the implementation of
OWL-API) to the graph model (under the implementation of
Jena) and vice-versa can be a solution.
Shortly, it is matter of implementation, not theory.
ONT-API is an effort in this sense.
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 33 / 37
Motivation
From Ideas to Ontologies
Get Started
ONTAPI
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 34 / 37
Motivation
From Ideas to Ontologies
Get Started
ONTAPI
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 35 / 37
Motivation
From Ideas to Ontologies
Get Started
ONTAPI
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 36 / 37
Motivation
From Ideas to Ontologies
Get Started
ONTAPI
Daniele Francesco Santamaria - Course of Web Reasoning Department of Maths and CS - Univ. of Catania 37 / 37