Master Informatique 1 Semantic Technologies Part 4Jena Werner Nutt.

Slides:



Advertisements
Similar presentations
RDF and RDF Schema Raúl García-Castro, Óscar Corcho, Daniel Vila-Suero
Advertisements

Language (Formalisms) For Ontology Building Neda Alipanah 22 October 2012.
Querying the RDF: Small Case Study in the Bicycle Sale Domain Ondřej Šváb, Vojtěch Svátek, Martin Kavalec, Martin Labský VŠE, University of Economics,
The Semantic Web – WEEK 4: RDF
Semantic Web Andrejs Lesovskis 4/11/2017 6:03 PM
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
1 RDF Tutorial. C. Abela RDF Tutorial2 What is RDF? RDF stands for Resource Description Framework It is used for describing resources on the web Makes.
인터넷기술 강혜원 Java 를 이용한 RDF Process 인터넷기술 012ITI01 강혜원.
An Introduction to Semantic Web Portal
1 © Copyright 2010 Dieter Fensel, Federico Facca and Ioan Toma Semantic Web Storage and Querying.
RDF – RESOURCE DESCRIPTION FRAMEWORK Antonio Bucchiarone FBK-IRST Trento, Italy 20 Novembre 2009.
Jena a introduction Semantic Web Tools. Originally devised by HP Labs in Bristol, it was developed by Brian McBride of Hewlett-Packard and was derived.
ESDSWG2011 – Semantic Web session Semantic Web Sub-group Session ESDSWG 2011 Meeting – Semantic Web sub-group session Wednesday, November 2, 2011 Norfolk,
RDF Tutorial.
Semantic Web Introduction
JENA –A SEMANTIC WEB TOOL by Ranjani Sankaran & krishna Priyanka Chebrolu.
© Copyright IBM Corporation 2014 Getting started with Rational Engineering Lifecycle Manager queries Andy Lapping – Technical sales and solutions Joanne.
ICE0534 – Web-based Software Development ICE1338 – Programming for WWW Lecture #12 Lecture #12 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information.
Jena Sparql 4/11/2017.
 Copyright 2004 Digital Enterprise Research Institute. All rights reserved. SPARQL Query Language for RDF presented by Cristina Feier.
