The Jena RDF Framework Konstantinos Tzonas.

Slides:



Advertisements
Similar presentations
CH-4 Ontologies, Querying and Data Integration. Introduction to RDF(S) RDF stands for Resource Description Framework. RDF is a standard for describing.
Advertisements

Chronos: A Tool for Handling Temporal Ontologies in Protégé
An Introduction to RDF(S) and a Quick Tour of OWL
1 UIM with DAML-S Service Description Team Members: Jean-Yves Ouellet Kevin Lam Yun Xu.
ΑΝΑΠΑΡΑΣΤΑΣΗ ΓΝΩΣΗΣ ΣΤΟΝ ΠΑΓΚΟΣΜΙΟ ΙΣΤΟ OWL
Master Informatique 1 Semantic Technologies Part 4Jena Werner Nutt.
JENA –A SEMANTIC WEB TOOL by Ranjani Sankaran & krishna Priyanka Chebrolu.
Jena Sparql 4/11/2017.
Progress Update Semantic Web, Ontology Integration, and Web Query Seminar Department of Computing David George.
Of 27 lecture 7: owl - introduction. of 27 ece 627, winter ‘132 OWL a glimpse OWL – Web Ontology Language describes classes, properties and relations.
Semantic Web Tools Vagan Terziyan Department of Mathematical Information Technology, University of Jyvaskyla ;
CSCI 572 Project Presentation Mohsen Taheriyan Semantic Search on FOAF profiles.
1 An Introduction To The Semantic Web. 2 Information Access on the Web Find an mp3 of a song that was on the Billboard Top Ten that features a cowbell.
Chapter 8: Web Ontology Language (OWL) Service-Oriented Computing: Semantics, Processes, Agents – Munindar P. Singh and Michael N. Huhns, Wiley, 2005.
Semantic Representation of Temporal Metadata in a Virtual Observatory Han Wang 1 Eric Rozell 1
Using Java in Linked Data Applications Fuming Shih Oct 12.
Triple Stores.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Managing Large RDF Graphs (Infinite Graph) Vaibhav Khadilkar Department of Computer Science, The University of Texas at Dallas FEARLESS engineering.
ONTOLOGY SUPPORT For the Semantic Web. THE BIG PICTURE  Diagram, page 9  html5  xml can be used as a syntactic model for RDF and DAML/OIL  RDF, RDF.
1 Ontology Query and Reasoning Payam Barnaghi Institute for Communication Systems (ICS) Faculty of Engineering and Physical Sciences University of Surrey.
Okech Odhiambo Faculty of Information Technology Strathmore University
Protege OWL Plugin Short Tutorial. OWL Usage The world wide web is a natural application area of ontologies, because ontologies could be used to describe.
Biomedical Informatics Introduction to Ontology Liqin Wang, MS SWE Workshop 2011 Aug 10 th, 2011.
Database Support for Semantic Web Masoud Taghinezhad Omran Sharif University of Technology Computer Engineering Department Fall.
Building an Ontology of Semantic Web Techniques Utilizing RDF Schema and OWL 2.0 in Protégé 4.0 Presented by: Naveed Javed Nimat Umar Syed.
The Jena RDF Framework Konstantinos Tzonas. Contents What is Jena Capabilities of Jena Basic notions RDF concepts in Jena Persistence Ontology management.
OWL 2 in use. OWL 2 OWL 2 is a knowledge representation language, designed to formulate, exchange and reason with knowledge about a domain of interest.
Ontology Query. What is an Ontology Ontologies resemble faceted taxonomies but use richer semantic relationships among terms and attributes, as well as.
SPARQL All slides are adapted from the W3C Recommendation SPARQL Query Language for RDF Web link:
Presentation : Konstantinos Kanaris.  What is Jena?  Usage of Jena  Main Concepts  Main Components  Storage Models  OWL API  RDF API  Reasoning.
Michael Eckert1CS590SW: Web Ontology Language (OWL) Web Ontology Language (OWL) CS590SW: Semantic Web (Winter Quarter 2003) Presentation: Michael Eckert.
Metadata. Generally speaking, metadata are data and information that describe and model data and information For example, a database schema is the metadata.
Advanced topics in software engineering (Semantic web)
Efficient RDF Storage and Retrieval in Jena2 Written by: Kevin Wilkinson, Craig Sayers, Harumi Kuno, Dave Reynolds Presented by: Umer Fareed 파리드.
1 Artificial Intelligence Applications Institute Centre for Intelligent Systems and their Applications Stuart Aitken Artificial Intelligence Applications.
Practical RDF Chapter 10. Querying RDF: RDF as Data Shelley Powers, O’Reilly SNU IDB Lab. Hyewon Lim.
User Profiling using Semantic Web Group members: Ashwin Somaiah Asha Stephen Charlie Sudharshan Reddy.
6 Dec Rev. 14 Dec CmpE 583 Fall 2008OWL Intro 1 OWL Intro Notes off Lacy Ch. 4 Atilla Elçi.
OWL Web Ontology Language Overview. The OWL Web Ontology Language is designed for use by applications that need to process the content of information.
THE SEMANTIC WEB By Conrad Williams. Contents  What is the Semantic Web?  Technologies  XML  RDF  OWL  Implementations  Social Networking  Scholarly.
Basics of JDBC Session 14.
Intelligent Space 國立台灣大學資訊工程研究所 智慧型空間實驗室 Jena: A Semantic Web Framework for Java Reporter C.F.Liao ( 廖峻鋒 ) May 17,2007.
W3C’s (world wide web consortium) Semantic Web: - RDF and metadata markup efforts to represent data in a machine understandable form. DARPA started the.
Web Ontology Language (OWL). OWL The W3C Web Ontology Language (OWL) is a Semantic Web language designed to represent rich and complex knowledge about.
Semantic Interoperability in GIS N. L. Sarda Suman Somavarapu.
Sesame A generic architecture for storing and querying RDF and RDFs Written by Jeen Broekstra, Arjohn Kampman Summarized by Gihyun Gong.
Ontology Technology applied to Catalogues Paul Kopp.
Jena 2 Ontology API 4/28/2017.
Ontology 101 PHIN Ontology Workshop August Ontology 101 Agenda What is (an) Ontology? What do we mean when we use the word? The main types of Ontologies.
Introduction to Database Programming with Python Gary Stewart
1 Knowledge Representation XI – IKT437 Knowledge Representation XI – IKT437 Part I RDF Jan Pettersen Nytun, UiA Apache Jena.
OWL (Ontology Web Language and Applications) Maw-Sheng Horng Department of Mathematics and Information Education National Taipei University of Education.
Knowledge Representation XI – IKT437 Part II OWL, SPARQL, …
Databases (CS507) CHAPTER 2.
Jena Ontology API 4/14/2018.
Charlie Abela Department of Intelligent Computer Systems
Knowledge Representation Part II Description Logic & Introduction to Protégé Jan Pettersen Nytun.
Building Trustworthy Semantic Webs
Jena 6/8/2018.
Introduction to the Semantic Web (tutorial) 2009 Semantic Technology Conference San Jose, California, USA June 15, 2009 Ivan Herman, W3C
Online Laptop Shop through Semantic Web
Knowledge Representation Part II
Grid Computing 7700 Fall 2005 Lecture 18: Semantic Grid
Jena Sparql (for Mac) 9/22/2018.
ece 720 intelligent web: ontology and beyond
Triple Stores.
Grid Computing 7700 Fall 2005 Lecture 18: Semantic Grid
Triple Stores.
Presentation transcript:

