DOC PREVIEW
UTD CS 6375 - SPARQL - Part 1

This preview shows page 1-2-16-17-18-33-34 out of 34 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

SPARQL Part 1 All slides are adapted from the W3C Recommendation SPARQL Query Language for RDF Web link http www w3 org TR rdf sparql query Overview SPARQL RDF is a directed labeled graph representation of the information on the Web SPARQL expresses queries across multiple and highly heterogeneous data sources that contain RDF SPARQL is used for querying the graphs for patterns SPARQL SPARQL also supports extensible value testing and constraining queries by source RDF graph SPARQL results are result sets or RDF graphs 1 Introduction Introduction RDF is a data representation language for the information on the Web RDF is used to represent diverse information such as social networks information about people etc Another feature of RDF is that it can be used to merge these islands of diverse data SPARQL is a language designed to query RDF Introduction SPARQL is designed to meet the requirements identified by the RDF Data Access Working Group SPARQL also relates to SPARQL Protocol for RDF SPROT remote protocol for issuing SPARQL queries and receiving results SPARQL Query Results XML Format RESULTS defines an XML format for representing results of SPARQL SELECT and ASK queries Conventions Namespaces Prefix IRI rdf http www w3 org 1999 02 22 rdf syntax ns rdfs http www w3 org 2000 01 rdf schema xsd http www w3 org 2001 XMLSchema fn http www w3 org 2005 xpath functions Conventions Data Description We use the TURTLE format for triples this allows the use of prefixes in IRI s prefix dc http purl org dc elements 1 1 prefix http example org book book1 dc title SPARQL Tutorial Conventions Result Descriptions All results are represented in tabular form x y Alice http example a z We define the use of a binding which is an association between a variable and the RDF term In the example above the variable x is bound to the RDF term Alice the variable y is bound to the RDF http example a and the variable z is not bound to any RDF term Conventions Terminology used IRI s Internationalized Resource Identifier Literals Lexical form Plain literal Language tag Typed Literal Datatype IRI Blank node 2 Writing Simple Queries Writing Simple Queries The most basic form of a SPARQL query is the basic graph pattern which is nothing but a set of triples where each of the subject predicate or object may be a variable We find a match of the basic graph pattern in the given subgraph when RDF terms in a subgraph match the variables in the query resulting in a RDF graph that matches the given subgraph Writing Simple Queries A simple example Data one triple http example org book book1 http purl org dc elements 1 1 title SPARQL Tutorial Query SELECT title WHERE http example org book book1 http purl org dc elements 1 1 title title Result title SPARQL Tutorial Writing Simple Queries A simple example We see that the given data graph contains the URI for a book with a predicate identifying the title of the book The SPARQL query consists of the SELECT clause that identifies the variables that should appear in the query result and the WHERE clause that identifies the basic graph pattern that should be used to match against the data graph In the above example the basic graph pattern consists of a simple triple pattern with a variable for the object Writing Simple Queries An example with multiple matching results Data prefix foaf http xmlns com foaf 0 1 a foaf name Johnny Lee Outlaw a foaf mbox mailto jlow example com b foaf name Peter Goodguy b foaf mbox mailto peter example org c foaf mbox mailto carol example org Query PREFIX foaf http xmlns com foaf 0 1 SELECT name mbox WHERE x foaf name name x foaf mbox mbox Writing Simple Queries An example with multiple matching results Results name mbox Johnny Lee Outlaw mailto jlow example com Peter Goodguy mailto peter example org The query result may have 0 1 or many solutions Each solution gives one way to match the basic graph pattern against the data in the above example there are two ways to bind variables to the RDF terms a foaf name Johnny Lee Outlaw a foaf box mailto jlow example com b foaf name Peter Goodguy b foaf box mailto peter example org Example A query to select objects given any subject and a property based on some PREFIX PREFIX info http somewhere peopleInfo SELECT z WHERE element info age z Note End of Lines are essentially a space so SPARQL can all be one or more lines Example A query to select objects based on a join condition PREFIX vCard http www w3 org 2001 vcard rdf 3 0 SELECT x z WHERE element vCard Family x element vCard Given z Matching RDF Literals Consider the data below 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 Note that in Turtle cat en is an RDF literal with a lexical form cat and a language en 42 xsd integer is a typed literal with the datatype http www w3 org 2001 XMLSchema integer and abc dt specialDatatype is a typed literal with the datatype http example org datatype specialDatatype Matching RDF Literals Matching Literals with language tags Language tags are expressed using and the language tag The following query has no solution because cat is not the same as cat en Query SELECT v WHERE v p cat Result v The query below finds a solution because variable v is bound to x and the language tag is specified and matches the given data Query SELECT v WHERE v p cat en Result v http example org ns x Matching RDF Literals Matching Literals with Numeric Types Integers in a SPARQL query indicate an RDF typed literal with the datatype xsd integer Example 42 is a shortened form of 42 http www w3 org 2001 XMLSchema integer The following query has a solution with the variable v bound to y Query SELECT v WHERE v p 42 Result v http example org ns y Matching RDF Literals Matching Literals with Arbitrary Datatypes The following query has a solution with the variable v bound to z The query processor does not have to have any understanding of the values in the space of the datatype The lexical form and the datatype IRI both match hence the literal matches Query SELECT v WHERE v p abc http example org datatype specialDatatype Result v http example org ns z Example Select objects based on a stronger join condition with a matching literal value PREFIX info http somewhere peopleInfo PREFIX vCard http www w3 org 2001 vcard rdf 3 0 SELECT x WHERE element vCard FN x element info age 43 Blank Node Labels in Query


View Full Document

UTD CS 6375 - SPARQL - Part 1

Download SPARQL - Part 1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view SPARQL - Part 1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view SPARQL - Part 1 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?