SlideShare a Scribd company logo
1 of 43
+

Sesame

Mariano Rodriguez-Muro,
Free University of Bozen-Bolzano
+

Disclaimer


License




This work is licensed under a
Creative Commons Attribution-Share Alike 3.0 License
(http://creativecommons.org/licenses/by-sa/3.0/)

Material for these slides has been taken from


Programming the Semantic Web (Chapter 8)



Sesame’s documentation
+

Reading material


Programming the Semantic Web Chapter 8



Sesame user guide http://www.openrdf.org/doc/sesame2/users/



See also Jetty 8
http://download.eclipse.org/jetty/stable-8/dist/
+
Overview
+

Overview


Sesame


History



Overview



Repository API


Creating a Repository



Repository connections



Sesame Console



Sesame workbench
+

Overview and History


Open source Java for storage
and querying RDF



By Aduna for the On-ToKnowledge EU project



RDF inference





RDF IO (all file formats)

Now developed by Nlnet
foundation, Ontotext and
community volunteers



JDBC-like user API



Available at
www.openrdf.org



RESTful HTTP interface



SPARQL Protocol support



Easy learning curve, great
management features
+

Sesame components



RDF Model: contains all basic
entities



Repository API: high level API with
developer-methods



Rio: parsers and writers



HTTP Server: Java Servlets to
access Sesame repos



Sail: low level API for RDF stores
and inferencers (abstraction)



HTTPClient: Abstraction layer to
access HTTP Servers
+
Repository API
+

Repository API


Developer-focused API



In contrast with Jena, in Sesame RDF models are not handled
by the user (normally), instead we use Repositories.



Vendors provide triple stores as Repository implementations



Sesame provides the following repository implementations:






Main memory
Native RDF repository
Remote repository (HTTP proxy)

To use Sesame repositories, these must be stacked in Sails,
i.e., stacks of layered behavior
+

Creating a repository


An in-memory repo

Repository myRepository = new SailRepository(new MemoryStore());
myRepository.initialize();


An in-memory repo with persistance

File dataDir = new File("c:tempmyRepository");
Repository myRepository = new SailRepository( new
MemoryStore(dataDir) );
myRepository.initialize();
+

Creating a repository


a native RDF repository

File dataDir = new File("/path/to/datadir/");
Repository myRepository = new SailRepository(new NativeStore(dataDir));
myRepository.initialize();



a native RDF repository with custom indexes

File dataDir = new File("/path/to/datadir/");
String indexes = "spoc,posc,cosp";
Repository myRepository =
new SailRepository(new NativeStore(dataDir, indexes));
myRepository.initialize();
+

Creating a repository


a remote Repository

String sesameServer = "http://example.org/sesame2";
String repositoryID = "example-db";
Repository myRepository = new HTTPRepository(sesameServer,
repositoryID);
myRepository.initialize();
+

Using a repository:
RepositoryConnection


JDBC like-interface



Operations
 add triples by file, URI,
Statement
 query using SPARQL
SELECT, ASK or Construct
queries
 create, retrieve, remove
individual statements
 prepared queries



Transaction support
 commit(), rollback()
+

Adding to a repository
File file = new File("/path/to/example.rdf");
String baseURI = "http://example.org/example/local";

try {
RepositoryConnection con = myRepository.getConnection();
try {
con.add(file, baseURI, RDFFormat.RDFXML);
URL url = new URL("http://example.org/example/remote");
con.add(url, url.toString(), RDFFormat.RDFXML);
}
finally {
con.close();
}

}
catch (…)
+

Querying a repository (tuple)
RepositoryConnection con = myRepository.getConnection();
try {
String queryString = “SELECT …. “;
TupleQuery tupleQuery =
con.prepareTupleQuery(SPARQL, queryString);
TupleQueryResult result = tupleQuery.evaluate();
try {
.... // do something with the result
}
finally {
result.close();
}
}
finally {
con.close();
}
+

Tuple queries (cont)
while (result.hasNext()) {
BindingSet bindingSet = result.next();
Value valueOfX = bindingSet.getValue("x");
Value valueOfY = bindingSet.getValue("y");
// do something interesting with the values here...
}
List<String> bindingNames = result.getBindingNames();
while (result.hasNext()) {
BindingSet bindingSet = result.next();
Value firstValue =
bindingSet.getValue(bindingNames.get(0));
Value secondValue =
bindingSet.getValue(bindingNames.get(1));
// do something interesting with the values here...
}
+

TupleQueryResultHandler
FileOutputStream out = new FileOutputStream("/path/to/result.srx");
try {
SPARQLResultsXMLWriter sparqlWriter = new
SPARQLResultsXMLWriter(out);
RepositoryConnection con = myRepository.getConnection();
try {
String queryString = "SELECT * FROM {x} p {y}";
TupleQuery tupleQuery =
con.prepareTupleQuery(QueryLanguage.SERQL, queryString);
tupleQuery.evaluate(sparqlWriter);
}
finally {
con.close();
}
}
finally {
out.close();
}
+

Evaluating Graph queries

GraphQueryResult graphResult = con.prepareGraphQuery(
QueryLanguage.SPARQL, "CONSTRUCT ….").evaluate();

while (graphResult.hasNext()) {
Statement st = graphResult.next();
// ... do something with the resulting statement here.
}
+

RDF Handler


Equivalent for TupleQueryResultHandler > RDFHandler



Examples: RDFXMLWriter, TurtleWriter, etc.

TurtleWriter turtleWriter = new TurtleWriter(System.out);
con.prepareGraphQuery(QueryLanguage.SPARQL,
"CONSTRUCT …").evaluate(turtleWriter);
+

Adding individual statements
ValueFactory f = myRepository.getValueFactory();

URI alice = f.createURI("http://example.org/people/alice");
URI bob = f.createURI("http://example.org/people/bob");
URI name = f.createURI("http://example.org/ontology/name");
URI person = f.createURI("http://example.org/ontology/Person");
Literal bobsName = f.createLiteral("Bob");
Literal alicesName = f.createLiteral("Alice");
RepositoryConnection con = myRepository.getConnection();
con.add(alice, RDF.TYPE, person);
con.add(alice, name, alicesName);
con.add(bob, RDF.TYPE, person);
con.add(bob, name, bobsName);
+

Retrieving
RepositoryResult<Statement> statements = con.getStatements(alice,
null, null, true);
try {
while (statements.hasNext()) {
Statement st = statements.next();

... // do something with the statement
}
}
finally {
statements.close(); // make sure the result object is closed properly
}
+

Deleting statements


a single statement

con.remove(alice, name, alicesName);



many statements

con.remove(alice, null, null);
+

Iterators and statements


Sesame’s API offer many calls compatible for iterators to
facilitate “batch” manipulation

// Retrieve all statements about Alice and put them in a list
RepositoryResult<Statement> statements =
con.getStatements(alice, null, null, true));
List<Statement> aboutAlice =
Iterations.addAll(statements, new ArrayList<Statement>());
// Then, remove them from the repository
con.remove(aboutAlice);
con.remove(con.getStatements(alice, null, null, true));
+

