SPARQL query language

With a generic understanding of Ontologies, the RDF, and OWL, we are able to fundamentally understand how intelligent systems can communicate with each other seamlessly with a semantic view of the world. With a semantic worldview, the entities come to life by translating data assets into information and information assets into knowledge. It is imperative that there is a common language to leverage a semantic worldview so that heterogeneous systems can communicate with each other. SPARQL is a W3C standard that is attempting to be the global query language with the primary goal of interoperability. SPARQL is a recurring acronym and stands for SPARQL Protocol and RDF Query Language. As the name indicates, it is a query language for querying knowledge (as triples) stored in RDF format. Traditionally, we stored the information in relational databases in tabular format. The relational database view of the entities can easily be represented as triples. For example, let us once again consider the BOOK table:

Here, the row identifier (Book_ID and Title) is the subject, the column name is the predicate, and the column value is the object. For example:

A Triple:

     {1: Hit Refresh}                            {Author}                                           {Satya Nadella}

Subject (Entity Name)          Predicate (Attribute Name)                  Object (Attribute Value)

The subjects and predicates are represented using URIs which universally identify specific subjects and predicates as resources:

http://www.artificial-intelligence.big-data/book#   http://www.artificial-intelligence.big-data/book#author "Satya Nadella"

Turtle syntax allows an RDF graph to be completely written in a compact and natural text form. It provides abbreviations for common usage patterns and datatypes. This format is compatible with the triple pattern syntax of SPARQL.

Let us use the turtle syntax to represent the book table in RDF format:

@prefix book: <http://www.artificial-intelligence.big-data/book#>

book:1 book:Title "Hit Refresh"
book:1 book:Author "Satya Nadella"
book:1 book:Company "Microsoft"
book:1 book:Year "2017"

book:2 book:Title "Shoe Dog"
book:2 book:Author "Phil Knight"
book:2 book:Company "Nike"
book:2 book:Year "2016"

Let us use a simple SPARQL query for getting a list of books published in the year 2017:

PREFIX book: <http://www.artificial-intelligence.big-data/book#>

SELECT ?books
WHERE
{
?books book:year "2017" .
}

We have the following result:

?books
book:1

Here is another SELECT query, which fetches more data elements from the dataset:

PREFIX book: <http://www.artificial-intelligence.big-data/book#>

SELECT ?books ?bookName ?company
WHERE
{
?books book:year "2017" .
?books book:title ?bookName .
?books book:company ?company .
}

The result is as follows:

?books    ?bookName     ?company
book:1 Hit Refresh Microsoft

While we are discussing role of Ontologies in the context of Artificial Intelligence for Big Data, a complete reference to OWL and SPARQL is outside of the scope of this book. In the following subsections, we will introduce a generic SPARQL language reference, which will help us leverage Ontologies to build artificial intelligence.