Jena Sparql (for Mac) 9/22/2018.

Slides:



Advertisements
Similar presentations
Internet Technologies 1 Master of Information System Management Internet Technologies Lecture 7: SPARQL.
Advertisements

SPARQL- A QUERY LANGUAGE FOR RDF( S ) Fred Freitas - CIn/UFPE - Brazil.
인터넷기술 강혜원 Java 를 이용한 RDF Process 인터넷기술 012ITI01 강혜원.
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.
 Copyright 2004 Digital Enterprise Research Institute. All rights reserved. SPARQL Query Language for RDF presented by Cristina Feier.
SPARQL RDF Query.
JAVA BASICS. Why Java for this Project? Its open source - FREE Java has tools that work well with rdf and xml –Jena, Jdom, Saxon Can be run on UNIX,Windows,LINUX,etc.
PACKAGES. PACKAGES IN JAVA A package is a collection of related classes and interfaces in Java Packages help in logical grouping of classes and interfaces.
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,
Ontology Views Update Marianne Shaw 03/04/2008. Overview Sub and recursive queries on DB model  ds-config.ttl  Demo: Liver part TC Skolem Functions.
Jena 4/17/2017.
Eclipse for Jena & ARQ. File needed Jena ( ARQ-2.2 (
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.
Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction.
© 2006 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice Publishing data on the Web (with.
1 Semantic query, rules, tools (Inference, triple stores, etc) Peter Fox (RPI) ESIP Winter Meeting Washington D.C., 2009, Jan 6, 4-5:30pm.
1 Ontology Query and Reasoning Payam Barnaghi Institute for Communication Systems (ICS) Faculty of Engineering and Physical Sciences University of Surrey.
SPARQL All slides are adapted from the W3C Recommendation SPARQL Query Language for RDF Web link:
Master Informatique 1 Semantic Technologies Part 5SPARQL Werner Nutt.
Example: Jena and Fuseki
Introduction to SPARQL. Acknowledgements This presentation is based on the W3C Candidate Recommendation “SPARQL Query Language for RDF” from
Entity Recognition via Querying DBpedia ElShaimaa Ali.
SPARQL Semantic Web - Spring 2008 Computer Engineering Department Sharif University of Technology.
Chapter 3 Querying RDF stores with SPARQL. Why an RDF Query Language? Why not use an XML query language? XML at a lower level of abstraction than RDF.
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Querying on the Web: XQuery, RDQL, SparQL Semantic Web.
The Jena RDF Framework Konstantinos Tzonas. Contents What is Jena Capabilities of Jena Basic notions RDF concepts in Jena Persistence Ontology management.
Ontology Query. What is an Ontology Ontologies resemble faceted taxonomies but use richer semantic relationships among terms and attributes, as well as.
SPARQL AN RDF Query Language. SPARQL SPARQL is a recursive acronym for SPARQL Protocol And Rdf Query Language SPARQL is the SQL for RDF Example: PREFIX.
SPARQL All slides are adapted from the W3C Recommendation SPARQL Query Language for RDF Web link:
Logics for Data and Knowledge Representation SPARQL -- Exercises Feroz Farazi.
SPARQL Query Graph Model (How to improve query evaluation?) Ralf Heese and Olaf Hartig Humboldt-Universität zu Berlin.
1 SPARQL A. Emrah Sanön. 2 RDF RDF is quite committed to Semantic Web. Data model Serialization by means of XML Formal semantics Still something is missing!
Semantic Web Basics Dominic DiFranzo PhD Student/Research Assistant Rensselaer Polytechnic Institute Tetherless World Constellation.
© Copyright 2008 STI INNSBRUCK Semantic Web Repositories and SPARQL Dieter Fensel Federico Facca.
SPARQL In-Class Shared Exercise. Pop Quiz If you have a large knowledge store, why should you not issue: SELECT ?s ?p ?o WHERE { ?s ?p ?o } Ans: It returns.
Practical RDF Chapter 10. Querying RDF: RDF as Data Shelley Powers, O’Reilly SNU IDB Lab. Hyewon Lim.
Practical RDF Ch.10 Querying RDF: RDF as Data Taewhi Lee SNU OOPSLA Lab. Shelley Powers, O’Reilly August 27, 2004.
05/01/2016 SPARQL SPARQL Protocol and RDF Query Language S. Garlatti.
Alexandra Cristea 1.  pronounced "sparkle“  recursive acronym for: ◦ SPARQL Protocol and RDF Query Language  a semantic query language  a query language.
CC L A W EB DE D ATOS P RIMAVERA 2015 Lecture 7: SPARQL (1.0) Aidan Hogan
Internet Technologies 1 Master of Information System Management Internet Technologies Making Queries on RDF.
Lecture 8: RDF& SPARQL Dr. Taysir Hassan A. Soliman December 13, 2015 INF411 Information Engineering Information Systems Dept. Faculty of Computers & Information.
Semantic Web in Depth SPARQL Protocol and RDF Query Language Dr Nicholas Gibbins –
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
1 Knowledge Representation XI – IKT437 Knowledge Representation XI – IKT437 Part I RDF Jan Pettersen Nytun, UiA Apache Jena.
Vincenzo Maltese, Fausto Giunchiglia University of Trento
CC La Web de Datos Primavera 2017 Lecture 7: SPARQL [i]
Storage and Querying Anna Fensel
SPARQL.
Jena 6/8/2018.
Introduction to SPARQL
SPARQL ดร.มารุต บูรณรัช
Resource Description Framework
SPARQL SPARQL Protocol and RDF Query Language
Introduction to Exceptions in Java
SPARQL: A query language for RDF
SPARQL Exercise Much of this exercise has been copied from: INF3580/INF4580 – MANDATORY EXERCISE 3
Miguel Azurin, Andrew Engroff, Ahmad Sadiq
Topics Introduction to File Input and Output
CC La Web de Datos Primavera 2016 Lecture 7: SPARQL (1.0)
SPARQL Exercise Most of this exercise has been copied from: INF3580/INF4580 – MANDATORY EXERCISE 3
The Jena RDF Framework Konstantinos Tzonas.
Logics for Data and Knowledge Representation
Example: Jena and Fuseki
Triple Stores.
Topics Introduction to File Input and Output
Presentation transcript:

Jena Sparql (for Mac) 9/22/2018

Jena SPARQL SPARQL queries RDF graphs (a set of triples): RDF graphs – models (in Jena) RDF triples – statements (in Jena) It is the triples that SPARQL cares, not the serialization. The serialization is just a way to write the triples down Here we use Turtle 9/22/2018

vc-db-1.rdf in Turtle @prefix vCard: <http://www.w3.org/2001/vcard-rdf/3.0#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . <http://somewhere/MattJones/> vCard:FN "Matt Jones" . <http://somewhere/MattJones/> vCard:N _:b0 . _:b0 vCard:Family "Jones" . _:b0 vCard:Given "Matthew" . <http://somewhere/RebeccaSmith/> vCard:FN "Becky Smith" . <http://somewhere/RebeccaSmith/> vCard:N _:b1 . _:b1 vCard:Family "Smith" . _:b1 vCard:Given "Rebecca" . <http://somewhere/JohnSmith/> vCard:FN "John Smith" . <http://somewhere/JohnSmith/> vCard:N _:b2 . _:b2 vCard:Family "Smith" . _:b2 vCard:Given "John" . <http://somewhere/SarahJones/> vCard:FN "Sarah Jones" . <http://somewhere/SarahJones/> vCard:N _:b3 . _:b3 vCard:Family "Jones" . _:b3 vCard:Given "Sarah" . 9/22/2018

ARQ ARQ is a query engine for Jena that supports the SPARQL RDF Query language. ARQ Features: Multiple query languages SPARQL (.rq – file extension) RDQL (.rdql) ARQ, the engine’s own language (.arq) Multiple query engines General purpose engine Remote access engines Rewriter to SQL 9/22/2018

Install ARQ Set ARQROOT export ARQROOT=“/Users/username/somewhere/Jena/ARQ-2.2/ARQ-2.2” Replace username with your own username; replace somewhere with the file path where you save Jena folder (Jena folder is saved in Desktop in this screenshot) 9/22/2018

Query 1 SPARQL file: “~/Desktop/Jena/ARQ-2.2/ARQ-2.2/bin/sparql” Data file: “~/Desktop/Jena/Tutorial/vc-db-1.rdf” Query file: “~/Desktop/Jena/Tutorial/arq/q1.rq” Execute query q1.rq ARQ-2.2/ARQ-2.2/bin/sparql --data=Tutorial/vc-db-1.rdf --query=Tutorial/arq/q1.rq The working directory in all the examples is “~/Desktop/Jena”. If you are not in the same directory, you have to modify the path of the SPARQL file, the data file, and the query file. SELECT ?x WHERE { ?x <http://www.w3.org/2001/vcard-rdf/3.0#FN> "John Smith" } 9/22/2018

Query 2 Data file: “~/Desktop/Jena/Tutorial/vc-db-1.rdf” Query file: “~/Desktop/Jena/Tutorial/arq/q2.rq” PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> SELECT ?y ?givenName WHERE { ?y vcard:Family "Smith" . ?y vcard:Given ?givenName . } 9/22/2018

Query 3 - Filter Data file: “~/Desktop/Jena/Tutorial/vc-db-1.rdf” Query file: “~/Desktop/Jena/Tutorial/arq/q3.rq” PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> SELECT ?g WHERE { ?y vcard:Given ?g . FILTER regex(?g, "r", "i") } 9/22/2018

Query 4 - OPTIONAL Data file: “~/Desktop/Jena/Tutorial/vc-db-2.rdf” Query file: “~/Desktop/Jena/Tutorial/arq/q4.rq” PREFIX info: <http://somewhere/peopleInfo#> PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> SELECT ?name ?age WHERE { ?person vcard:FN ?name . OPTIONAL { ?person info:age ?age } } 9/22/2018

Query 5 Data file: “~/Desktop/Jena/Tutorial/vc-db-2.rdf” Query file: “~/Desktop/Jena/Tutorial/arq/q5.rq” PREFIX info: <http://somewhere/peopleInfo#> PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> SELECT ?name ?age WHERE { ?person vcard:FN ?name . ?person info:age ?age . } 9/22/2018

Query 6 – Optional and Filter Data file: “~/Desktop/Jena/Tutorial/vc-db-2.rdf” Query file: “~/Desktop/Jena/Tutorial/arq/q6.rq” PREFIX info: <http://somewhere/peopleInfo#> PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> SELECT ?name ?age WHERE { ?person vcard:FN ?name . OPTIONAL { ?person info:age ?age . FILTER ( ?age > “24” ) } } 9/22/2018

Query 7 - Union Data: ~/Desktop/Jena/Tutorial/name.rdf @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> . _:a foaf:name "Matt Jones" . _:b foaf:name "Sarah Jones" . _:c vcard:FN "Becky Smith" . _:d vcard:FN "John Smith" . 9/22/2018

Query 7 – Union Data file: “~/Desktop/Jena/Tutorial/name.rdf” Query file: “~/Desktop/Jena/Tutorial/arq/q7.rq” PREFIX info: <http://somewhere/peopleInfo#> PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> SELECT ?name ?age WHERE { ?person vcard:FN ?name . OPTIONAL { ?person info:age ?age . FILTER ( ?age > “24” ) } } 9/22/2018

Query 8 – Named Graphs Default graph: ds-dft.ttl @prefix dc: <http://purl.org/dc/elements/1.1/> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . <ds-ng-1.ttl> dc:date "2005-07-14T03:18:56+0100"^^xsd:dateTime . <ds-ng-2.ttl> dc:date "2005-09-22T05:53:05+0100"^^xsd:dateTime . Default graph: ds-dft.ttl Named graph: ds-ng-1.ttl @prefix dc: <http://purl.org/dc/elements/1.1/> . [] dc:title "Harry Potter and the Philospher's Stone" . [] dc:title "Harry Potter and the Chamber of Secrets" . Named graph: ds-ng-2.ttl @prefix dc: <http://purl.org/dc/elements/1.1/> . [] dc:title "Harry Potter and the Sorcerer's Stone" . [] dc:title "Harry Potter and the Chamber of Secrets" . 9/22/2018

Query 8 – Named Graphs Data file: ~/Desktop/Jena/Tutorial Query file: ~/Desktop/Jena/Tutorial/arq/q8.rq PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX : <.> SELECT ?title ?graph FROM <ds-dft.ttl> FROM NAMED <ds-ng-1.ttl> FROM NAMED <ds-ng-2.ttl> WHERE { GRAPH ?graph { ?x dc:title ?title . } } 9/22/2018

Query 8 – Named Graphs 9/22/2018

Executing SPARQL queries via Jena API SPARQL queries are created and executed with Jena via classes in the com.hp.hpl.jena.query package. Using QueryFactory is the simplest approach. Create() methods are used to read a textual query from a file or from a String. Create() returns a query object with a parsed query Create an instance of QueryExecution to perform a different type of query Call QueryExecutionFactory.create(query, model) Because the data for the query is provided programmatically, the query does not need a FROM clause. ResultSet allows you to iterate over QuerySolution providing access to each bound variable’s value. 9/22/2018

Bloggers.rdf 9/22/2018

Query bloggers Data file: ~/Desktop/Jena/Tutorial/arq/bloggers.rdf Query file: ~/Desktop/Jena/Tutorial/arq/bloggers1.rq PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?url FROM <bloggers.rdf> WHERE { ?contributor foaf:name "Jon Foobar" . ?contributor foaf:weblog ?url . } 9/22/2018

Bloggers.java import com.hp.hpl.jena.rdf.model.*; import com.hp.hpl.jena.util.FileManager; import com.hp.hpl.jena.query.* ; import com.hp.hpl.jena.query.ARQ; import com.hp.hpl.jena.sparql.*; import java.io.*; public class Bloggers extends Object { static final String inputFileName = "bloggers.rdf"; public static void main (String args[]) { // Create an empty in-memory model Model model = ModelFactory.createDefaultModel(); // use the FileManager to open the bloggers RDF graph from the filesystem InputStream in = FileManager.get().open(inputFileName); if (in == null) { throw new IllegalArgumentException( "File: " + inputFileName + " not found"); } // read the RDF/XML file model.read( in, "" ); Bloggers.java 9/22/2018

Bloggers.java // Create a new query String queryString = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " + "SELECT ?url " + "WHERE {" + " ?contributor foaf:name \"Jon Foobar\" . " + " ?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); // Important - free up resources used running the query qe.close(); } Bloggers.java 9/22/2018

Executing SPARQL queries via Jena API Set up CLASSPATH for Jena API CLASSPATH=“.:/Users/usersname/somewhere/Jena/Jena-2.5.5/lib/*” export CLASSPATH Replace username with your own username; replace somewhere with the file path where you save Jena folder (Jena folder is saved in Desktop in this screenshot) 9/22/2018

Executing SPARQL queries via Jena API Store bloggers.java in ~\Desktop\Jena\Tutorial\arq Compile Run The working directory in this examples is “~/Desktop/Jena/Tutorial/arq”. If you are not in the same directory, you have to modify the file path. 9/22/2018

Executing SPARQL queries via Jena API PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?url FROM <bloggers.rdf> WHERE { ?x foaf:name ?name . ?x foaf:weblog ?url . } Bloggers1.java Store bloggers1.java in ~/Desktop/Jena/Tutorial/arq Compile and run 9/22/2018

Summary Practicing and mastering all the Jena Sparql tutorials on your own. Be able to create similar tutorials using your own examples. 9/22/2018