Learning SPARQL
Querying and Updating with SPARQL 1.1
Bob DuCharme
Beijing Cambridge Farnham Kln Sebastopol Tokyo
Download from Wow! eBook
For my mom and dad, Linda and Bob Sr., who always supported any ambitious projects I attempted, even when I left college because my bandmates and I thought we were going to become big stars. (We didnt.)
Special Upgrade Offer
If you purchased this ebook directly from oreilly.com, you have the following benefits:
DRM-free ebooksuse your ebooks across devices without restrictions or limitations
Multiple formatsuse on your laptop, tablet, or phone
Lifetime access, with free updates
Dropbox syncingyour files, anywhere
If you purchased this ebook from another retailer, you can upgrade your ebook to take advantage of all these benefits for just $4.99. to access your ebook upgrade.
Please note that upgrade offers are not available from sample content.
Preface
It is hardly surprising that the science they turned to for an explanation of things was divination, the science that revealed connections between words and things, proper names and the deductions that could be drawn from them ...
Henri-Jean Martin, The History and Power of Writing
Why Learn SPARQL?
More and more people are using the query language SPARQL (pronounced sparkle) to pull data from a growing collection of public and private data. Whether this data is part of a semantic web project or an integration of two inventory databases on different platforms behind the same firewall, SPARQL is making it easier to access it. In the words of W3C Director and web inventor Tim Berners-Lee, Trying to use the Semantic Web without SPARQL is like trying to use a relational database without SQL.
SPARQL was not designed to query relational data, but to query data conforming to the RDF data model. RDF-based data formats have not yet achieved the mainstream status that XML and relational databases have, but an increasing number of IT professionals are discovering that tools that use this data model make it possible to expose diverse sets of data (including, as well see, relational databases) with a common, standardized interface. Accessing this data doesnt require learning new APIs because both open source and commercial software (including Oracle 11g and IBMs DB2) are available with SPARQL support that lets you take advantage of these data sources. Because of this data and tool availability, SPARQL has let people access a wide variety of public data and has provided easier integration of data silos within many enterprises.
Although this books table of contents, glossary, and index let it serve as a reference guide when you want to look up the syntax of common SPARQL tasks, its not a complete reference guideif it covered every corner case that might happen when you use strange combinations of different keywords, it would be a much longer book. Instead, the books primary goal is to quickly get you comfortable using SPARQL to retrieve and update data and to make the best use of that retrieved data. Once you can do this, you can take advantage of the extensive choice of tools and application libraries that use SPARQL to retrieve, update, and mix and match the huge amount of RDF-accessible data out there.
1.1 Alert
The W3C promoted the SPARQL 1.0 specifications into Recommendations, or official standards, in January of 2008. The following year the SPARQL Working Group began work on SPARQL 1.1, and this larger set of specifications became Recommendations in March of 2013. SPARQL 1.1 added new features such as new functions to call, greater control over variables, and the ability to update data.
While 1.1 was widely supported by the time it reached Recommendation status, there are still some triplestores whose SPARQL engines have not yet caught up, so this books discussions of new 1.1 features are highlighted with 1.1 Alert boxes like this to help you plan around the use of software that might be a little behind. The free software described in this book is completely up to date with SPARQL 1.1.
Organization of This Book
You dont have to read this book cover-to-cover. After you read .
Writing and running a few simple queries before getting into more detail on the background and use of SPARQL
The bigger picture: the semantic web, related specifications, and what SPARQL adds to and gets out of them
Building on , a broader introduction to the query language
Using SPARQL to copy data from a dataset, to create new data, and to find bad data
How datatype metadata, standardized functions, and extension functions can contribute to your queries
Using SPARQLs update facility to add to and change data in a dataset instead of just retrieving it
Things to keep in mind that can help your queries run more efficiently as you work with growing volumes of data
How your applications can take advantage of the XML, JSON, CSV, and TSV formats defined by the W3C for SPARQL processors to return query results
How SPARQL can take advantage of the metadata that RDF Schemas, OWL ontologies, and SPARQL rules can add to your data
Different roles that SPARQL can play in applications that you develop
A set of SPARQL queries and update requests that can be useful in a wide variety of situations
A glossary of terms and acronyms used when discussing SPARQL and RDF technology
Youll find an index at the back of the book to help you quickly locate explanations for SPARQL and RDF keywords and concepts. The index also lets you find where in the book each sample file is used.
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, datatypes, environment variables, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.
Documentation Conventions
Variables and prefixed names are written in a monospace font like this
. (If you dont know what prefixed names are, youll learn in
# filename: ex001.rqPREFIX d: SELECT ?personWHERE{ ?person d:homeTel
"(229) 276-5135" . }
When including punctuation at end of a quoted phrase, this book has it inside the quotation marks in the American publishing style, like this, unless the quoted string represents a specific value that would be changed if it included the punctuation. For example, if your password on a system is swordfish, I dont want you to think that the comma is part of the password.
The following icons alert you to details that are worth a little extra attention:
Note
An important point that might be easy to miss.
Tip
A tip that can make your development or your queries more efficient.
Warning
A warning about a common problem or an easy trap to fall into.
Using Code Examples
Youll find a ZIP file of all of this books sample code and data files at http://www.learningsparql.com, along with links to free SPARQL software and other resources.