The Jena RDF Framework Konstantinos Tzonas

Contents What is Jena Capabilities of Jena Basic notions RDF concepts in Jena Persistence Ontology management Reasoning SPARQL Query processing

What is Jena Jena is a Java framework for the creation of applications for the Semantic Web Provides interfaces and classes for the creation and manipulation of RDF repositories Also provides classes/interfaces for the management of OWL-based ontologies

Capabilities of Jena RDF API Reading and writing in RDF/XML, N-Triples OWL API In-memory and persistent storage SPARQL query engine

RDF Concepts Resources, Properties, Literals, Statements (Triples: <subj pred obj>) A set of (related) statements constitute an RDF graph The Jena RDF API contains classes and interfaces for every important aspect of the RDF specification They can be used in order to construct RDF graphs from scratch, or edit existent graphs These classes/interfaces reside in the com.hp.hpl.jena.rdf.model package In Jena, the Model interface is used to represent RDF graphs Through Model, statements can be obtained/ created/ removed etc

RDF API - Example // Create an empty model Model model = ModelFactory.createDefaultModel(); String ns = new String("http://www.example.com/example#"); // Create two Resources Resource john = model.createResource(ns + "John"); Resource jane = model.createResource(ns + "Jane"); // Create the 'hasBrother' Property declaration Property hasBrother = model.createProperty(ns, "hasBrother"); // Associate jane to john through 'hasBrother' jane.addProperty(hasBrother, john); // Create the 'hasSister' Property declaration Property hasSister = model.createProperty(ns, "hasSister"); // Associate john and jane through 'hasSister' with a Statement Statement sisterStmt = model.createStatement(john, hasSister, jane); model.add(sisterStmt);

