SPARQL ME-E4300 Semantic Web,

Similar documents
MI-PDB, MIE-PDB: Advanced Database Systems

Semantic Web Information Management

Querying the Semantic Web

Semantic Web ME-E4300 Semantic Web,

SPARQL. Dr Nicholas Gibbins

Querying RDF & RDFS. Several query languages exist to retrieve

RDF AND SPARQL. Part IV: Syntax of SPARQL. Dresden, August Sebastian Rudolph ICCL Summer School

INFO216: Advanced Modelling

SPARQL QUERY LANGUAGE WEB:

SPARQL By Example: The Cheat Sheet

Semantic Web. CS-E4410 Semantic Web, Eero Hyvönen Aalto University, Semantic Computing Research Group (SeCo)

3. Queries Applied Artificial Intelligence Prof. Dr. Bernhard Humm Faculty of Computer Science Hochschule Darmstadt University of Applied Sciences

Chapter 3 Querying RDF stores with SPARQL

Day 2. RISIS Linked Data Course

KNOWLEDGE GRAPHS. Lecture 3: Modelling in RDF/Introduction to SPARQL. TU Dresden, 30th Oct Markus Krötzsch Knowledge-Based Systems

Lars Schmidt-Thieme, Information Systems and Machine Learning Lab (ISMLL), University of Hildesheim, Germany, Course on XML and Semantic Web

Semantic Web Technologies: Assignment 1. Axel Polleres Siemens AG Österreich

Linked Open Data Infrastructure for Digital Humanities in Finland

RDF AND SPARQL. Part V: Semantics of SPARQL. Dresden, August Sebastian Rudolph ICCL Summer School

SPAR-QL. Mario Arrigoni Neri

XML and Semantic Web Technologies. III. Semantic Web / 3. SPARQL Query Language for RDF

Web NDL Authorities SPARQL API Specication

SEMANTIC WEB 03 RDF DATA MODEL RESOURCE DESCRIPTION FRAMEWORK IMRAN IHSAN ASSISTANT PROFESSOR, AIR UNIVERSITY, ISLAMABAD

Semantic Web Technologies

SPARQL. Fausto Giunchiglia and Mattia Fumagallli. University of Trento

KNOWLEDGE GRAPHS. Lecture 4: Introduction to SPARQL. TU Dresden, 6th Nov Markus Krötzsch Knowledge-Based Systems

SPARQL: An RDF Query Language

Filter: Evaluable Expression. List Syntax. Tests. Filter: Evaluable Expression. Tests : functions. Tests 06/09/2013. (1?x v )

infoh509 xml & web technologies lecture 9: sparql Stijn Vansummeren February 14, 2017

SPARQL Protocol And RDF Query Language

KNOWLEDGE GRAPHS. Lecture 2: Encoding Graphs with RDF. TU Dresden, 23th Oct Markus Krötzsch Knowledge-Based Systems

CS Knowledge Representation and Reasoning (for the Semantic Web)

Introduction to a Web of Linked Data

FOUNDATIONS OF SEMANTIC WEB TECHNOLOGIES

From the Web to the Semantic Web: RDF and RDF Schema

B4M36DS2, BE4M36DS2: Database Systems 2

RESOURCES DESCRIPTION FRAMEWORK: RDF

Multi-agent and Semantic Web Systems: RDF Data Structures

JSON-LD and MongoDB. Gregg Kellogg. Powering Linked Web Monday, August 20, 12

SAHA Metadata Management System Technical Report

Implementing and extending SPARQL queries over DLVHEX

Introduction to RDF and the Semantic Web for the life sciences

Representing Linked Data as Virtual File Systems

WWW today ME-E4300 Semantic Web,

Introduction to Semantic Web Databases. Version 1 Prepared By: Amgad Madkour Ph.D. Candidate Purdue University April 2018

Interacting with Linked Data Part I: General Introduction

Querying Semantic Web Data

Using SPARQL with RDFS and OWL Entailment

Jena.