SPARQL RDF Query.
RDF formats for Linked Data by Mabi Harandi. RDF is not a format, it is a model for data So: It will provide supports for different formats like :  Turtle.
Chapter 3 RDF Syntax 1. Topics Basic concepts of RDF resources, properties, values, statements, triples URIs and URIrefs RDF graphs Literals and Qnames.
Michael Povolotsky CMSC491s/691s. What is Virtuoso? Virtuoso, known as Virtuoso Universal Server, is a multi-protocol RDBMS Includes an object-relational.
Triple Stores
A division of Publishing Technology Facet Building Web Pages With SPARQL SWIG-UK Event, HP Labs November 23 rd 2007 Leigh Dodds Chief Technology Officer,
RDF(S) Tools Adrian Pop, Programming Environments Laboratory Linköping University.
Jena --- A Java API for RDF Jing deng CSCI 7818 Web Technologies Computer Science Department University of Colorado at Boulder Wednesday, October 31, 2001.
Internet Technologies 1 Master of Information System Management Internet Technologies The Resource Description Framework (RDF)
Jena 4/17/2017.
1 An Introduction to RDF and the Jena RDF API. 2 Outline Introduction Statements Writing RDF Reading RDF Navigating a Graph Querying a Graph Operations.
Using Java in Linked Data Applications Fuming Shih Oct 12.
Triple Stores.
Managing Large RDF Graphs (Infinite Graph) Vaibhav Khadilkar Department of Computer Science, The University of Texas at Dallas FEARLESS engineering.
Rajashree Deka Tetherless World Constellation Rensselaer Polytechnic Institute.
Master Informatique 1 Semantic Technologies Part 5SPARQL Werner Nutt.
Co-funded by the European Union Semantic CMS Community Semantic Data Access Copyright IKS Consortium 1 SRDC Ltd. August, 2011.
Towards linked sensor data Analysis of project task, tools and Hackystat architecture Author: Myriam Leggieri GSoC 2009 project for Hackystat.
The Jena RDF Framework Konstantinos Tzonas. Contents What is Jena Capabilities of Jena Basic notions RDF concepts in Jena Persistence Ontology management.
Master Informatique 1 Semantic Technologies Part 11Direct Mapping Werner Nutt.
Ontology Query. What is an Ontology Ontologies resemble faceted taxonomies but use richer semantic relationships among terms and attributes, as well as.
Presentation : Konstantinos Kanaris.  What is Jena?  Usage of Jena  Main Concepts  Main Components  Storage Models  OWL API  RDF API  Reasoning.
Efficient RDF Storage and Retrieval in Jena2 Written by: Kevin Wilkinson, Craig Sayers, Harumi Kuno, Dave Reynolds Presented by: Umer Fareed 파리드.
RDF languages and storages part 1 - expressivness Maciej Janik Conrad Ibanez CSCI 8350, Fall 2004.
Using the DAWG Test Cases with Relational Databases Matthew Gheen October 26, 2007.
Practical RDF Chapter 10. Querying RDF: RDF as Data Shelley Powers, O’Reilly SNU IDB Lab. Hyewon Lim.
Introduction to the Semantic Web and Linked Data Module 1 - Unit 2 The Semantic Web and Linked Data Concepts 1-1 Library of Congress BIBFRAME Pilot Training.
User Profiling using Semantic Web Group members: Ashwin Somaiah Asha Stephen Charlie Sudharshan Reddy.
THE BIBFRAME EDITOR AND THE LC PILOT Module 3 – Unit 1 The Semantic Web and Linked Data : a Recap of the Key Concepts Library of Congress BIBFRAME Pilot.
Ontology based e-Real Estate Agency Information System By Moein Mehrolhasani Bijan Zamanian cmpe 588.
Triple Stores. What is a triple store? A specialized database for RDF triples Can ingest RDF in a variety of formats Supports a query language – SPARQL.
Doc.: IEEE /0169r0 Submission Joe Kwak (InterDigital) Slide 1 November 2010 Slide 1 Overview of Resource Description Framework (RFD/XML) Date:
RDF storages and indexes Maciej Janik September 1, 2005 Enterprise Integration – Semantic Web.
Linked Open Data for European Earth Observation Products Carlo Matteo Scalzo CTO, Epistematica epistematica.
CHAPTER 8 – Jena:RDF in Java 박형우 SNU OOPSLA Lab. August 27, 2004.
Semantic Web In Depth Resource Description Framework Dr Nicholas Gibbins –
Setting the stage: linked data concepts Moving-Away-From-MARC-a-thon.
1 Knowledge Representation XI – IKT437 Knowledge Representation XI – IKT437 Part I RDF Jan Pettersen Nytun, UiA Apache Jena.
Charlie Abela Department of Intelligent Computer Systems
Triple Stores.
Jena 6/8/2018.
Resource Description Framework
University of Central Florida COP 3330 Object Oriented Programming
Knowledge Representation Part II
Miguel Azurin, Andrew Engroff, Ahmad Sadiq
Jena Sparql (for Mac) 9/22/2018.
Triple Stores.
The Jena RDF Framework Konstantinos Tzonas.
Triple Stores.
Triple Stores.
Presentation transcript:

Master Informatique 1 Semantic Technologies Part 4Jena Werner Nutt

