SPARQL By Example: The Cheat Sheet



Similar documents
A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX

13 RDFS and SPARQL. Internet Technology. MSc in Communication Sciences Program in Technologies for Human Communication.

SPARQL UniProt.RDF. Get these slides! Tutorial plan. Everyone has had some introduction slash knowledge of RDF.

RDF Resource Description Framework

Instant SQL Programming

RDF y SPARQL: Dos componentes básicos para la Web de datos

Semantic Interoperability

Towards the Integration of a Research Group Website into the Web of Data

Extending the Linked Data API with RDFa

Integrating Open Sources and Relational Data with SPARQL

HadoopSPARQL : A Hadoop-based Engine for Multiple SPARQL Query Answering

We have big data, but we need big knowledge

Microsoft' Excel & Access Integration

Benchmarking the Performance of Storage Systems that expose SPARQL Endpoints

12 The Semantic Web and RDF

OSLC Primer Learning the concepts of OSLC

Federated Data Management and Query Optimization for Linked Open Data

Taming Big Data Variety with Semantic Graph Databases. Evren Sirin CTO Complexible

Graph Database Performance: An Oracle Perspective

DISCOVERING RESUME INFORMATION USING LINKED DATA

Grids, Logs, and the Resource Description Framework

Business Intelligence Extensions for SPARQL

ELIS Multimedia Lab. Linked Open Data. Sam Coppens MMLab IBBT - UGent

Network Graph Databases, RDF, SPARQL, and SNA

SPARQL: Un Lenguaje de Consulta para la Web

Microsoft Access 3: Understanding and Creating Queries

LINKED DATA EXPERIENCE AT MACMILLAN Building discovery services for scientific and scholarly content on top of a semantic data model

excellent graph matching capabilities with global graph analytic operations, via an interface that researchers can use to plug in their own

Big Data, Fast Data, Complex Data. Jans Aasman Franz Inc

Semantic Modeling with RDF. DBTech ExtWorkshop on Database Modeling and Semantic Modeling Lili Aunimo

Oracle Database: SQL and PL/SQL Fundamentals

3.GETTING STARTED WITH ORACLE8i

Lecture 2: Storing and querying RDF data

Additional mechanisms for rewriting on-the-fly SPARQL queries proxy

Linked Statistical Data Analysis

Relational Database: Additional Operations on Relations; SQL

Fulvio Corno, Laura Farinetti. Dipartimento di Automatica e Informatica

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Template Guide. HTML . Release 8. This template guide is an overview of how to use and customize an HTML templates with Conga Composer.

Scalable and Reactive Programming for Semantic Web Developers

The presentation explains how to create and access the web services using the user interface. WebServices.ppt. Page 1 of 14

ABSTRACT 1. INTRODUCTION. Kamil Bajda-Pawlikowski

Oracle Database: SQL and PL/SQL Fundamentals NEW

CHAPTER 6 EXTRACTION OF METHOD SIGNATURES FROM UML CLASS DIAGRAM

A Review and Comparison of Rule Languages and Rule-based Inference Engines for the Semantic Web

Programming with SQL

Semantic Stored Procedures Programming Environment and performance analysis

RDF Support in Oracle Oracle USA Inc.

Open Data Integration Using SPARQL and SPIN

Querying Microsoft SQL Server (20461) H8N61S

ARC: appmosphere RDF Classes for PHP Developers

MOC 20461C: Querying Microsoft SQL Server. Course Overview

Getting Started with GRUFF