SPARQL (RDF Query Language)

Today s Plan. INF3580/4580 Semantic Technologies Spring Reminder: RDF triples. Outline. Lecture 4: The SPARQL Query Language.

Knowledge Representation for the Semantic Web

What's New in RDF 1.1

Building Blocks of Linked Data

Semantic Web meets biology: Finnish experiences in modelling, managing, and using biological linked data

Enabling Semantic Web Programming by Integrating RDF and Common Lisp

Multi-agent and Semantic Web Systems: Querying

Today s Plan. 1 Repetition: RDF. 2 Jena: Basic Datastructures. 3 Jena: Inspecting Models. 4 Jena: I/O. 5 Example. 6 Jena: ModelFactory and ModelMaker

Select all persons who belong to the class Father. SPARQL query PREFIX g: <

Mapping Relational Data to RDF with Virtuoso's RDF Views

KNOWLEDGE GRAPHS. Lecture 11: Cypher / Knowledge Graph Quality. TU Dresden, 8th Jan Markus Krötzsch Knowledge-Based Systems

Today s Plan. 1 Repetition: RDF. 2 Jena: Basic Datastructures. 3 Jena: Inspecting Models. 4 Jena: I/O. 5 Example. 6 Jena: ModelFactory and ModelMaker

Profiles Research Networking Software API Guide

Linking Data with RDF

Semantic Days 2011 Tutorial Semantic Web Technologies

Orchestrating Music Queries via the Semantic Web

COMPUTER AND INFORMATION SCIENCE JENA DB. Group Abhishek Kumar Harshvardhan Singh Abhisek Mohanty Suhas Tumkur Chandrashekhara

RDF AND SPARQL. Part I: Basics of RDF. Dresden, August Sebastian Rudolph ICCL Summer School

BASI DI DATI II 2 modulo Parte VIII: SPARQL

Transforming Data from into DataPile RDF Structure into RDF

Semantic Technologies and CDISC Standards. Frederik Malfait, Information Architect, IMOS Consulting Scott Bahlavooni, Independent

Using Linked Data Concepts to Blend and Analyze Geospatial and Statistical Data Creating a Semantic Data Platform

BUILDING THE SEMANTIC WEB

A short tutorial on rrdf

Semantic Web Systems Sample Solution for Assignment 2 part 1. SPARQL Queries

Semantic Web Technologies: Theory & Practice. Axel Polleres Siemens AG Österreich

Optimising a Semantic IoT Data Hub

SEMANTIC WEB 07 SPARQL TUTORIAL BY EXAMPLE: DBPEDIA IMRAN IHSAN ASSISTANT PROFESSOR, AIR UNIVERSITY, ISLAMABAD

Today s Plan. INF3580 Semantic Technologies Spring Outline. Oblig 4. Lecture 13: More SPARQL. Kjetil Kjernsmo.

Semantics. Matthew J. Graham CACR. Methods of Computational Science Caltech, 2011 May 10. matthew graham

Web 2.0 Lecture 8: Resource Description Framework

Querying Data with Transact SQL

Contents. G52IWS: The Semantic Web. The Semantic Web. Semantic web elements. Semantic Web technologies. Semantic Web Services

Linked data and its role in the semantic web. Dave Reynolds, Epimorphics

a paradigm for the Semantic Web RDF Data Model Angelica Lo Duca IIT-CNR Linked Open Data:

Energy-related data integration using Semantic data models for energy efficient retrofitting projects

Knowledge Representation VII - IKT507. SPARQL stands for SPARQL Protocol And RDF Query Language

Semantic Web. MPRI : Web Data Management. Antoine Amarilli Friday, January 11th 1/29

Semantic Web Systems Querying Jacques Fleuriot School of Informatics

API Documentation. Web Application Development. Zsolt Tóth. University of Miskolc. Zsolt Tóth (University of Miskolc) API Documentation / 28

Is Linked Data the future of data integration in the enterprise?

Shape Constraint Language