Named graphs


Named graphs are natively supported by Sesame



Named graphs are called “Context” in Sesame

String location = "http://example.org/example/example.rdf";
String baseURI = location;
URL url = new URL(location);
URI context = f.createURI(location);
con.add(url, baseURI, RDFFormat.RDFXML, context);
+

Transactions


SQL-like transactions



Treat a “block” of operations as a single update



Failures can be “rolled back”
+

Transactions
File inputFile1 = new File("/path/to/example1.rdf");
String baseURI1 = "http://example.org/example1/";
File inputFile2 = new File("/path/to/example2.rdf");
String baseURI2 = "http://example.org/example2/";
RepositoryConnection con = myRepository.getConnection();
try {
con.setAutoCommit(false);
con.add(inputFile1, baseURI1, RDFFormat.RDFXML);
con.add(inputFile2, baseURI2, RDFFormat.RDFXML);

con.commit();
}
catch (RepositoryException e) { con.rollback(); }
finally { con.close(); }
+
Sesame Console
+

Sesame console


command-line application to
interact with Sesame



Possible actions:



Easy way to create and
manage repositories
Create in the console, use from
Java

Creating repositories



Load/Unload data from
Files/URIs/SPARQL Update







Query using SPARQL



Querying/Managing remote
Sesame repositories

> sh bin/console.sh
Connected to default data directory
Commands end with '.' at the end of a line
Type 'help.' for help
> help.
+


