SlideShare a Scribd company logo
Programming
THE SEMANTIC WEB
Build an application upon Semantic Web
models. Brief overview of Apache Jena and
OWL-API.
Recap: Tools
• Editors (http://semanticweb.org/wiki/Editors)
– Most common editor: Protégé 5
– Other tools: TopBraid Composer ($), NeOn toolkit
– Special purpose apps, esp. for light-weight ontologies
(e.g., FOAF editors)
• Reasoners
(http://semanticweb.org/wiki/Reasoners)
– OWL DL: Pellet 2.0*, HermiT, FaCT++, RacerPro ($)
– OWL EL: CEL, SHER, snorocket ($), ELLY
– OWL RL: OWLIM, Jena, Oracle OWL Reasoner ($)
– OWL QL: Owlgres, QuOnto, Quill
* The next-gen reasoner (version 3) is part of Stardog, a closed source RDF database
22/02/2017 Programming the Semantic Web 2
Recap: How to create an ontology
1. Determine the scope
2. Consider reuse
3. Enumerate terms
4. Define classes
5. Define properties
6. Define constraints
7. Create instances
22/02/2017 Programming the Semantic Web 3
Determine
the scope
Consider
reuse
Enumerate
terms
Define
classes
Define
properties
Define
constraints
Create
instances
Now what?
• You created a OWL ontology…
• … or you want to query some SPARQL
endpoints…
• How to do this programmatically?
– e.g., from a software application
• Good news: frameworks exist!
– They are written in Java…
– Apache Jena (RDF/SPARQL/…)
– OWL API (OWL2)
22/02/2017 Programming the Semantic Web 4
Apache Jena
• Free and open source Java
framework
– for building Semantic Web
and Linked Data
applications
– https://jena.apache.org
• It is composed by several
APIs
– as well as command line tools
22/02/2017 Programming the Semantic Web 5
Apache Jena
• Tutorials available
– https://jena.apache.org/tutorials/index.html
– sample code:
https://github.com/apache/jena/tree/master/jena-
core/src-examples/jena/examples/rdf
• It has a limited support to OWL 1.1
– no OWL2
– basically, do not use Jena for ontologies!
22/02/2017 Programming the Semantic Web 6
Creating a RDF…
String personURI = "http://somewhere/JohnSmith";
String givenName = "John";
String familyName = "Smith";
String fullName = givenName + " " + familyName;
// create an empty model
Model model = ModelFactory.createDefaultModel();
// create the resource and add the properties cascading style
Resource johnSmith = model.createResource(personURI)
.addProperty(VCARD.FN, fullName)
.addProperty(VCARD.N,
model.createResource()
.addProperty(VCARD.Given, givenName)
.addProperty(VCARD.Family, familyName));
22/02/2017 Programming the Semantic Web 7
Writing RDF…
• Write the previous model on a OutputStream
// now write the model in XML form to a file
model.write(System.out);
• You can also specify the format
// you can also specify the format, e.g.,
// model.write(System.out, "TURTLE");
22/02/2017 Programming the Semantic Web 8
Reading RDF…
• Read from a InputStream
String inputFileName = "vc-db-1.rdf";
InputStream in =
FileManager.get().open(inputFileName);
// read the RDF/XML file
model.read(in, "");
22/02/2017 Programming the Semantic Web 9
The base URI to be used when converting
relative URI's to absolute URI's
SPARQL
• Jena supports SPARQL querying through the ARQ
engine
– Standard SPARQL
– Free text search via Lucene
– Access and extension of the SPARQL algebra
– Property functions for custom processing of semantic
relationships
– Aggregation, GROUP BY and assignment as SPARQL
extensions
– Client-support for remote access to any SPARQL endpoint
– …
22/02/2017 Programming the Semantic Web 10
SPARQL with ARQ
[...]
// Create a new query
String queryString =
"PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
"SELECT ?url " +
"WHERE {" +
" ?contributor foaf:name "Luigi De Russis" . " +
" ?contributor foaf:weblog ?url . " +
" }";
Query query = QueryFactory.create(queryString);
// Execute the query and obtain results
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
// Output query results
ResultSetFormatter.out(System.out, results, query);
// Free up resources used running the query
qe.close();
22/02/2017 Programming the Semantic Web 11
OWL API
• A Java API and reference implementation
– for creating, manipulating and serializing OWL 2
Ontologies
– http://owlcs.github.io/owlapi
• Free and open source
• Created and maintained by the University of
Manchester
– http://owl.cs.manchester.ac.uk
22/02/2017 Programming the Semantic Web 12
OWL API
• It includes the following components
– API for OWL 2 and an efficient in-memory reference
implementation
– RDF/XML parser and writer
– OWL/XML parser and writer
– OWL Functional Syntax parser and writer
– Turtle parser and writer
– SWRL
– Reasoner interfaces
• towards, e.g., FaCT++, HermiT, Pellet, and Racer
22/02/2017 Programming the Semantic Web 13
OWL API
• Documentation and Javadocs
– https://github.com/owlcs/owlapi/wiki
– http://owlcs.github.io/owlapi/apidocs_4/index.html
– scarce and not updated, sometimes
• Versions
– 5.0, cutting edge, Java 8 only
– 4.0, stable, Java 7+
• currently used by Protégé
• several examples are available, right now
22/02/2017 Programming the Semantic Web 14
OWL API Fundamentals
• OWLOntology
– an interface
– modelling a set of logical and nonlogical OWLAxioms,
with a name (an IRI) and convenience methods to
retrieve such axioms
• OWLEntity
– anything that can be identified with an IRI, i.e., class
names, data and object properties, named
individuals, …
22/02/2017 Programming the Semantic Web 15
OWL API Fundamentals
• OWLAxiom
– the basic unity
– TBox axioms describe relations between classes and
class expressions (equivalence, subsumption,
disjointness)
– ABox axioms (assertions) describe relations between
individuals and between individuals and classes/class
expressions
– RBox axioms describe relations between properties
22/02/2017 Programming the Semantic Web 16
Load (or create) an ontology…
• Ontology creation
OWLOntologyManager m =
OWLManager.createOWLOntologyManager();
OWLOntology o = m.createOntology(example_iri);
• Ontology loading
OWLOntologyManager m =
OWLManager.createOWLOntologyManager();
OWLOntology o =
m.loadOntologyFromOntologyDocument(ont_iri);
22/02/2017 Programming the Semantic Web 17
a File or a IRI
Save an ontology…
• Save in OWL/XML format
m.saveOntology(ontology, new
OWLXMLOntologyFormat(), file);
• Save in RDF/XML format
m.saveOntology(ontology, file);
22/02/2017 Programming the Semantic Web 18
Learning by Example
• We are going to use the University ontology we
developed few weeks ago
• We would like to
– load the ontology
– compute logical inferences
– ask for
• university individuals
• which degrees each university offers
• which courses each degree offers
• who is enrolled in those courses
22/02/2017 Programming the Semantic Web 19
We are going to use…
• Eclipse (neon)
– https://www.eclipse.org/downloads/
• OWL API 4.2.8
• HermiT reasoner 1.3.8.413
– download from
https://github.com/owlcs/owlapi/wiki/Reasoners,-OWL-
API-Support,-papers-about-the-OWL-API
• Gradle 3.4
– for handling the OWL API/HermiT set up and
dependencies
– https://gradle.org/
– Eclipse supports Gradle through the Buildship plugin
22/02/2017 Programming the Semantic Web 20
Questions?
01RRDIU SEMANTIC WEB
Luigi De Russis
luigi.derussis@polito.it
License
• This work is licensed under the Creative Commons “Attribution-
NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License.
• You are free:
– to Share - to copy, distribute and transmit the work
– to Remix - to adapt the work
• Under the following conditions:
– Attribution - You must attribute the work in the manner specified by the
author or licensor (but not in any way that suggests that they endorse you
or your use of the work).
– Noncommercial - You may not use this work for commercial purposes.
– Share Alike - If you alter, transform, or build upon this work, you may
distribute the resulting work only under the same or similar license to this
one.
• To view a copy of this license, visit
http://creativecommons.org/license/by-nc-sa/3.0/
22/02/2017 Programming the Semantic Web 22

More Related Content

What's hot (20)

PPTX
ASP.NET Core MVC + Web API with Overview
Shahed Chowdhuri
 
PDF
react redux.pdf
Knoldus Inc.
 
PPTX
Introduction à spring boot
Antoine Rey
 
PPTX
Migrating to Java 11
Arto Santala
 
PDF
Node JS Crash Course
Haim Michael
 
PPTX
Model Your Application Domain, Not Your JSON Structures
Markus Lanthaler
 
PDF
JPA and Hibernate
elliando dias
 
PDF
Modern UI Development With Node.js
Ryan Anklam
 
PPTX
React / Redux Architectures
Vinícius Ribeiro
 
PDF
Introduction to Java 11
Knoldus Inc.
 
PPTX
React js
Oswald Campesato
 
PDF
Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...
Edureka!
 
PPTX
Basic Concept of Node.js & NPM
Bhargav Anadkat
 
ODP
Xke spring boot
sourabh aggarwal
 
PPTX
Node.js Express
Eyal Vardi
 
PPTX
What Is Express JS?
Simplilearn
 
PDF
Spring Data JPA
Knoldus Inc.
 
PPTX
RESTful Architecture
Kabir Baidya
 
PPTX
Reactjs
Neha Sharma
 
ASP.NET Core MVC + Web API with Overview
Shahed Chowdhuri
 
react redux.pdf
Knoldus Inc.
 
Introduction à spring boot
Antoine Rey
 
Migrating to Java 11
Arto Santala
 
Node JS Crash Course
Haim Michael
 
Model Your Application Domain, Not Your JSON Structures
Markus Lanthaler
 
JPA and Hibernate
elliando dias
 
Modern UI Development With Node.js
Ryan Anklam
 
React / Redux Architectures
Vinícius Ribeiro
 
Introduction to Java 11
Knoldus Inc.
 
Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...
Edureka!
 
Basic Concept of Node.js & NPM
Bhargav Anadkat
 
Xke spring boot
sourabh aggarwal
 
Node.js Express
Eyal Vardi
 
What Is Express JS?
Simplilearn
 
Spring Data JPA
Knoldus Inc.
 
RESTful Architecture
Kabir Baidya
 
Reactjs
Neha Sharma
 

Viewers also liked (6)

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

Similar to Programming the Semantic Web (20)

PDF
Staab programming thesemanticweb
Aneta Tu
 
PDF
ESWC SS 2013 - Tuesday Keynote Steffen Staab: Programming the Semantic Web
eswcsummerschool
 
PPTX
Programming the Semantic Web
Steffen Staab
 
PDF
Swt
Ngoc Anh
 
ODP
Building a semantic website
CJ Jenkins
 
PPT
Semantic Web 2.0
hchen1
 
PPT
ontology.ppt
Prerak10
 
PPT
Future of Web 2.0 & The Semantic Web
is20090
 
PPT
Toward The Semantic Deep Web
Samiul Hoque
 
PDF
Overview of the SPARQL-Generate language and latest developments
Maxime Lefrançois
 
PPT
Semantic Web: Technolgies and Applications for Real-World
Amit Sheth
 
PPT
A hands on overview of the semantic web
Marakana Inc.
 
PPT
A review of the state of the art in Machine Learning on the Semantic Web
Simon Price
 
PDF
CS6010 Social Network Analysis Unit II
pkaviya
 
PDF
.Net and Rdf APIs
Recean Denis
 
PPTX
Semantic Web: introduction & overview
Amit Sheth
 
ZIP
XSLT+SPARQL: Scripting the Semantic Web with SPARQL embedded into XSLT styles...
Diego Berrueta
 
PPTX
RDFa Semantic Web
Rob Paok
 
PDF
Semantic - Based Querying Using Ontology in Relational Database of Library Ma...
dannyijwest
 
PPTX
Semantic web xml-rdf-dom parser
Serdar Sönmez
 
Staab programming thesemanticweb
Aneta Tu
 
ESWC SS 2013 - Tuesday Keynote Steffen Staab: Programming the Semantic Web
eswcsummerschool
 
Programming the Semantic Web
Steffen Staab
 
Building a semantic website
CJ Jenkins
 
Semantic Web 2.0
hchen1
 
ontology.ppt
Prerak10
 
Future of Web 2.0 & The Semantic Web
is20090
 
Toward The Semantic Deep Web
Samiul Hoque
 
Overview of the SPARQL-Generate language and latest developments
Maxime Lefrançois
 
Semantic Web: Technolgies and Applications for Real-World
Amit Sheth
 
A hands on overview of the semantic web
Marakana Inc.
 
A review of the state of the art in Machine Learning on the Semantic Web
Simon Price
 
CS6010 Social Network Analysis Unit II
pkaviya
 
.Net and Rdf APIs
Recean Denis
 
Semantic Web: introduction & overview
Amit Sheth
 
XSLT+SPARQL: Scripting the Semantic Web with SPARQL embedded into XSLT styles...
Diego Berrueta
 
RDFa Semantic Web
Rob Paok
 
Semantic - Based Querying Using Ontology in Relational Database of Library Ma...
dannyijwest
 
Semantic web xml-rdf-dom parser
Serdar Sönmez
 
Ad

More from Luigi De Russis (20)

PDF
Assessing Virtual Assistant Capabilities with Italian Dysarthric Speech
Luigi De Russis
 
PDF
Semantic Web: an Introduction
Luigi De Russis
 
PDF
AmI 2017 - Python intermediate
Luigi De Russis
 
PDF
AmI 2017 - Python basics
Luigi De Russis
 
PDF
AngularJS: an introduction
Luigi De Russis
 
PDF
AmI 2016 - Python basics
Luigi De Russis
 
PDF
Ambient Intelligence: An Overview
Luigi De Russis
 
PDF
Version Control with Git
Luigi De Russis
 
PDF
LAM 2015 - Social Networks Technologies
Luigi De Russis
 
PDF
AmI 2015 - Python basics
Luigi De Russis
 
PDF
PowerOnt: an ontology-based approach for power consumption estimation in Smar...
Luigi De Russis
 
PDF
Interacting with Smart Environments - Ph.D. Thesis Presentation
Luigi De Russis
 
PDF
Semantic Web: an introduction
Luigi De Russis
 
PDF
Living in Smart Environments - 3rd year PhD Report
Luigi De Russis
 
PDF
Semantic Web: an introduction
Luigi De Russis
 
PDF
Social Network Technologies
Luigi De Russis
 
PDF
Clean Code
Luigi De Russis
 
PDF
Living in Smart Environments - 2nd year PhD Report
Luigi De Russis
 
PDF
Introduction to OpenCV
Luigi De Russis
 
PDF
Installing OpenCV 2.4.x with Qt
Luigi De Russis
 
Assessing Virtual Assistant Capabilities with Italian Dysarthric Speech
Luigi De Russis
 
Semantic Web: an Introduction
Luigi De Russis
 
AmI 2017 - Python intermediate
Luigi De Russis
 
AmI 2017 - Python basics
Luigi De Russis
 
AngularJS: an introduction
Luigi De Russis
 
AmI 2016 - Python basics
Luigi De Russis
 
Ambient Intelligence: An Overview
Luigi De Russis
 
Version Control with Git
Luigi De Russis
 
LAM 2015 - Social Networks Technologies
Luigi De Russis
 
AmI 2015 - Python basics
Luigi De Russis
 
PowerOnt: an ontology-based approach for power consumption estimation in Smar...
Luigi De Russis
 
Interacting with Smart Environments - Ph.D. Thesis Presentation
Luigi De Russis
 
Semantic Web: an introduction
Luigi De Russis
 
Living in Smart Environments - 3rd year PhD Report
Luigi De Russis
 
Semantic Web: an introduction
Luigi De Russis
 
Social Network Technologies
Luigi De Russis
 
Clean Code
Luigi De Russis
 
Living in Smart Environments - 2nd year PhD Report
Luigi De Russis
 
Introduction to OpenCV
Luigi De Russis
 
Installing OpenCV 2.4.x with Qt
Luigi De Russis
 

Recently uploaded (20)

PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Dimensions of Societal Planning in Commonism
StefanMz
 
community health nursing question paper 2.pdf
Prince kumar
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 

Programming the Semantic Web

  • 1. Programming THE SEMANTIC WEB Build an application upon Semantic Web models. Brief overview of Apache Jena and OWL-API.
  • 2. Recap: Tools • Editors (http://semanticweb.org/wiki/Editors) – Most common editor: Protégé 5 – Other tools: TopBraid Composer ($), NeOn toolkit – Special purpose apps, esp. for light-weight ontologies (e.g., FOAF editors) • Reasoners (http://semanticweb.org/wiki/Reasoners) – OWL DL: Pellet 2.0*, HermiT, FaCT++, RacerPro ($) – OWL EL: CEL, SHER, snorocket ($), ELLY – OWL RL: OWLIM, Jena, Oracle OWL Reasoner ($) – OWL QL: Owlgres, QuOnto, Quill * The next-gen reasoner (version 3) is part of Stardog, a closed source RDF database 22/02/2017 Programming the Semantic Web 2
  • 3. Recap: How to create an ontology 1. Determine the scope 2. Consider reuse 3. Enumerate terms 4. Define classes 5. Define properties 6. Define constraints 7. Create instances 22/02/2017 Programming the Semantic Web 3 Determine the scope Consider reuse Enumerate terms Define classes Define properties Define constraints Create instances
  • 4. Now what? • You created a OWL ontology… • … or you want to query some SPARQL endpoints… • How to do this programmatically? – e.g., from a software application • Good news: frameworks exist! – They are written in Java… – Apache Jena (RDF/SPARQL/…) – OWL API (OWL2) 22/02/2017 Programming the Semantic Web 4
  • 5. Apache Jena • Free and open source Java framework – for building Semantic Web and Linked Data applications – https://jena.apache.org • It is composed by several APIs – as well as command line tools 22/02/2017 Programming the Semantic Web 5
  • 6. Apache Jena • Tutorials available – https://jena.apache.org/tutorials/index.html – sample code: https://github.com/apache/jena/tree/master/jena- core/src-examples/jena/examples/rdf • It has a limited support to OWL 1.1 – no OWL2 – basically, do not use Jena for ontologies! 22/02/2017 Programming the Semantic Web 6
  • 7. Creating a RDF… String personURI = "http://somewhere/JohnSmith"; String givenName = "John"; String familyName = "Smith"; String fullName = givenName + " " + familyName; // create an empty model Model model = ModelFactory.createDefaultModel(); // create the resource and add the properties cascading style Resource johnSmith = model.createResource(personURI) .addProperty(VCARD.FN, fullName) .addProperty(VCARD.N, model.createResource() .addProperty(VCARD.Given, givenName) .addProperty(VCARD.Family, familyName)); 22/02/2017 Programming the Semantic Web 7
  • 8. Writing RDF… • Write the previous model on a OutputStream // now write the model in XML form to a file model.write(System.out); • You can also specify the format // you can also specify the format, e.g., // model.write(System.out, "TURTLE"); 22/02/2017 Programming the Semantic Web 8
  • 9. Reading RDF… • Read from a InputStream String inputFileName = "vc-db-1.rdf"; InputStream in = FileManager.get().open(inputFileName); // read the RDF/XML file model.read(in, ""); 22/02/2017 Programming the Semantic Web 9 The base URI to be used when converting relative URI's to absolute URI's
  • 10. SPARQL • Jena supports SPARQL querying through the ARQ engine – Standard SPARQL – Free text search via Lucene – Access and extension of the SPARQL algebra – Property functions for custom processing of semantic relationships – Aggregation, GROUP BY and assignment as SPARQL extensions – Client-support for remote access to any SPARQL endpoint – … 22/02/2017 Programming the Semantic Web 10
  • 11. SPARQL with ARQ [...] // Create a new query String queryString = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " + "SELECT ?url " + "WHERE {" + " ?contributor foaf:name "Luigi De Russis" . " + " ?contributor foaf:weblog ?url . " + " }"; Query query = QueryFactory.create(queryString); // Execute the query and obtain results QueryExecution qe = QueryExecutionFactory.create(query, model); ResultSet results = qe.execSelect(); // Output query results ResultSetFormatter.out(System.out, results, query); // Free up resources used running the query qe.close(); 22/02/2017 Programming the Semantic Web 11
  • 12. OWL API • A Java API and reference implementation – for creating, manipulating and serializing OWL 2 Ontologies – http://owlcs.github.io/owlapi • Free and open source • Created and maintained by the University of Manchester – http://owl.cs.manchester.ac.uk 22/02/2017 Programming the Semantic Web 12
  • 13. OWL API • It includes the following components – API for OWL 2 and an efficient in-memory reference implementation – RDF/XML parser and writer – OWL/XML parser and writer – OWL Functional Syntax parser and writer – Turtle parser and writer – SWRL – Reasoner interfaces • towards, e.g., FaCT++, HermiT, Pellet, and Racer 22/02/2017 Programming the Semantic Web 13
  • 14. OWL API • Documentation and Javadocs – https://github.com/owlcs/owlapi/wiki – http://owlcs.github.io/owlapi/apidocs_4/index.html – scarce and not updated, sometimes • Versions – 5.0, cutting edge, Java 8 only – 4.0, stable, Java 7+ • currently used by Protégé • several examples are available, right now 22/02/2017 Programming the Semantic Web 14
  • 15. OWL API Fundamentals • OWLOntology – an interface – modelling a set of logical and nonlogical OWLAxioms, with a name (an IRI) and convenience methods to retrieve such axioms • OWLEntity – anything that can be identified with an IRI, i.e., class names, data and object properties, named individuals, … 22/02/2017 Programming the Semantic Web 15
  • 16. OWL API Fundamentals • OWLAxiom – the basic unity – TBox axioms describe relations between classes and class expressions (equivalence, subsumption, disjointness) – ABox axioms (assertions) describe relations between individuals and between individuals and classes/class expressions – RBox axioms describe relations between properties 22/02/2017 Programming the Semantic Web 16
  • 17. Load (or create) an ontology… • Ontology creation OWLOntologyManager m = OWLManager.createOWLOntologyManager(); OWLOntology o = m.createOntology(example_iri); • Ontology loading OWLOntologyManager m = OWLManager.createOWLOntologyManager(); OWLOntology o = m.loadOntologyFromOntologyDocument(ont_iri); 22/02/2017 Programming the Semantic Web 17 a File or a IRI
  • 18. Save an ontology… • Save in OWL/XML format m.saveOntology(ontology, new OWLXMLOntologyFormat(), file); • Save in RDF/XML format m.saveOntology(ontology, file); 22/02/2017 Programming the Semantic Web 18
  • 19. Learning by Example • We are going to use the University ontology we developed few weeks ago • We would like to – load the ontology – compute logical inferences – ask for • university individuals • which degrees each university offers • which courses each degree offers • who is enrolled in those courses 22/02/2017 Programming the Semantic Web 19
  • 20. We are going to use… • Eclipse (neon) – https://www.eclipse.org/downloads/ • OWL API 4.2.8 • HermiT reasoner 1.3.8.413 – download from https://github.com/owlcs/owlapi/wiki/Reasoners,-OWL- API-Support,-papers-about-the-OWL-API • Gradle 3.4 – for handling the OWL API/HermiT set up and dependencies – https://gradle.org/ – Eclipse supports Gradle through the Buildship plugin 22/02/2017 Programming the Semantic Web 20
  • 22. License • This work is licensed under the Creative Commons “Attribution- NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License. • You are free: – to Share - to copy, distribute and transmit the work – to Remix - to adapt the work • Under the following conditions: – Attribution - You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). – Noncommercial - You may not use this work for commercial purposes. – Share Alike - If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one. • To view a copy of this license, visit http://creativecommons.org/license/by-nc-sa/3.0/ 22/02/2017 Programming the Semantic Web 22