THE SEMANTIC WEB AND IT`S APPLICATIONS

Oracle SQL. Course Summary. Duration. Objectives

Ad Hoc Advanced Table of Contents

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

Programming the Semantic Web with Java. Taylor Cowan Travelocity 8982

LDIF - Linked Data Integration Framework

Cal Answers Analysis Training Part I. Creating Analyses in OBIEE

Lightweight Data Integration using the WebComposition Data Grid Service

Yet Another Triple Store Benchmark? Practical Experiences with Real-World Data

Ontological Modeling: Part 6

How To Create A Table In Sql (Ahem)

Towards a Semantic Wiki Wiki Web

Differences at a glance

Field Properties Quick Reference

Publishing Relational Databases as Linked Data

Lift your data hands on session

RDF Dataset Management Framework for Data.go.th

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

Oracle Database: SQL and PL/SQL Fundamentals

Common definitions and specifications for OMA REST interfaces

Using RDF Metadata To Enable Access Control on the Social Semantic Web

Qlik REST Connector Installation and User Guide

Transcription:

SPARQL By Example: The Cheat Sheet Accompanies slides at: http://www.cambridgesemantics.com/2008/09/sparql-by-example/ Comments & questions to: Lee Feigenbaum <lee@cambridgesemantics.com> VP Technology & Standards, Cambridge Semantics Co-chair, W3C SPARQL Working Group

Conventions Red text means: This is a core part of the SPARQL syntax or language. Blue text means: This is an example of query-specific text or values that might go into a SPARQL query.

URIs Nuts & Bolts Write full URIs: <http://this.is.a/full/uri/written#out> Literals a plain literal Plain literals: Abbreviate URIs with prefixes: PREFIX foo: <http://this.is.a/uri/prefix#> foo:bar http://this.is.a/uri/prefix#bar a rdf:type Shortcuts: bonjour @fr 13 ^^xsd:integer Plain literal with language tag: true true ^^xsd:boolean 3 3 ^^xsd:integer 4.2 4.2 ^^xsd:decimal Typed literal: Shortcuts: Variables?var1,?anotherVar,?and_one_more Variables: Comments Comments: # Comments start with a # # continue to the end of the line Triple Patterns ex:mywidget ex:partnumber XY24Z1.?person foaf:name Lee Feigenbaum. conf:semtech2009?property?value. Match an exact RDF triple: Match one variable: Match multiple variables:

Common Prefixes prefix... rdf: rdfs: owl: xsd: dc: foaf: stands for http://xmlns.com/foaf/0.1/ http://www.w3.org/2000/01/rdf-schema# http://www.w3.org/2002/07/owl# http://www.w3.org/2001/xmlschema# http://purl.org/dc/elements/1.1/ http://xmlns.com/foaf/0.1/ More common prefixes at http://prefix.cc

Declare prefix shortcuts (optional) Define the dataset (optional) Query modifiers (optional) Anatomy of a Query PREFIX foo: < > PREFIX bar: < > SELECT FROM < > FROM NAMED < > WHERE { GROUP BY HAVING ORDER BY LIMIT OFFSET BINDINGS Query result clause Query pattern

4 Types of SPARQL Queries SELECT queries Project out specific variables and expressions: SELECT?c?cap (1000 *?people AS?pop) SELECT * Project out all variables: Project out distinct combinations only: SELECT DISTINCT?country Results in a table of values (in XML or JSON):?c?cap?pop ex:france ex:paris 63,500,000 ex:canada ex:ottawa 32,900,000 ex:italy ex:rome 58,900,000 ASK queries ASK Ask whether or not there are any matches: Result is either true or false (in XML or JSON): true, false CONSTRUCT queries Construct RDF triples/graphs: CONSTRUCT {?country a ex:holidaydestination ; ex:arrive_at?capital ; ex:population?population. Results in RDF triples (in any RDF serialization): ex:france a ex:holidaydestination ; ex:arrive_at ex:paris ; ex:population 635000000. ex:canada a ex:holidaydestination ; ex:arrive_at ex:ottawa ; ex:population 329000000. DESCRIBE queries Describe the resources matched by the given variables: DESCRIBE?country Result is RDF triples (in any RDF serialization) : ex:france a geo:country ; ex:continent geo:europe ; ex:flag <http:// /flag-france.png> ;

Combining SPARQL Graph Patterns Consider A and B as graph patterns. A. B A Basic Graph Pattern one or more triple patterns Conjunction. Join together the results of solving A and B by matching the values of any variables in common. A OPTIONAL { B Optional Graph Patterns Left join. Join together the results of solving A and B by matching the values of any variables in common, if possible. Keep all solutions from A whether or not there s a matching solution in B

Combining SPARQL Graph Patterns Consider A and B as graph patterns. { A UNION { B Either-or Graph Patterns Disjunction. Include both the results of solving A and the results of solving B. A MINUS { B Subtracted Graph Patterns (SPARQL 1.1) Negation. Solve A. Solve B. Include only those results from solving A that are not compatible with any of the results from B.

SPARQL Subqueries (SPARQL 1.1) Consider A and B as graph patterns. A. { SELECT WHERE { B C. Join the results of the subquery with the results of solving A and C.

SPARQL Filters SPARQL FILTERs eliminate solutions that do not cause an expression to evaluate to true. Place FILTERs in a query inline within a basic graph pattern A. B. FILTER ( expr ) Category Functions / Operators Examples Logical!, &&,, =,!=, <, <=, >, >=?haspermit?age < 25 Math +, -, *, /?decimal * 10 >?minpercent Existence (SPARQL 1.1) EXISTS, NOT EXISTS NOT EXISTS {?p foaf:mbox?email SPARQL tests isuri, isblank, isliteral, bound isuri(?person)!bound(?person) Accessors str, lang, datatype lang(?title) = en Miscellaneous sameterm, langmatches, regex regex(?ssn, \\d{3-\\d{2-\\d{4 )

Aggregates (SPARQL 1.1) 1. Partition results into groups based on the expression(s) in the GROUP BY clause 2. Evaluate projections and aggregate functions in SELECT clause to get one result per group 3. Filter aggregated results via the HAVING clause?key?val?other1 1 4 1 4 2 5 2 4 2 10 2 2 2 1 3 3?key?sum_of_val 1 8 2 22 3 3?key?sum_of_val 1 8 3 3 SPARQL 1.1 includes: COUNT, SUM, AVG, MIN, MAX, SAMPLE, GROUP_CONCAT

Property Paths (SPARQL 1.1) Property paths allow triple patterns to match arbitrarylength paths through a graph Predicates are combined with regular-expression-like operators: Construct path1/path2 ^path1 path1 path2 path1* path1+ path1? path1{m,n path1{n path1{m, path1{,n Meaning Forwards path (path1 followed by path2) Backwards path (object to subject) Either path1 or path2 path1, repeated zero or more times path1, repeated one or more times path1, optionally At least m and no more than n occurrences of path1 Exactly n occurrences of path1 At least m occurrences of path1 At most n occurrences of path1

RDF Datasets A SPARQL queries a default graph (normally) and zero or more named graphs (when inside a GRAPH clause). Default graph (the merge of zero or more graphs) ex:g1 ex:g1 ex:g4 Named graphs ex:g2 ex:g3 OR OR PREFIX ex: < > SELECT FROM ex:g1 FROM ex:g4 FROM NAMED ex:g1 FROM NAMED ex:g2 FROM NAMED ex:g3 WHERE { A GRAPH ex:g3 { B GRAPH?g { C

SPARQL Over HTTP (the SPARQL Protocol) http://host.domain.com/sparql/endpoint?<parameters> where <parameters> can include: query=<encoded query string> e.g. SELECT+*%0DWHERE+{ default-graph-uri=<encoded graph URI> e.g. http%3a%2f%2fexmaple.com%2ffoo n.b. zero of more occurrences of default-graph-uri named-graph-uri=<encoded graph URI> e.g. http%3a%2f%2fexmaple.com%2fbar n.b. zero of more occurrences of named-graph-uri HTTP GET or POST. Graphs given in the protocol override graphs given in the query.

Federated Query (SPARQL 1.1) Local Graph Store SPARQL Endpoint ex:s1 SPARQL Endpoint ex:s2 ex:g1 Web PREFIX ex: < > SELECT FROM ex:g1 WHERE { A SERVICE ex:s1 { B SERVICE ex:s2 { C

SPARQL 1.1 Update SPARQL Update Language Statements INSERT DATA { triples DELETE DATA {triples [ DELETE { template ] [ INSERT { template ] WHERE { pattern LOAD <uri> [ INTO GRAPH <uri> ] CLEAR GRAPH <uri> CREATAE GRAPH <uri> DROP GRAPH <uri> [ ] denotes optional parts of SPARQL 1.1 Update syntax

Some Public SPARQL Endpoints Name URL What s there? SPARQLer DBPedia DBLP LinkedMDB World Factbook bio2rdf http://sparql.org/sparql.html http://dbpedia.org/sparql http://www4.wiwiss.fu-berlin.de/dblp/snorql/ http://data.linkedmdb.org/sparql http://www4.wiwiss.fuberlin.de/factbook/snorql/ http://bio2rdf.org/sparql General-purpose query endpoint for Web-accessible data Extensive RDF data from Wikipedia Bibliographic data from computer science journals and conferences Films, actors, directors, writers, producers, etc. Country statistics from the CIA World Factbook Bioinformatics data from around 40 public databases

SPARQL Resources The SPARQL Specification http://www.w3.org/tr/rdf-sparql-query/ SPARQL implementations http://esw.w3.org/topic/sparqlimplementations SPARQL endpoints http://esw.w3.org/topic/sparqlendpoints SPARQL Frequently Asked Questions http://www.thefigtrees.net/lee/sw/sparql-faq SPARQL Working Group http://www.w3.org/2009/sparql/wiki/ Common SPARQL extensions http://esw.w3.org/topic/sparql/extensions