FOUNDATIONS OF DATABASES AND QUERY LANGUAGES

SPARQL. A Query-language for the Web of Data

Web Ontology Editor: architecture and applications

Semantic Web Fundamentals

Flat triples approach to RDF graphs in JSON

SPARQL UniProt.RDF. Everyone has had some introduction slash knowledge of RDF.

Publishing Statistical Data and Geospatial Data as Linked Data Creating a Semantic Data Platform

Semantic Web and Python Concepts to Application development

Transcription:

SPARQL ME-E4300 Semantic Web, 27.1.2016 Jouni Tuominen Semantic Computing Research Group (SeCo), http://seco.cs.aalto.fi jouni.tuominen@aalto.fi

SPARQL SPARQL Protocol and RDF Query Language sparkle 2

SPARQL basics Query language for RDF and data management W3C recommendation - SPARQL 1.0 recommendation 15.1.2008 - SPARQL 1.1 recommendation 21.3.2013 Based on Turtle notation s triple patterns, which are matched against the RDF data graph 3

Example query PREFIX ns: <http://www.domain.com/namespace/> SELECT?person?name WHERE { }?person ns:type ns:person.?person ns:name?name person type H1 Akseli Gallen-Kallela name occupation artist birth place Lemu type?person H1 H2?name Akseli Gallen-Kallela Gustav Mannerheim name Gustaf Mannerheim H2 occupation marshal birth place Askainen 4

Basic query form: SELECT SELECT List of the wanted result variables FROM The graph the query is restricted to Optional WHERE Condition expressions as a graph pattern with variables; most restricting conditions first Variables Marked by the use of either? or $ character Prefixes Eases the writing of queries - http://www.domain.com/namespace/property ns:property 5

Writing queries Turtle notation with variables Can query for: - Subject?person rdf:type ns:person - Predicate ns:person23?predicate ns:helsinki - Object ns:person45 ns:age?age 6

Example PREFIX ns: <http://www.domain.com/namespace/> SELECT?person?name WHERE { }?person rdf:type ns:person.?person ns:name?name -------------------------------- person name ================================= <ns:person5> Matti <ns:person2> Teppo <ns:person13> Liisa -------------------------------- 7

Matching Literals @prefix dt: <http://example.org/datatype#>. @prefix ns: <http://example.org/ns#>. @prefix : <http://example.org/ns#>. @prefix xsd: <http://www.w3.org/2001/xmlschema#>. :x ns:p "cat"@en. :y ns:p "42"^^xsd:integer. :z ns:p "abc"^^dt:specialdatatype. Language Tags - SELECT?v WHERE {?v?p "cat" } Empty result - SELECT?v WHERE {?v?p "cat"@en } :x Numbers - SELECT?v WHERE {?v?p 42 } :y Datatypes - SELECT?v WHERE {?v?p "abc"^^dt:specialdatatype } -> :z (Example from SPARQL 1.1. W3C Specification) 8

Creating new values with expressions: CONCAT, BIND (Example from SPARQL 1.1. W3C Specification) 9

Restricting Solutions: FILTER Type conversions (cast) for strings and numbers E.g., str( ), xsd:decimal( ) Literals can be filtered using regular expressions Regex() Numeric values can be compared <, >,!=, = Other datatypes: xsd:boolean, xsd:datetime?person ns:age?age. FILTER(xsd:integer(?age) > 18)?object rdf:type?type. FILTER(?type!= ns:car)?book ns:title?title. FILTER regex(str(?title), work, i ) i = case-insensitive 10

Combining alternatives: UNION Alternative results (into same variable) {?person ns:nationality ns:finnish} UNION {?person ns:nationality ns:swedish} UNION {?person ns:name John }?person 11

OPTIONAL Optional information, which is included in the result set, if the information exists?person rdf:type ns:person.?person ns:name?name. OPTIONAL {?person ns:age?age} -------------------------------- name age ================================= Matti Teppo 34 Liisa 52 -------------------------------- 12