Repository types

memory,memory-rdfs
a memory based RDF repository
(optionaly with RDFS inference)

Please specify values for the following variables:
Repository ID [native]: myRepo
Repository title [Native store]: My repository
Triple indexes [spoc,posc]:
Repository created
 pgsql, mysql
> show repositories.
a repository that stores data in a
> +---------PostgreSQL (mysql) database
> |SYSTEM
> |myRepo(”My repository")
 remote -- a repository that serves as > +---------

native, native-rdfs
a repository that uses on-disk data
structure (optional RDFS inference)

a proxy for a repository on a Sesame
Server
+
Sesame Workbench
Repository Manager and SPARQL end-points with Sesame
+

Sesame workbench


SPARQL Protocol
implementation (sparqlendpoint) for Sesame
repositories



Web based management
console for Sesame
repositories



Web based query interface for
repositories.
+

Setup


Requires a JSP server, e.g.,
Tomcat or Jetty 8



Drop the 2 .war files from the
/war folder of the sesame .zip
into your webapps folder



Start the JSP server
If you are using Jetty, do:
jetty.sh/bat start
in the command line
4 sesame
4 sesame
4 sesame
4 sesame
4 sesame
4 sesame
4 sesame
4 sesame
4 sesame
4 sesame
4 sesame

More Related Content

What's hot

File include
File includeFile include
File includeRoy
 
eZ Publish cluster unleashed revisited
eZ Publish cluster unleashed revisitedeZ Publish cluster unleashed revisited
eZ Publish cluster unleashed revisitedBertrand Dunogier
 
Java Search Engine Framework
Java Search Engine FrameworkJava Search Engine Framework
Java Search Engine FrameworkAppsterdam Milan
 
C# Application program UNIT III
C# Application program UNIT IIIC# Application program UNIT III
C# Application program UNIT IIIMinu Rajasekaran
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web ServicesBradley Holt
 
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NYPuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NYPuppet
 
eZ Publish Cluster Unleashed
eZ Publish Cluster UnleashedeZ Publish Cluster Unleashed
eZ Publish Cluster UnleashedBertrand Dunogier
 
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -Kenji Tanaka
 
Automate the boring stuff with python
Automate the boring stuff with pythonAutomate the boring stuff with python
Automate the boring stuff with pythonDEEPAKSINGHBIST1
 
Vancouver presentation
Vancouver presentationVancouver presentation
Vancouver presentationColleen_Murphy
 
File upload for the 21st century
File upload for the 21st centuryFile upload for the 21st century
File upload for the 21st centuryJiří Pudil
 
Big data - Solr Integration
Big data - Solr IntegrationBig data - Solr Integration
Big data - Solr Integrationrkulandaivel
 

What's hot (20)

File include
File includeFile include
File include
 
eZ Publish cluster unleashed revisited
eZ Publish cluster unleashed revisitedeZ Publish cluster unleashed revisited
eZ Publish cluster unleashed revisited
 
Routing @ Scuk.cz
Routing @ Scuk.czRouting @ Scuk.cz
Routing @ Scuk.cz
 
File upload php
File upload phpFile upload php
File upload php
 
Database Homework Help
Database Homework HelpDatabase Homework Help
Database Homework Help
 
Finding Clojure
Finding ClojureFinding Clojure
Finding Clojure
 
Unqlite
UnqliteUnqlite
Unqlite
 
Java Search Engine Framework
Java Search Engine FrameworkJava Search Engine Framework
Java Search Engine Framework
 
C# Application program UNIT III
C# Application program UNIT IIIC# Application program UNIT III
C# Application program UNIT III
 
Database Homework Help
Database Homework HelpDatabase Homework Help
Database Homework Help
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web Services
 
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NYPuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
 
eZ Publish Cluster Unleashed
eZ Publish Cluster UnleashedeZ Publish Cluster Unleashed
eZ Publish Cluster Unleashed
 
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
 
Automate the boring stuff with python
Automate the boring stuff with pythonAutomate the boring stuff with python
Automate the boring stuff with python
 
Vancouver presentation
Vancouver presentationVancouver presentation
Vancouver presentation
 
Java
JavaJava
Java
 
Php sql-android
Php sql-androidPhp sql-android
Php sql-android
 
File upload for the 21st century
File upload for the 21st centuryFile upload for the 21st century
File upload for the 21st century
 
Big data - Solr Integration
Big data - Solr IntegrationBig data - Solr Integration
Big data - Solr Integration
 

Similar to 4 sesame

PigSPARQL: A SPARQL Query Processing Baseline for Big Data
PigSPARQL: A SPARQL Query Processing Baseline for Big DataPigSPARQL: A SPARQL Query Processing Baseline for Big Data
PigSPARQL: A SPARQL Query Processing Baseline for Big DataAlexander Schätzle
 
WebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPediaWebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPediaKatrien Verbert
 
Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Baruch Sadogursky
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareAlona Mekhovova
 
Tutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component pluginTutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component pluginsearchbox-com
 
Web data from R
Web data from RWeb data from R
Web data from Rschamber
 
Ingesting and Manipulating Data with JavaScript
Ingesting and Manipulating Data with JavaScriptIngesting and Manipulating Data with JavaScript
Ingesting and Manipulating Data with JavaScriptLucidworks
 
Java7 New Features and Code Examples
Java7 New Features and Code ExamplesJava7 New Features and Code Examples
Java7 New Features and Code ExamplesNaresh Chintalcheru
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsSadayuki Furuhashi
 
SWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQLSWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQLMariano Rodriguez-Muro
 
Writing Swift code with great testability
Writing Swift code with great testabilityWriting Swift code with great testability
Writing Swift code with great testabilityJohn Sundell
 
WhatsNewNIO2.pdf
WhatsNewNIO2.pdfWhatsNewNIO2.pdf
WhatsNewNIO2.pdfMohit Kumar
 
Web Technologies (8/12): XML & HTML Data Processing. Simple API for XML. Simp...
Web Technologies (8/12): XML & HTML Data Processing. Simple API for XML. Simp...Web Technologies (8/12): XML & HTML Data Processing. Simple API for XML. Simp...
Web Technologies (8/12): XML & HTML Data Processing. Simple API for XML. Simp...Sabin Buraga
 

Similar to 4 sesame (20)

Tornadoweb
TornadowebTornadoweb
Tornadoweb
 
LibreCat::Catmandu
LibreCat::CatmanduLibreCat::Catmandu
LibreCat::Catmandu
 
PigSPARQL: A SPARQL Query Processing Baseline for Big Data
PigSPARQL: A SPARQL Query Processing Baseline for Big DataPigSPARQL: A SPARQL Query Processing Baseline for Big Data
PigSPARQL: A SPARQL Query Processing Baseline for Big Data
 
WebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPediaWebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPedia
 
Power tools in Java
Power tools in JavaPower tools in Java
Power tools in Java
 
Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java
 
4 sw architectures and sparql
4 sw architectures and sparql4 sw architectures and sparql
4 sw architectures and sparql
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
 
Angular Schematics
Angular SchematicsAngular Schematics
Angular Schematics
 
Tutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component pluginTutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component plugin
 
Web data from R
Web data from RWeb data from R
Web data from R
 
Ingesting and Manipulating Data with JavaScript
Ingesting and Manipulating Data with JavaScriptIngesting and Manipulating Data with JavaScript
Ingesting and Manipulating Data with JavaScript
 
Apache Beam de A à Z
 Apache Beam de A à Z Apache Beam de A à Z
Apache Beam de A à Z
 
Java7 New Features and Code Examples
Java7 New Features and Code ExamplesJava7 New Features and Code Examples
Java7 New Features and Code Examples
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
 
SWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQLSWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQL
 
Writing Swift code with great testability
Writing Swift code with great testabilityWriting Swift code with great testability
Writing Swift code with great testability
 
Xml & Java
Xml & JavaXml & Java
Xml & Java
 
WhatsNewNIO2.pdf
WhatsNewNIO2.pdfWhatsNewNIO2.pdf
WhatsNewNIO2.pdf
 
Web Technologies (8/12): XML & HTML Data Processing. Simple API for XML. Simp...
Web Technologies (8/12): XML & HTML Data Processing. Simple API for XML. Simp...Web Technologies (8/12): XML & HTML Data Processing. Simple API for XML. Simp...
Web Technologies (8/12): XML & HTML Data Processing. Simple API for XML. Simp...
 

More from Mariano Rodriguez-Muro

SWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mappingSWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mappingMariano Rodriguez-Muro
 
SWT Lecture Session 8 - Inference in jena
SWT Lecture Session 8 - Inference in jenaSWT Lecture Session 8 - Inference in jena
SWT Lecture Session 8 - Inference in jenaMariano Rodriguez-Muro
 
SWT Lecture Session 7 - Advanced uses of RDFS
SWT Lecture Session 7 - Advanced uses of RDFSSWT Lecture Session 7 - Advanced uses of RDFS
SWT Lecture Session 7 - Advanced uses of RDFSMariano Rodriguez-Muro
 
SWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfs
SWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfsSWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfs
SWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfsMariano Rodriguez-Muro
 
Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...
Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...
Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...Mariano Rodriguez-Muro
 

More from Mariano Rodriguez-Muro (20)

SWT Lecture Session 2 - RDF
SWT Lecture Session 2 - RDFSWT Lecture Session 2 - RDF
SWT Lecture Session 2 - RDF
 
SWT Lab 3
SWT Lab 3SWT Lab 3
SWT Lab 3
 
SWT Lab 5
SWT Lab 5SWT Lab 5
SWT Lab 5
 
SWT Lab 2
SWT Lab 2SWT Lab 2
SWT Lab 2
 
SWT Lab 1
SWT Lab 1SWT Lab 1
SWT Lab 1
 
SWT Lecture Session 11 - R2RML part 2
SWT Lecture Session 11 - R2RML part 2SWT Lecture Session 11 - R2RML part 2
SWT Lecture Session 11 - R2RML part 2
 
SWT Lecture Session 10 R2RML Part 1
SWT Lecture Session 10 R2RML Part 1SWT Lecture Session 10 R2RML Part 1
SWT Lecture Session 10 R2RML Part 1
 
SWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mappingSWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mapping
 
SWT Lecture Session 8 - Rules
SWT Lecture Session 8 - RulesSWT Lecture Session 8 - Rules
SWT Lecture Session 8 - Rules
 
SWT Lecture Session 8 - Inference in jena
SWT Lecture Session 8 - Inference in jenaSWT Lecture Session 8 - Inference in jena
SWT Lecture Session 8 - Inference in jena
 
SWT Lecture Session 7 - Advanced uses of RDFS
SWT Lecture Session 7 - Advanced uses of RDFSSWT Lecture Session 7 - Advanced uses of RDFS
SWT Lecture Session 7 - Advanced uses of RDFS
 
SWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfs
SWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfsSWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfs
SWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfs
 
SWT Lecture Session 5 - RDFS
SWT Lecture Session 5 - RDFSSWT Lecture Session 5 - RDFS
SWT Lecture Session 5 - RDFS
 
SWT Lecture Session 4 - Sesame
SWT Lecture Session 4 - SesameSWT Lecture Session 4 - Sesame
SWT Lecture Session 4 - Sesame
 
SWT Lecture Session 3 - SPARQL
SWT Lecture Session 3 - SPARQLSWT Lecture Session 3 - SPARQL
SWT Lecture Session 3 - SPARQL
 
7 advanced uses of rdfs
7 advanced uses of rdfs7 advanced uses of rdfs
7 advanced uses of rdfs
 
5 rdfs
5 rdfs5 rdfs
5 rdfs
 
SWT Lecture Session 1 - Introduction
SWT Lecture Session 1 - IntroductionSWT Lecture Session 1 - Introduction
SWT Lecture Session 1 - Introduction
 
ontop: A tutorial
ontop: A tutorialontop: A tutorial
ontop: A tutorial
 
Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...
Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...
Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...
 

Recently uploaded

Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 

Recently uploaded (20)

Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

4 sesame

  • 2. + Disclaimer  License   This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License (http://creativecommons.org/licenses/by-sa/3.0/) Material for these slides has been taken from  Programming the Semantic Web (Chapter 8)  Sesame’s documentation
  • 3. + Reading material  Programming the Semantic Web Chapter 8  Sesame user guide http://www.openrdf.org/doc/sesame2/users/  See also Jetty 8 http://download.eclipse.org/jetty/stable-8/dist/
  • 5. + Overview  Sesame  History  Overview  Repository API  Creating a Repository  Repository connections  Sesame Console  Sesame workbench
  • 6. + Overview and History  Open source Java for storage and querying RDF  By Aduna for the On-ToKnowledge EU project  RDF inference   RDF IO (all file formats) Now developed by Nlnet foundation, Ontotext and community volunteers  JDBC-like user API  Available at www.openrdf.org  RESTful HTTP interface  SPARQL Protocol support  Easy learning curve, great management features
  • 7. + Sesame components  RDF Model: contains all basic entities  Repository API: high level API with developer-methods  Rio: parsers and writers  HTTP Server: Java Servlets to access Sesame repos  Sail: low level API for RDF stores and inferencers (abstraction)  HTTPClient: Abstraction layer to access HTTP Servers
  • 9. + Repository API  Developer-focused API  In contrast with Jena, in Sesame RDF models are not handled by the user (normally), instead we use Repositories.  Vendors provide triple stores as Repository implementations  Sesame provides the following repository implementations:     Main memory Native RDF repository Remote repository (HTTP proxy) To use Sesame repositories, these must be stacked in Sails, i.e., stacks of layered behavior
  • 10. + Creating a repository  An in-memory repo Repository myRepository = new SailRepository(new MemoryStore()); myRepository.initialize();  An in-memory repo with persistance File dataDir = new File("c:tempmyRepository"); Repository myRepository = new SailRepository( new MemoryStore(dataDir) ); myRepository.initialize();
  • 11. + Creating a repository  a native RDF repository File dataDir = new File("/path/to/datadir/"); Repository myRepository = new SailRepository(new NativeStore(dataDir)); myRepository.initialize();  a native RDF repository with custom indexes File dataDir = new File("/path/to/datadir/"); String indexes = "spoc,posc,cosp"; Repository myRepository = new SailRepository(new NativeStore(dataDir, indexes)); myRepository.initialize();
  • 12. + Creating a repository  a remote Repository String sesameServer = "http://example.org/sesame2"; String repositoryID = "example-db"; Repository myRepository = new HTTPRepository(sesameServer, repositoryID); myRepository.initialize();
  • 13. + Using a repository: RepositoryConnection  JDBC like-interface  Operations  add triples by file, URI, Statement  query using SPARQL SELECT, ASK or Construct queries  create, retrieve, remove individual statements  prepared queries  Transaction support  commit(), rollback()
  • 14. + Adding to a repository File file = new File("/path/to/example.rdf"); String baseURI = "http://example.org/example/local"; try { RepositoryConnection con = myRepository.getConnection(); try { con.add(file, baseURI, RDFFormat.RDFXML); URL url = new URL("http://example.org/example/remote"); con.add(url, url.toString(), RDFFormat.RDFXML); } finally { con.close(); } } catch (…)
  • 15. + Querying a repository (tuple) RepositoryConnection con = myRepository.getConnection(); try { String queryString = “SELECT …. “; TupleQuery tupleQuery = con.prepareTupleQuery(SPARQL, queryString); TupleQueryResult result = tupleQuery.evaluate(); try { .... // do something with the result } finally { result.close(); } } finally { con.close(); }
  • 16. + Tuple queries (cont) while (result.hasNext()) { BindingSet bindingSet = result.next(); Value valueOfX = bindingSet.getValue("x"); Value valueOfY = bindingSet.getValue("y"); // do something interesting with the values here... } List<String> bindingNames = result.getBindingNames(); while (result.hasNext()) { BindingSet bindingSet = result.next(); Value firstValue = bindingSet.getValue(bindingNames.get(0)); Value secondValue = bindingSet.getValue(bindingNames.get(1)); // do something interesting with the values here... }
  • 17. + TupleQueryResultHandler FileOutputStream out = new FileOutputStream("/path/to/result.srx"); try { SPARQLResultsXMLWriter sparqlWriter = new SPARQLResultsXMLWriter(out); RepositoryConnection con = myRepository.getConnection(); try { String queryString = "SELECT * FROM {x} p {y}"; TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SERQL, queryString); tupleQuery.evaluate(sparqlWriter); } finally { con.close(); } } finally { out.close(); }
  • 18. + Evaluating Graph queries GraphQueryResult graphResult = con.prepareGraphQuery( QueryLanguage.SPARQL, "CONSTRUCT ….").evaluate(); while (graphResult.hasNext()) { Statement st = graphResult.next(); // ... do something with the resulting statement here. }
  • 19. + RDF Handler  Equivalent for TupleQueryResultHandler > RDFHandler  Examples: RDFXMLWriter, TurtleWriter, etc. TurtleWriter turtleWriter = new TurtleWriter(System.out); con.prepareGraphQuery(QueryLanguage.SPARQL, "CONSTRUCT …").evaluate(turtleWriter);
  • 20. + Adding individual statements ValueFactory f = myRepository.getValueFactory(); URI alice = f.createURI("http://example.org/people/alice"); URI bob = f.createURI("http://example.org/people/bob"); URI name = f.createURI("http://example.org/ontology/name"); URI person = f.createURI("http://example.org/ontology/Person"); Literal bobsName = f.createLiteral("Bob"); Literal alicesName = f.createLiteral("Alice"); RepositoryConnection con = myRepository.getConnection(); con.add(alice, RDF.TYPE, person); con.add(alice, name, alicesName); con.add(bob, RDF.TYPE, person); con.add(bob, name, bobsName);
  • 21. + Retrieving RepositoryResult<Statement> statements = con.getStatements(alice, null, null, true); try { while (statements.hasNext()) { Statement st = statements.next(); ... // do something with the statement } } finally { statements.close(); // make sure the result object is closed properly }
  • 22. + Deleting statements  a single statement con.remove(alice, name, alicesName);  many statements con.remove(alice, null, null);
  • 23. + Iterators and statements  Sesame’s API offer many calls compatible for iterators to facilitate “batch” manipulation // Retrieve all statements about Alice and put them in a list RepositoryResult<Statement> statements = con.getStatements(alice, null, null, true)); List<Statement> aboutAlice = Iterations.addAll(statements, new ArrayList<Statement>()); // Then, remove them from the repository con.remove(aboutAlice); con.remove(con.getStatements(alice, null, null, true));
  • 24. + Named graphs  Named graphs are natively supported by Sesame  Named graphs are called “Context” in Sesame String location = "http://example.org/example/example.rdf"; String baseURI = location; URL url = new URL(location); URI context = f.createURI(location); con.add(url, baseURI, RDFFormat.RDFXML, context);
  • 25. + Transactions  SQL-like transactions  Treat a “block” of operations as a single update  Failures can be “rolled back”
  • 26. + Transactions File inputFile1 = new File("/path/to/example1.rdf"); String baseURI1 = "http://example.org/example1/"; File inputFile2 = new File("/path/to/example2.rdf"); String baseURI2 = "http://example.org/example2/"; RepositoryConnection con = myRepository.getConnection(); try { con.setAutoCommit(false); con.add(inputFile1, baseURI1, RDFFormat.RDFXML); con.add(inputFile2, baseURI2, RDFFormat.RDFXML); con.commit(); } catch (RepositoryException e) { con.rollback(); } finally { con.close(); }
  • 28. + Sesame console  command-line application to interact with Sesame  Possible actions:  Easy way to create and manage repositories Create in the console, use from Java Creating repositories  Load/Unload data from Files/URIs/SPARQL Update    Query using SPARQL  Querying/Managing remote Sesame repositories > sh bin/console.sh Connected to default data directory Commands end with '.' at the end of a line Type 'help.' for help > help.
  • 29. +  Repository types memory,memory-rdfs a memory based RDF repository (optionaly with RDFS inference) Please specify values for the following variables: Repository ID [native]: myRepo Repository title [Native store]: My repository Triple indexes [spoc,posc]: Repository created  pgsql, mysql > show repositories. a repository that stores data in a > +---------PostgreSQL (mysql) database > |SYSTEM > |myRepo(”My repository")  remote -- a repository that serves as > +--------- native, native-rdfs a repository that uses on-disk data structure (optional RDFS inference) a proxy for a repository on a Sesame Server
  • 30. + Sesame Workbench Repository Manager and SPARQL end-points with Sesame
  • 31. + Sesame workbench  SPARQL Protocol implementation (sparqlendpoint) for Sesame repositories  Web based management console for Sesame repositories  Web based query interface for repositories.
  • 32. + Setup  Requires a JSP server, e.g., Tomcat or Jetty 8  Drop the 2 .war files from the /war folder of the sesame .zip into your webapps folder  Start the JSP server If you are using Jetty, do: jetty.sh/bat start in the command line