Reading/Writing models RDF Models can be retrieved from external sources (files/databases) Example of a Model retrieved by a file // The location of the RDF file is specified String fileURI = “file:myRDF.rdf”; // An empty Model is created Model modelFromFile = ModelFactory.createDefaultModel(); // The Model retrieves the definitions in the RDF file modelFromFile.read(fileURI); Example of a Model being written to the stanadard output in RDF/XML // The destination and RDF dialect are specified Model.write(System.out, “RDF/XML”)

Reading from databases The package com.hp.hpl.jena.db is used to provide persistent storage of Jena Models Accessing a Model in a MySQL DB: try { // Load MySQL driver Class.forName("com.mysql.jdbc.Driver"); } catch(ClassNotFoundException e) { ... } // Create a database connection IDBConnection conn = new DBConnection("jdbc:mysql://localhost/jenadb", “user”, “pass”, "MySQL"); ModelMaker maker = ModelFactory.createModelRDBMaker(conn); // Retrieve Model Model dbModel = maker.openModel(“http://www.example.com/example", true); // View all the statements in the model as triples StmtIterator iter = dbModel.listStatements(); while(iter.hasNext()) { Statement stmt = (Statement)iter.next(); System.out.println(stmt.asTriple().toString());

Jena OWL API OWL is an extension to RDF. This relation is reflected in the Jena framework OWL related classes/interfaces extend or use classes/interfaces of the RDF API Properties  Datatype properties, Object properties, Symmetric, Functional, InverseFunctional… Resources  Ontology Resources  Classes, Individuals Subclass-superclass relations (from RDFS) Equivalency/Disjointness Constraints on properties (AllValuesFrom, <Min/Max>Cardinality restrictions, etc) The OWL API of Jena provides classes/interfaces to represent all aspects of the OWL language These classes/interfaces reside in the com.hp.hpl.jena.ontology package OntModel is the interface mostly used to manage ontologies

Jena OWL API OntModel Classes are represented by OntClass Contains ontology statements Can be used to retrieve existent resources (Classes, individuals, properties etc) or create new ones Classes are represented by OntClass OntClass methods can be used to view the instances, superclasses, subclasses, restrictions etc of a particular class OntClass provides methods in order to assert subclass/superclass relations, or class/instance relations Classes may be just ‘labels’ under which individuals are categorized, but they can be more complex, e.g. described using other class definitions UnionClass, IntersectionClass, EnumeratedClass, ComplementClass, Restriction The OWL API provides ways to determine whether a class falls on one of the above categories OntModel provides methods to construct such complex definitions

Jena OWL API Properties are represented by OntProperty OntProperty provides methods to define the domains and ranges of properties, as well as determine the property type DatatypeProperty, ObjectProperty, SymmetricProperty, FunctionalProperty etc Subproperty/Superproperty relations can be defined Properties are defined on their own (i.e., they are not ‘tied’ to certain classes, as happens in frame-like systems) However, it is often necessary to obtain ‘the properties of a specific class’. This means finding the properties with a domain ‘containing’ the specific class. Jena provides convenience methods for such tasks.

OWL API Example: Classes // Create an empty ontology model OntModel ontModel = ModelFactory.createOntologyModel(); String ns = new String(“http://www.example.com/onto1#”); String baseURI = new String(“http://www.example.com/onto1”); Ontology onto = ontModel.createOntology(baseURI); // Create ‘Person’, ‘MalePerson’ and ‘FemalePerson’ classes OntClass person = ontModel.createClass(ns + "Person"); OntClass malePerson = ontModel.createClass(ns + "MalePerson"); OntClass femalePerson = ontModel.createClass(ns + "FemalePerson"); // FemalePerson and MalePerson are subclasses of Person person.addSubClass(malePerson); person.addSubClass(femalePerson); // FemalePerson and MalePerson are disjoint malePerson.addDisjointWith(femalePerson); femalePerson.addDisjointWith(malePerson);

OWL API Example: Classes

OWL API Example: Datatype properties // Create datatype property 'hasAge' DatatypeProperty hasAge = ontModel.createDatatypeProperty(ns + "hasAge"); // 'hasAge' takes integer values, so its range is 'integer' // Basic datatypes are defined in the ‘vocabulary’ package hasAge.setDomain(person); hasAge.setRange(XSD.integer); // com.hp.hpl.jena.vocabulary.XSD // Create individuals Individual john = malePerson.createIndividual(ns + "John"); Individual jane = femalePerson.createIndividual(ns + "Jane"); Individual bob = malePerson.createIndividual(ns + "Bob"); // Create statement 'John hasAge 20' Literal age20 = ontModel.createTypedLiteral("20", XSDDatatype.XSDint); Statement johnIs20 = ontModel.createStatement(john, hasAge, age20); ontModel.add(johnIs20);

OWL API Example: Datatype properties

OWL API Example: Object properties // Create object property 'hasSibling' ObjectProperty hasSibling = ontModel.createObjectProperty(ns + "hasSibling"); // Domain and Range for 'hasSibling' is 'Person' hasSibling.setDomain(person); hasSibling.setRange(person); // Add statement 'John hasSibling Jane‘ // and 'Jane hasSibling John' Statement siblings1 = ontModel.createStatement(john, hasSibling, jane); Statement siblings2 = ontModel.createStatement(jane, hasSibling, john); ontModel.add(siblings1); ontModel.add(siblings2);

OWL API Example: Property Restrictions // Create object property ‘hasSpouse’ ObjectProperty hasSpouse = ontModel.createObjectProperty(ns + "hasSpouse"); hasSpouse.setDomain(person); hasSpouse.setRange(person); Statement spouse1 = ontModel.createStatement(bob, hasSpouse, jane); Statement spouse2 = ontModel.createStatement(jane, hasSpouse, bob); ontModel.add(spouse1); ontModel.add(spouse2); // Create an AllValuesFromRestriction on hasSpouse: // MalePersons hasSpouse only FemalePerson AllValuesFromRestriction onlyFemalePerson = ontModel.createAllValuesFromRestriction(null, hasSpouse, femalePerson); // A MalePerson can have at most one spouse -> MaxCardinalityRestriction MaxCardinalityRestriction hasSpouseMaxCard = ontModel.createMaxCardinalityRestriction(null, hasSpouse, 1); // Constrain MalePerson with the two constraints defined above malePerson.addSuperClass(onlyFemalePerson); malePerson.addSuperClass(hasSpouseMaxCard);

OWL API Example: Property Restrictions

OWL API Example: Defined Classes // Create class ‘MarriedPerson’ OntClass marriedPerson = ontModel.createClass(ns + "MarriedPerson"); MinCardinalityRestriction mincr = ontModel.createMinCardinalityRestriction(null, hasSpouse, 1); // A MarriedPerson  A Person, AND with at least 1 spouse // A list must be created, that will hold the Person class // and the min cardinality restriction RDFNode[] constraintsArray = { person, mincr }; RDFList constraints = ontModel.createList(constraintsArray); // The two classes are combined into one intersection class IntersectionClass ic = ontModel.createIntersectionClass(null, constraints); // ‘MarriedPerson’ is declared as an equivalent of the // intersection class defined above marriedPerson.setEquivalentClass(ic);

OWL API Example: Defined Classes

Reasoning Jena is designed so that inference engines can be ‘plugged’ in Models and reason with them The reasoning subsystem of Jena is found in the com.hp.hpl.jena.reasoner package All reasoners must provide implementations of the ‘Reasoner’ Java interface Jena provides some inference engines, which however have limited reasoning capabilities Accessible through the ReasonerRegistry class Once a Reasoner object is obtained, it must be ‘attached’ to a Model. This is accomplished by modifying the Model specifications

Reasoning Objects of the OntModelSpec class are used to form model specifications Storage scheme Inference engine Language profile (RDF, OWL-Lite, OWL-DL, OWL Full, DAML) Jena provides predefined OntModelSpec objects for basic Model types e.g. The OntModelSpec.OWL_DL_MEM object is a specification of OWL-DL models, stored in memory, which use no reasoning. Reasoner implementations can then be attached, as in the following example: // PelletReasonerFactory is found in the Pellet API Reasoner reasoner = PelletReasonerFactory.theInstance().create(); // Obtain standard OWL-DL spec and attach the Pellet reasoner OntModelSpec ontModelSpec = OntModelSpec.OWL_DL_MEM; ontModelSpec.setReasoner(reasoner); // Create ontology model with reasoner support OntModel ontModel = ModelFactory.createOntologyModel(ontModelSpec, model);

Reasoning Apart from the reference to a Reasoner object, no further actions are required to enable reasoning OntModels without reasoning support will answer queries using only the asserted statements, while OntModels with reasoning support will infer additional statements, without any interaction with the programmer // MarriedPerson has no asserted instances // However, if an inference engine is used, two of the three // individuals in the example presented here will be // recognized as MarriedPersons OntClass marriedPerson = ontModel.getOntClass(ns + “MarriedPerson”); ExtendedIterator married = marriedPerson.listInstances(); while(married.hasNext()) { OntResource mp = (OntResource)married.next(); System.out.println(mp.getURI()); }

SPARQL query processing Jena uses the ARQ engine for the processing of SPARQL queries The ARQ API classes are found in com.hp.hpl.jena.query Basic classes in ARQ: Query: Represents a single SPARQL query. Dataset: The knowledge base on which queries are executed (Equivalent to RDF Models) QueryFactory: Can be used to generate Query objects from SPARQL strings QueryExecution: Provides methods for the execution of queries ResultSet: Contains the results obtained from an executed query QuerySolution: Represents a row of query results. If there are many answers to a query, a ResultSet is returned after the query is executed. The ResultSet contains many QuerySolutions

SPARQL query execution example // Prepare query string String queryString = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX : <http://www.example.com/onto1#>\n" + "SELECT ?married ?spouse WHERE {" + "?married rdf:type :MarriedPerson.\n" + "?married :hasSpouse ?spouse." + "}"; // Use the ontology model to create a Dataset object // Note: If no reasoner has been attached to the model, no results // will be returned (MarriedPerson has no asserted instances) Dataset dataset = DatasetFactory.create(ontModel); // Parse query string and create Query object Query q = QueryFactory.create(queryString); // Execute query and obtain result set QueryExecution qexec = QueryExecutionFactory.create(q, dataset); ResultSet resultSet = qexec.execSelect();

SPARQL query execution example // Print results while(resultSet.hasNext()) { // Each row contains two fields: ‘married’ and ‘spouse’, // as defined in the query string QuerySolution row = (QuerySolution)resultSet.next(); RDFNode nextMarried = row.get("married"); System.out.print(nextMarried.toString()); System.out.print(" is married to "); RDFNode nextSpouse = row.get("spouse"); System.out.println(nextSpouse.toString()); }

Notes Jena can be used to manage existent ontologies, or create ontologies from scratch Regardless of the storage method Understanding the triple and/or XML form of ontology documents is required, since some complex concepts like restrictions, RDF lists and defined classes must be created in certain ways (otherwise, inconsistencies may be caused) Reasoning with existent data in order to obtain inferred knowledge Inference engines must provide implementations of a specific Java interface For complex ontologies, reasoning may slow down your application, especially if data is inserted or removed regularly from the ontology It is important to know when an inference engine is actually needed

End of presentation