Master Informatique 2 Semantic Technologies Part 4Jena Acknowledgment These slides are based on the slide set RDF By Mariano Rodriguez (see

Master Informatique 3 Semantic Technologies Part 4Jena Available at Available under the Apache license. Developed by HP Labs (now community based development) Best-known framework Used to: –Create and manipulate RDF graphs –Query RDF graphs –Read/Serialize RDF from/into different syntaxes –Perform inference –Build SPARQL endpoints Tutorial:

Master Informatique 4 Semantic Technologies Part 4Jena Basic operations Creating a graph from Java –URIs/Literals/Bnodes Listing all “Statements” Writing RDF (Turtle/N-Triple/XML) Reading RDF Prefixes Querying (through the API)

Master Informatique 5 Semantic Technologies Part 4Jena Creating a basic graph // some definitions static String personURI = " static String fullName = "John Smith"; URIs in Jena are strings // create an empty Model Model model = ModelFactory.createDefaultModel(); RDF graphs are “models” in the Jena API (and “graphs” in the SPI = Service Provider API) Model is an interface (why?) The DefaultModel is an empty “model”

Master Informatique 6 Semantic Technologies Part 4Jena Creating a basic graph // create the resource Resource johnSmith = model.createResource(personURI); Resources are attached to a model // add the property johnSmith.addProperty(VCARD.FN, fullName); VCARD is the Jena “vocabulary class” for the vCard vocabulary vCard terms are static attributes of the class VCARD addProperty takes two arguments a property a resource and creates a statement as a side effiect

Master Informatique 7 Semantic Technologies Part 4Jena Result

Master Informatique 8 Semantic Technologies Part 4Jena Creating a basic graph // some definitions String personURI = " 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)); createResource() creates a blank node

Master Informatique 9 Semantic Technologies Part 4Jena Result

Master Informatique 10 Semantic Technologies Part 4Jena Statements Statements and triples are the same kind of thing Models are sets of statements  adding duplicate statements has no effect Statements are inserted into a model by calls of addProperty Statements in Jena have subject, predicate, and object, like in the RDF data model –and selectors getSubject, getPredicate, getObject –getObject returns instances of RDFNode, a superclass of Resource and Literal Statements can be retrieved from a model with a statement iterator StmtIterator

Master Informatique 11 Semantic Technologies Part 4Jena Listing the statements of a model // list the statements in the Model StmtIterator iter = model.listStatements(); // print out the subject, predicate, and object of each statement while (iter.hasNext()) { Statement stmt = iter.nextStatement(); // get next statement Resource subject = stmt.getSubject(); // get the subject Property predicate = stmt.getPredicate(); // get the predicate RDFNode object = stmt.getObject(); // get the object System.out.print(subject.toString()); System.out.print(" " + predicate.toString() + " "); if (object instanceof Resource) { System.out.print(object.toString()); } else { // object is a literal System.out.print(" \"" + object.toString() + "\""); } System.out.println("."); }

Master Informatique 12 Semantic Technologies Part 4Jena Output anon:14df86:ecc3dee17b:-7fff. anon:14df86:ecc3dee17b:-7fff "Smith". anon:14df86:ecc3dee17b:-7fff "John". "John Smith". anon:14df86:ecc3dee17b:-7fff. anon:14df86:ecc3dee17b:-7fff "Smith". anon:14df86:ecc3dee17b:-7fff "John". "John Smith". Something like this:

Master Informatique 13 Semantic Technologies Part 4Jena Writing RDF Use the model.write(OutputStream s) method –any output stream is valid By default it will write in RDF/XML format Change format by specifying the format with: –model.write(OutputStream s, String format) –possible format strings: "RDF/XML-ABBREV" "N-TRIPLE" "RDF/XML" "TURTLE" "TTL" "N3"

Master Informatique 14 Semantic Technologies Part 4Jena Writing RDF <rdf:RDF xmlns:rdf=" xmlns:vcard=" > John Smith John Smith <rdf:RDF xmlns:rdf=" xmlns:vcard=" > John Smith John Smith // now write the model in XML form to a file model.write(System.out);

Master Informatique 15 Semantic Technologies Part 4Jena Default XML writer: Shortcomings Blank notes are not represented correctly –the blank node in the graph has been given a URI reference XML/RDF can represented blank nodes only to some extent: –only bNodes that appear no more than once as an object The Jena PrettyWriter (invoked by "RDF/XML-ABBREV”) –produces more compact XML –gets bNodes right when possible –needs a lot of time

Master Informatique 16 Semantic Technologies Part 4Jena Reading RDF Use model.read(InputStream, String syntax) // create an empty model Model model = ModelFactory.createDefaultModel(); // use the FileManager to find the input file InputStream in = FileManager.get().open( inputFileName ); if (in == null) { throw new IllegalArgumentException( "File: " + inputFileName + " not found"); } // read the RDF/XML file model.read(in, null); // write it to standard out model.write(System.out); the second argument of read(.,.) is the URI used for resolving relative (= shortened) URIs

Master Informatique 17 Semantic Technologies Part 4Jena Controlling Prefixes Prefixes are used in Turtle/RDF and other syntaxes Define prefixes prior to writing to obtain a “short” rendering

Master Informatique 18 Semantic Technologies Part 4Jena Example Model m = ModelFactory.createDefaultModel(); String nsA = " String nsB = " Resource root = m.createResource( nsA + "root" ); Property P = m.createProperty( nsA + "P" ); Property Q = m.createProperty( nsB + "Q" ); Resource x = m.createResource( nsA + "x" ); Resource y = m.createResource( nsA + "y" ); Resource z = m.createResource( nsA + "z" ); m.add( root, P, x ).add( root, P, y ).add( y, Q, z ); System.out.println( "# -- no special prefixes defined" ); m.write( System.out ); System.out.println( "# -- nsA defined" ); m.setNsPrefix( "nsA", nsA ); m.write( System.out ); System.out.println( "# -- nsA and cat defined" ); m.setNsPrefix( "cat", nsB ); m.write( System.out );

Master Informatique 19 Semantic Technologies Part 4Jena Output 1 # -- no special prefixes defined <rdf:RDF xmlns:j.0=" xmlns:rdf=" xmlns:j.1=" >

Master Informatique 20 Semantic Technologies Part 4Jena Output 2 # -- nsA defined <rdf:RDF xmlns:j.0=" xmlns:rdf=" xmlns:nsA=" >

Master Informatique 21 Semantic Technologies Part 4Jena Output 3 # -- nsA and cat defined <rdf:RDF xmlns:cat=" xmlns:rdf=" xmlns:nsA=" >

Master Informatique 22 Semantic Technologies Part 4Jena Prefixes: Summary Namespace prefixes can be set by m.setNsPrefix( prefix, uri); dropped by m.removeNsPrefix( prefix); The effect of prefixes depends on the linearization chosen for the output (why?)

Master Informatique 23 Semantic Technologies Part 4Jena Navigating the model The API allows one to query the model to get specific statements Use model.getResource(uriString): to retrieve the resource or create a new one: With a resource, use getProperty to retrieve statements and their objects resource.getProperty(uriString).getObject()  what if a resource has several statements with the same predicate? We can add further statements to the model through the resource

Master Informatique 24 Semantic Technologies Part 4Jena // retrieve the John Smith vcard resource from the model Resource vcard = model.getResource(johnSmithURI); // retrieve the value of the N property Resource name = (Resource) vcard.getProperty(VCARD.N).getObject(); // retrieve the value of the N property Resource name = vcard.getProperty(VCARD.N).getResource(); // retrieve the first name property String fullName = vcard.getProperty(VCARD.FN).getString();

Master Informatique 25 Semantic Technologies Part 4Jena Adding statements We add two nickname properties to John Smith’s vcard vcard.addProperty(VCARD.NICKNAME, "Smithy").addProperty(VCARD.NICKNAME, "Adman"); We retrieve all the nicknames with an iterator // set up the output System.out.println("The nicknames of \"" + fullName + "\" are:"); // list the nicknames StmtIterator iter = vcard.listProperties(VCARD.NICKNAME); while (iter.hasNext()) { System.out.println(" " + iter.nextStatement().getObject().toString()); }

Master Informatique 26 Semantic Technologies Part 4Jena We retrieve all the nicknames with an iterator // set up the output System.out.println("The nicknames of \"" + fullName + "\" are:"); // list the nicknames StmtIterator iter = vcard.listProperties(VCARD.NICKNAME); while (iter.hasNext()) { System.out.println(" " + iter.nextStatement().getObject().toString()); } The nicknames of "John Smith" are: Smithy Adman The nicknames of "John Smith" are: Smithy Adman Output:

Master Informatique 27 Semantic Technologies Part 4Jena Final notes Key API objects: DataSet, Model, Statement, Resource and Literal The default model implementation is in-memory Other implementations exists that use different storage methods –Native Jena TDB. Persistent, on disk, storage of models using Jena’s own data structures and indexing techniques –SDB. Persistent storage through a relational database. We’ll see more features as we advance in the course Third parties offer their own triple stores through Jena’s API (OWLIM, Virtuoso, etc.)