Representing the SELECT query result set: XML format (Example from SPARQL 1.1. W3C Specification) Other formats: JSON, CSV, TSV 13

Solution sequence (result set) modifiers DISTINCT Removes duplicate results ORDER BY Defines the order of the result set DESC() ASC() LIMIT Limits the number of results returned OFFSET Defines the result set to start after the specified number of results 14

Example PREFIX ns: <http://www.domain.com/namespace/> PREFIX xsd: <http://www.w3.org/2001/xmlschema#> SELECT?field?length?width WHERE {?field rdf:type ns:field ; ns:length?length ; ns:width?width. } ORDER BY ASC(xsd:decimal(?length) * xsd:decimal(?width)) Results are ordered by their area in an ascending order 15

Example PREFIX ns: <http://www.domain.com/namespace/> SELECT DISTINCT?person?name?age WHERE { {?person ns:gender ns:female ; ns:nationality ns:finnish ; ns:name?name. } OPTIONAL {?person ns:age?age. FILTER(xsd:integer(?age) > 30) } UNION {?person ns:gender ns:male ; ns:nationality ns:swedish ; ns:name?name. OPTIONAL {?person ns:age?age. FILTER(xsd:integer(?age) < 30) } }} ORDER BY?name LIMIT 7 16

Example result set ----------------------------------------------------- person name age ====================================================== <ns:person86> Daniel 28 <ns:person145> Håkan <ns:person23> Jaana 34 <ns:person125> Lars <ns:person231> Marjatta 42 <ns:person48> Mikael 23 <ns:person6> Tiina ----------------------------------------------------- 17

SPARQL query (+basic update) forms SELECT - Presented on previous slides CONSTRUCT - Returns an RDF graph specified by a graph template ASK - Test if a query pattern has solutions without returning the result set (boolean) DESCRIBE - Returns RDF descriptions of the resources found INSERT adds new triples into an RDF graph DELETE removes triples from an RDF graph 18

Building RDF graphs: CONSTRUCT (Example from SPARQL 1.1. W3C Specification) 19

Many other SPARQL 1.1 features available Path expressions Aggregating values over solution sets Federated queries - Using multiple SPARQL endpoints Subqueries Dealing with multiple graphs in datasets (Examples from SPARQL 1.1. W3C Specification) 20

More information W3C SPARQL recommendation family 21

Try SPARQL in various SPARQL endpoints: you can type in queries in forms For a list see http://www.w3.org/wiki/sparqlendpoints Linked Data Finland http://ldf.fi Each dataset has a form for SPARQLing Linked Open Aalto http://data.aalto.fi Recommended query interface: YASGUI http://yasgui.org Syntax highlighting; prefix, property, and class autocompletion 22

BookSampo SPARQL endpoint in LDF.fi: http://www.ldf.fi/dataset/kirjasampo 23

Getting a Resource Description 24

SPARQL result in JSON 25

Same result output as a table 26

Using a SPARQL endpoint programmatically HTTP API using the endpoint URL, e.g., http://dbpedia.org/sparql Query and other parameters as GET/POST parameters - Use URL encoding 27

Example using Firefox / Firebug 28

http://dbpedia.org/sparql?default-graphuri=http%3a%2f%2fdbpedia.org&query=describe+%3chttp%3a%2f%2fdbpedia.org%2fresource%2fthe_unknown_soldier_%281955_film%29%3e&form at=text%2fx-html-nice-turtle&cxml_redir_for_subjs=121&cxml_redir_for_hrefs=&timeout=30000&debug=on 29

Examples in course assignments Client side: JavaScript (Assignment 2) Server side: Python/Scala (Assignment 3) (changes possible) 30

What s next on this course? Lectures on Wednesdays at 10.15-12.00 in lecture hall 2534-2535 (TUAS) Assignment support sessions on Thursdays at 10.15-12.00 in computer class 1521-1522 (TUAS) 04.02. DL for Assignment 1 03.03. DL for Assignment 2 24.03. DL for Assignment 3 31