[Music] Sparkle is a w3c standard it stands for Sparkle protocol and rdf query language the protocol part is usually only an issue for people writing programs that pass Sparkle queries back and forth between different machines for most people Sparkle's greatest value is as a query language for rdf another w3c standard rdf lets you describe data using a collection of three-part statements such as employee 3 has a title of Vice President we call each statement a triple and we call its three parts the subject predicate and object you can think of them as an entity identifier
an attribute name and an attribute value the subject and predicate are actually represented using uis to make it absolutely clear what we're talking about Uris are kind of like URLs and often look like them but they're not locators or addresses they're just identifiers these Uris show that we mean employee 3 from a specific company and that we mean title in the sense of job title and not a label for a book movie or other creative work because we're using the URI for title defined by the w3c's published version of the vCard business card ontology the
object or third part of a triple can also be a URI if you like this way the same resource can be the object of some triples and the subject of others which lets you connect up triples into networks of data called graphs to make uis simpler to write rdf's popular Turtle syntax often shortens the uis by having an abbreviated prefix stand in for everything in the URI before the last part just about any data can be represented as a collection of triples for example we can usually represent each entry of a table by using the
row identifier as the subject the column name as the predicate and the value as the object this can give us triples for every fact on the table some of the property names here come from the vCard vocabulary for the properties not available in vCard I made up my own property names using my own domain name rdf makes it easy to mix and match standard vocabularies and customizations let's say that of the employees on this table John Smith completed the employee orientation course twice and we want to store both of his completed orientation values this is
no problem with rdf if the original data had been stored in a relational database table adding John's second completed or orientation value would have been a lot more difficult let's look at a simple Sparkle query that retrieves some of this data we want a list of all the employees whose last name is Smith like the turtle rdf syntax Sparkle lets you define prefixes so that you don't have to write out full Uris in your queries for most Sparkle queries it's best to look at the wear Clause first because that describes which triples we want to
pull from the data set that we're querying the wear Clause does this with one or more triple patterns which are like triples with variables as wild cards substituted into one two or all three of each triple's parts in this query the one triple pattern will match against triples whose predicate is the family name property from the vCard vocabulary whose object is the string Smith and whose subject is anything at all because this triple pattern has a variable that I named person in this position the select Clause indicates which variables values we want listed after the
query executes this query only has one variable so that's the one we want to see when the query executes it finds two triples that match the specified pattern so the query's results that is the values that got assigned to the person variable will be the subjects from those two Tri triples let's execute the query and find out who are these Smiths the M1 and M2 identifiers listed in our first query's results don't tell us much let's add a second triple pattern that matches on the given name of the employees who matched the first triple pattern
and stores that value in a new given name variable we'll also adjust the select Clause to request the value of our new variable after the query processor finds each triple that matches the first triple pattern it will remember the value it stored in the person variable when it looks for triples that match the second one of the two people who have a triple that matches the first triple pattern they each have a triple for given name as well so when we run the query we see their given name values in the result let's retrieve the
given name name family name and hire date of all the employees we can do this with a wear Clause that has three triple patterns one for each piece of information that we want to retrieve if we want to narrow down the results based on some condition we can use a filter pattern we want a list of employees who were hired before March 1st so the filter pattern specifies that we only want HD values that are less than in March 1st 2015 expressed as an ISO 8601 date format and that's what we get let's remove the
filter condition and list the employees and their completed orientation values instead of their higher date values we see Heidi and Jon's orientation dates but the other employees don't appear at all in the results why not let's look more closely at the queries trip triple patterns the query first looks for a triple with a given name value and then a triple with the same subject as the subject that it found to match the first triple pattern but with a family name value and then another triple with the same subject and a completed orientation value John and
Heidi each have triples that match all the query's triple patterns but Francis and Jane cannot match all three triple patterns note how John actually had two triples that matched the query's thirdd pattern which is why the query had two rows of results for him one for each completed orientation value what if we want to list all of the employees and if they have any they're completed orientation values we can tell the query processor that matching on the third triple pattern is optional this query asks for everyone with a given name and a family name and
if they have a completed orientation value it will show that too next let's say that Heidi is scheduling a new orientation meeting and wants to know who to invite in other words she wants to list all employees who do not have a completed orientation value her query asks for everyone's given and family names but only if for any employee who es those first two triple patterns no triple exists that lists a completed orientation value for that employee we do this with the keywords not exists and there they are Jane and Francis so far the only
way we've seen to store a value in a variable is to include that variable in a triple pattern for the query processor to match against some part of a triple we can use the bind keyword to store whatever we like in a variable this can be especially useful when the bind expression uses values from other variables and calls some of Sparkle's broad range of available functions to create a new value in this query the bind statement uses Sparkle's concat function to concatenate the given name value stored by the first triple pattern a space and the
family name value stored by the second triple pattern pattern it stores the result of this concatenation in a new variable called full name running the query creates a new full name value for each employee all the queries we've seen so far have been select queries which as with SQL list values that you want returned as columns in a table of results a sparkle construct query uses the same kind of wear Clauses that a select query can use but it can use the values stored in the variables to create new triples note how the triple pattern
showing the triple to construct is inside of curly braces these curly braces can enclose multiple triple patterns which is a common practice when for example a construct query takes data conforming to one model and creates triples conforming to another this is great for data integration projects Sparkle can do a lot more than what we've seen here you can use data types and language tags you can sort and aggregate query results and you can add delete and update data you can also retrieve Json XML and delimited versions of query results from query processors and you can
send queries to remote private or public data Collections and there are quite a few of those out there the O'Reilly book learning Sparkle shows you how to do all this and more you'll learn about what Sparkle can add to your applications and what kind of Open Source and Commercial Sparkle processors are available you'll also learn about what Sparkle and inferencing can offer each other and what issues to consider when you want your queries to be more efficient and you'll learn where Sparkle fits into discussions of the semantic web and link to data go to learnings
sparkle. comom to order learning Sparkle as a bound hard copy book or in a variety of ebook formats from Amazon or directly from ory publishing [Music]