{"id":1120,"date":"2019-10-28T17:41:49","date_gmt":"2019-10-28T17:41:49","guid":{"rendered":"http:\/\/www.macs.hw.ac.uk\/SWeL\/?p=1120"},"modified":"2021-10-27T16:26:13","modified_gmt":"2021-10-27T15:26:13","slug":"sparql-for-beginners","status":"publish","type":"post","link":"https:\/\/www.macs.hw.ac.uk\/SWeL\/2019\/10\/28\/sparql-for-beginners\/","title":{"rendered":"SPARQL For Beginners"},"content":{"rendered":"\n<p>\n                                <a href=\"https:\/\/www.w3.org\/TR\/sparql11-query\/\" target=\"_blank\" rel=\"noopener noreferrer\">SPARQL<\/a> (<b>S<\/b>parql <b>P<\/b>rotocol <b>A<\/b>nd <b>R<\/b>DF <b>Q<\/b>uery <b>L<\/b>anguage) is the <a href=\"https:\/\/www.w3.org\/standards\/\" target=\"_blank\" rel=\"noopener noreferrer\">W3C standard<\/a>. The protocol part is usally only an issue for people writing programs that pass SPARQL queries back and forth between different machines. For most people SPARQL greatest value is as a query language for <a href=\"https:\/\/www.w3.org\/RDF\/\" target=\"_blank\" rel=\"noopener noreferrer\">RDF<\/a> &#8211; another W3C standard. RDF describes data using a collection of three-part of one statement such as                                <em>emp3 has a title of Vice President<\/em>. <br \/>\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=1z-aT4qXbysSoSpJ7pdCvRqCtTA2ven-L&amp;export=download\" class=\"img-fluid col-md-11 mx-auto d-block\" \/>\n                            <\/p>\n<p>\n                                We call each statement a triple and one triple consist of three parts these are  <em>Subject<\/em>, <em>Predicate<\/em> and <em>Object<\/em>.\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=1HtE_Rr1EEMhaOJskcghy844crehwzh5p&amp;export=download\" class=\"img-fluid col-md-11 mx-auto d-block\" \/>\n                            <\/p>\n                            <p>\n                                We can also say the Subject as an Entity Identifier, Predicate as an Attribute Name and Object as an Attribute Value.\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=163wIFcH2YMRanwGamnzpbKe8wZCHLJov&amp;export=download\" class=\"img-fluid col-md-11 mx-auto d-block\" \/>\n                            <\/p>\n                            <p>\n                                The subject and predicate are actually represented using URIs to make it absolutely clear what we are talking about. URIs (Uniform Resource Identifier) kind of URLs and often look like them but they are not locators or addresses they are just identifiers. In our example, emp3 is the person who works in a specific company so we can represent this using URI like http:\/\/www.snee.com\/hr\/emp3 and title is also URI from the published ontology (In our case <a href=\"https:\/\/www.w3.org\/TR\/vcard-rdf\/\" target=\"_blank\" rel=\"noopener noreferrer\">VCard business card ontology<\/a>).\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=1mmllbruXmGut7P_o1whZ_DQje_J-9j5_&amp;export=download\" class=\"img-fluid col-md-11 mx-auto d-block\" \/>\n                            <\/p>\n                            <p>\n                                The object or third part of a triple can also be a URI if you like this way that same resource can be the object of some triples\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=1n7PKdJnMmQlqSZArQVHb9zv2LvAmJ35X&amp;export=download\" class=\"img-fluid col-md-11 mx-auto d-block\" \/>\n                                and subject of the others which lets you connect up triples into networks of data called Graphs.\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=1cAqeb_O2UAWBN-ZjuwQEyLZ60S1Om2gw&amp;export=download\" class=\"img-fluid col-md-11 mx-auto d-block\" \/>\n                            <\/p>\n                            <p>\n                                To make URIs simpler to write RDF popular <a href=\"https:\/\/www.w3.org\/TR\/turtle\/\" target=\"_blank\" rel=\"noopener noreferrer\">Turtle<\/a> syntax often shortens the URIs by having the abbreviated prefix stand-in for everything in the URI before the last part.\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=1Z0OHxFUYLy2hcAGEH1yX6aMVmHYCAK6A&amp;export=download\" class=\"img-fluid col-md-11 mx-auto d-block\" \/>\n                            <\/p>\n                            <p>\n                                Any data can be represented as a collection of triples for example we can usually represent each entry of a table by using the <em>Row Identifier<\/em> is the <b>Subject<\/b>, <em>Column Name<\/em> is the <b>Predicate<\/b> and <em>Value<\/em> is the <b>Object<\/b>.\n                                <img decoding=\"async\" id=\"table\" src=\"https:\/\/drive.google.com\/uc?id=1s6pXwYIiRlSPxiFJ23LY8SHXd5VgU-SU&amp;export=download\" class=\"img-fluid col-md-11 mx-auto d-block\" \/>\n                            <\/p>\n                            <p>\n                                <h4>Convert Relational Database Table to RDF Statements<\/h4>\n                                <hr \/>\n                                We can convert above table in RDF triple statements. The following RDF statements are in Turtle format of above table.\n                                <pre id=\"rdfTriples\"> <code style=\"font-size:1.125rem;background-color:white !important\">\n                                <span style=\"color:red\">\n    @prefix vcard: &lt;http:\/\/www.w3.org\/2006\/vcard\/ns#&gt; .\n    @prefix sn: &lt;http:\/\/www.snee.com\/hr\/&gt; .\n    <\/span>\n\n    sn:emp1   <span style=\"color:red\">vcard:given-name<\/span>        \"Heidi\" .\n    sn:emp1   <span style=\"color:red\">vcard:family-name<\/span>       \"Peter\" .\n    sn:emp1   <span style=\"color:red\">vcard:title<\/span>             \"CEO\" .\n    sn:emp1   <span style=\"color:red\">sn:hireDate<\/span>             \"2016-10-21\" .\n    sn:emp1   <span style=\"color:red\">sn:completedOrientation<\/span> \"2016-10-30\" .\n\n    sn:emp2   <span style=\"color:red\">vcard:given-name<\/span>         \"John\" .\n    sn:emp2   <span style=\"color:red\">vcard:family-name<\/span>        \"Peter\" .\n    sn:emp2   <span style=\"color:red\">sn:hireDate<\/span>              \"2016-10-28\" .\n    sn:emp2   <span style=\"color:red\">vcard:title<\/span>              \"Engineer\" .\n    sn:emp2   <span style=\"color:red\">sn:completedOrientation<\/span>  \"2015-01-30\" .\n\n    sn:emp3   <span style=\"color:red\">vcard:given-name<\/span>          \"Imran\" .\n    sn:emp3   <span style=\"color:red\">vcard:family-name<\/span>         \"Asif\" .\n    sn:emp3   <span style=\"color:red\">sn:hireDate<\/span>               \"2014-12-03\" .\n    sn:emp3   <span style=\"color:red\">vcard:title<\/span>               \"Vice President\" .\n\n    sn:emp4   <span style=\"color:red\">vcard:given-name<\/span>          \"Duke\" .\n    sn:emp4   <span style=\"color:red\">vcard:family-name<\/span>         \"Walliam\" .\n    sn:emp4   <span style=\"color:red\">vcard:title<\/span>               \"Sales\" .\n    sn:emp4   <span style=\"color:red\">sn:hireDate<\/span>               \"2015-11-10\" .\n<\/code><\/pre>\n                            <\/p>\n                            <p>\n                                This information can give us triples for every fact on the table. Some of the property names here from the <a href=\"https:\/\/www.w3.org\/TR\/vcard-rdf\/\" target=\"_blank\" rel=\"noopener noreferrer\">vCard vocabulary<\/a>. For those properties that are not available in <a href=\"https:\/\/www.w3.org\/TR\/vcard-rdf\/\" target=\"_blank\" rel=\"noopener noreferrer\">vCard vocabulary<\/a>, I made up my own property names using my own domain name. RDF makes it easy to mix and mash standard vocabularies and customizations.\n                            <\/p>\n                            <p>\n                                Let\u2019s say that the employee in the above <a href=\"#table\">table<\/a>, John Peter completed his employee orientation course twice and if we want to store both of his completed course orientation values in the RDF then there is not a problem with the RDF. But if we want to stored John\u2019s second completed orientation value in a relational database table then it would have been a lot more difficult.\n                                <pre> <code style=\"font-size:1.125rem;background-color:white !important\">\n    sn:emp2   vcard:given-name          \"John\" .\n    sn:emp2   vcard:family-name         \"Peter\" .\n    sn:emp2   sn:hireDate               \"2016-10-28\" .\n    sn:emp2   vcard:title               \"Engineer\" .\n    sn:emp2   sn:completedOrientation   \"2015-01-30\" .\n    <span style=\"color:red\">sn:emp2   sn:completedOrientation   \"2015-03-15\" .<\/span>\n<\/code><\/pre>\n                            <\/p>\n                            <h4>SPARQL Example Queries<\/h4>\n                            <hr \/>\n                            <h5>WHERE Clause<\/h5>\n                            <p>\n                                let&#8217;s look at a simple SPARQL query that retrieve some of the data from the <a href=\"#rdfTriples\">above RDF Triples<\/a>. <br \/><b id=\"query1\">Query 1: We want a list of all employees whose last name is Peter.<\/b>\n                                <pre>\n                                <code style=\"font-size:1.125rem;background-color:white !important\">\n    PREFIX vcard: &lt;http:\/\/www.w3.org\/2006\/vcard\/ns#&gt;\n    \n    SELECT ?person\n    WHERE\n    {\n      ?person vcard:family-name \"Peter\" .\n    }<\/code><\/pre>\n                            <\/p>\n                            <p>\n                                We can define the prefixes in the start of SPARQL query due to the Turtle RDF syntax, that\u2019s why you don\u2019t have to write absolute URIs in your queries. For most SPARQL queries it\u2019s best to look at the <em>Where<\/em> clause first because that describe which triples we want to pull from the dataset that we are querying. The <em>Where<\/em> clause does this with one or more triple patterns which are likely triples with variables as wildcards substituted into one, two or all three of each triples parts.\n                            <\/p>\n                            <p>\n                                In the <a href=\"#query1\">Query 1<\/a>, one triple pattern will match against triples whose predicate is the family name property from the vCard vocabulary, whose object is string <b>Peter<\/b> and whose subject is anything at all. Because this triple pattern has a variable that I named <b>person<\/b>.\n                            <\/p>\n                            <h5>SELECT Clause<\/h5>\n                            <p>\n                                The Select clause indicates which variables values we want listed after the query executes. The <a href=\"#query1\">Query 1<\/a> only has one variable so that\u2019s the one we want to see.\n                            <\/p>\n                            <p>\n                                When the query executes, it finds two triples that match the specified pattern from the RDF triples set and assigned these two triples to the person variable which are the subjects e.g., emp1 and emp2. The following triples show the two matches of the above query with green colour.\n                                <pre id=\"rdfTriples\"> <code style=\"font-size:1.125rem;background-color:white !important\">\n    @prefix vcard: &lt;http:\/\/www.w3.org\/2006\/vcard\/ns#&gt; .\n    @prefix sn: &lt;http:\/\/www.snee.com\/hr\/&gt; .\n\n    sn:emp1   vcard:given-name        \"Heidi\" .\n    <span style=\"color:mediumseagreen;font-weight:bold\">sn:emp1   vcard:family-name       \"Peter\" .<\/span>\n    sn:emp1   vcard:title             \"CEO\" .\n    sn:emp1   sn:hireDate             \"2016-10-21\" .\n    sn:emp1   sn:completedOrientation \"2016-10-30\" .\n\n    sn:emp2   vcard:given-name         \"John\" .\n    <span style=\"color:mediumseagreen;font-weight:bold\">sn:emp2   vcard:family-name        \"Peter\" .<\/span>\n    sn:emp2   sn:hireDate              \"2016-10-28\" .\n    sn:emp2   vcard:title              \"Engineer\" .\n    sn:emp2   sn:completedOrientation  \"2015-01-30\" .\n    sn:emp2   sn:completedOrientation  \"2015-03-15\" .\n\n    sn:emp3   vcard:given-name          \"Imran\" .\n    sn:emp3   vcard:family-name         \"Asif\" .\n    sn:emp3   sn:hireDate               \"2014-12-03\" .\n    sn:emp3   vcard:title               \"Vice President\" .\n\n    sn:emp4   vcard:given-name          \"Duke\" .\n    sn:emp4   vcard:family-name         \"Walliam\" .\n    sn:emp4   vcard:title               \"Sales\" .\n    sn:emp4   sn:hireDate               \"2015-11-10\" .\n<\/code><\/pre>\n                            <\/p>\n                            <p>\n                                Let&#8217;s executes the <a href=\"#query1\">Query 1<\/a> and find out who are these Peters. we get the following table as a result.<br \/>\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=1Z_0F-SL0NR9T2FUnrZVSll_7BU0-1ZmI&amp;export=download\" class=\"img-fluid col-md-3 mx-auto d-block\" style=\"width: 45%\" \/>\n                            <\/p>\n                            <p>\n                                From the above results, we can see that emp1 and emp2 are just identifiers. This doesn\u2019t give us meaningful result. <br \/><b id=\"query2\">Query 2: Now let&#8217;s add a second triple pattern in the <em>WHERE<\/em> clause that matches on the given name of the employee, who matches the first triple pattern and stores that value in a new <b>givenName<\/b> variable<\/b>.\n                                <pre>\n                                <code style=\"font-size:1.125rem;background-color:white !important\">\n    PREFIX vcard: &lt;http:\/\/www.w3.org\/2006\/vcard\/ns#&gt; \n\n    SELECT ?person ?givenName\n    WHERE \n    { \n       ?person vcard:family-name \"Peter\" . \n       ?person vcard:given-name ?givenName .\n    }<\/code><\/pre>\n                            <\/p>\n                            <p>\n                                The explanation of the <a href=\"#query2\">Query 2<\/a> is that we need to adjust the <em>SELECT<\/em> Clause with the new variable givenName because now we want this in the result. The SPARQL query processor finds each triple that matches the first triple pattern and store the value in the person variable. When it looks for the second triple pattern in the <em>WHERE<\/em> clause, who have a triple that matches the first triple pattern. In easy words, SPARQL processor get all triples of family-name Peter along with given-name. So when we run the <a href=\"#query2\">Query 2<\/a> we see given name values in the result.\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=1HZQiEyDda-06qt69tBkd3RlZ1wz7O_Mg&amp;export=download\" class=\"img-fluid col-md-6 mx-auto d-block\" \/>\n                            <\/p>\n                            <p>\n                                <b id=\"query3\">Query 3: Let&#8217;s retrieve the given name, family name and hire date of all the employees.<\/b><br \/> We can do this with a <em>WHERE<\/em> Clause that has three triple patterns one for each piece of information that we want to retrieve.\n                                <pre><code style=\"font-size:1.125rem;background-color:white !important\">\n    PREFIX vcard: &lt;http:\/\/www.w3.org\/2006\/vcard\/ns#&gt;\n    PREFIX sn: &lt;http:\/\/www.snee.com\/hr\/&gt;\n\n    SELECT ?givenName ?familyName ?hireDate\n    WHERE\n    {\n        ?person vcard:given-name ?givenName .\n        ?person vcard:family-name ?familyName .\n        ?person sn:hireDate ?hireDate .\n    }\n<\/code><\/pre>\n                            <\/p>\n                            <p>\n                                When we run the <a href=\"#query3\">query 3<\/a>, we get the following results.\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=15PcxaVTgh6EaxNWLbODqQoyxtPe2jMsO&amp;export=download\" class=\"img-fluid col-md-8 mx-auto d-block\" \/>\n                            <\/p>\n                            <h5>FILTER Keyword<\/h5>\n                            <p>\n                                If we want to narrow down the results based on some condition, we can use a <em>FILTER<\/em> pattern. <br \/> <b id=\"query4\">Query 4: Let\u2019s say we want a list of employees who are hired before November 1<sup>st<\/sup> so the <em>FILTER<\/em> pattern specifies that we only want HD values that are less than November 1<sup>st<\/sup> 2015<\/b>.\n                                <pre><code style=\"font-size:1.125rem;background-color:white !important\">\n    PREFIX vcard: &lt;http:\/\/www.w3.org\/2006\/vcard\/ns#&gt;\n    PREFIX sn: &lt;http:\/\/www.snee.com\/hr\/&gt;\n\n    SELECT ?givenName ?familyName ?hireDate\n    WHERE\n    {\n        ?person vcard:given-name ?givenName .\n        ?person vcard:family-name ?familyName .\n        ?person sn:hireDate ?hireDate .\n        FILTER(?hireDate &lt; &quot;2015-11-01&quot;)\n    }<\/code><\/pre>\n                            <\/p>\n                            <p>\n                                When we run the <a href=\"#query4\">query 4<\/a>, we get the following results in the ISO 8601 date format.\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=1Qh2_Qwe93-dfwkMXkrxyRcwsV-1EkDrm&amp;export=download\" class=\"img-fluid col-md-8 mx-auto d-block\" \/>\n                            <\/p>\n                            <p>\n                                <b id=\"query5\">Query 5: Let\u2019s remove the <em>FILTER<\/em> condition and list the employees and their completed orientation values instead of their hire date values.<\/b>\n                                <pre><code style=\"font-size:1.125rem;background-color:white !important\">\n    PREFIX vcard: &lt;http:\/\/www.w3.org\/2006\/vcard\/ns#&gt;\n    PREFIX sn: &lt;http:\/\/www.snee.com\/hr\/&gt;\n\n    SELECT ?givenName ?familyName ?oDate\n    WHERE\n    {\n        ?person vcard:given-name ?givenName .\n        ?person vcard:family-name ?familyName .\n        ?person sn:completedOrientation  ?oDate .\n    }<\/code><\/pre>\n                            <\/p>\n                            <p>\n                                When we run the <a href=\"#query5\">query 5<\/a>, we get the following results.\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=1D8QUZztl4ONmGz788SJ0I1SKtOvMGbv-&amp;export=download\" class=\"img-fluid col-md-8 mx-auto d-block\" \/>\n                            <\/p>\n                            <p>\n                                We see only Heidi and John\u2019s orientation dates but the other employees don\u2019t appear at all in the results why not? Let\u2019s look more closely at the query 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 triple patterns but Imran and Duke cannot match all three triple patterns. You have noted that John actually had two triples that matched the third pattern of the query, so the query had two rows of results for him, one for each completed orientation value.\n                            <\/p>\n                            <h5>OPTIONAL Keyword<\/h5>\n                            <p>\n                                <b id=\"query6\">Query 6: Let\u2019s take another example, list of all employees and if they have any their completed orientation values.<\/b><br \/> We can tell query processor that matching on the third triple pattern is <em>OPTIONAL<\/em>.\n                                <pre><code style=\"font-size:1.125rem;background-color:white !important\">\n    PREFIX vcard: &lt;http:\/\/www.w3.org\/2006\/vcard\/ns#&gt;\n    PREFIX sn: &lt;http:\/\/www.snee.com\/hr\/&gt;\n\n    SELECT ?givenName ?familyName ?oDate\n    WHERE\n    {\n        ?person vcard:given-name ?givenName .\n        ?person vcard:family-name ?familyName .\n        OPTIONAL { ?person sn:completedOrientation  ?oDate . }\n    }<\/code><\/pre>\n                            <\/p>\n                            <p>\n                                This query asks for everyone with a given name and a family name and if they have a completed orientation value it will show the following result.\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=1aXboeQUl_HlothFtkD3rr-r7Hrb6UlFp&amp;export=download\" class=\"img-fluid col-md-8 mx-auto d-block\" \/>\n                            <\/p>\n                            <h5>NOT EXISTS Keyword<\/h5>\n                            <p>\n                                <b id=\"query7\">Query 7: Next let\u2019s 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.<\/b><br \/> Her query asks for everyone\u2019s given and family names but only if for any employee who matches those first two triple patterns no triple exists that lists a completed orientation value for that employee. We do this with the keywords <em>NOT EXISTS<\/em>.\n                                <pre><code style=\"font-size:1.125rem;background-color:white !important\">\n    PREFIX vcard: &lt;http:\/\/www.w3.org\/2006\/vcard\/ns#&gt;\n    PREFIX sn: &lt;http:\/\/www.snee.com\/hr\/&gt;\n\n    SELECT ?givenName ?familyName\n    WHERE\n    {\n        ?person vcard:given-name ?givenName .\n        ?person vcard:family-name ?familyName .\n        NOT EXISTS { ?person sn:completedOrientation  ?oDate . }\n    }<\/code><\/pre>\n                            <\/p>\n                            <p>\n                                When we run the <a href=\"#query7\">query 7<\/a>, we get the following results.\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=1-PYhP5rBoz-qbKE8IqIeVx0SNgkrxihT&amp;export=download\" class=\"img-fluid col-md-7 mx-auto d-block\" \/>\n                            <\/p>\n                            <h5>BIND Keyword<\/h5>\n                            <p>\n                                So far, the only way we have 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 triple. We can use the bind keyword to store whatever we like in a variable.\n                                <pre><code style=\"font-size:1.125rem;background-color:white !important\">\n    PREFIX vcard: &lt;http:\/\/www.w3.org\/2006\/vcard\/ns#&gt;\n    PREFIX sn: &lt;http:\/\/www.snee.com\/hr\/&gt;\n\n    SELECT ?givenName ?familyName ?someVariable\n    WHERE {\n        ?person vcard:given-name ?givenName .\n        ?person vcard:family-name ?familyName .\n        BIND(\"some value\" AS ?someVariable)\n    }<\/code><\/pre>\n                            <\/p>\n                            <p>\n                                When we run the above query, we get the following results.\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=1EfgB2-XIKNeJE5p6Wvaumx6i5AqmC3t-&amp;export=download\" class=\"img-fluid col-md-8 mx-auto d-block\" \/>\n                            <\/p>\n                            <p>\n                                This can be especially useful when the BIND expression uses values from other variables and calls some of SPARQL broad range of available functions to create a new value. In the following query the bind statement uses SPARQL\u2019s 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. It stores the result of this concatenation in a new variable called <b>fullName<\/b>.\n                                <pre><code style=\"font-size:1.125rem;background-color:white !important\">\n    PREFIX vcard: &lt;http:\/\/www.w3.org\/2006\/vcard\/ns#&gt;\n    PREFIX sn: &lt;http:\/\/www.snee.com\/hr\/&gt;\n\n    SELECT ?givenName ?familyName ?fullName\n    WHERE {\n        ?person vcard:given-name ?givenName .\n        ?person vcard:family-name ?familyName .\n        BIND(concat(?givenName,\" \",?familyName) AS ?fullName)\n    }<\/code><\/pre>\n                            <\/p>\n                            <p>\n                                When we run the above query, we get the following results with new full name value for each employee.\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=1UxXOc3kwsd0vHW_4qaT7iyEwOnA964Jx&amp;export=download\" class=\"img-fluid col-md-8 mx-auto d-block\" \/>\n                            <\/p>\n                            <h5>CONSTRUCT Clause<\/h5>\n                            <p>\n                                All the queries we have seen so far have been <em>SELECT<\/em> queries which are like SQL <em>SELECT<\/em> statements. A Sparql construct query uses the same kind of <em>WHERE<\/em> clauses that a <em>SELECT<\/em> query can use but it can use the values stored in the variables to create the new triples.\n                                <pre><code style=\"font-size:1.125rem;background-color:white !important\">\n    PREFIX vcard: &lt;http:\/\/www.w3.org\/2006\/vcard\/ns#&gt;\n    PREFIX sn: &lt;http:\/\/www.snee.com\/hr\/&gt;\n\n    CONSTRUCT {?person vcard:fn ?fullName\n    WHERE {\n        ?person vcard:given-name ?givenName .\n        ?person vcard:family-name ?familyName .\n        BIND(concat(?givenName,\" \",?familyName) AS ?fullName)\n    }<\/code><\/pre>\n                            <\/p>\n                            <p>\n                                When we run the above query, we get the following new triples.\n                                <img decoding=\"async\" src=\"https:\/\/drive.google.com\/uc?id=1qs9aV0956uMdr82jSo7NQD2KdwNL1I7Z&amp;export=download\" class=\"img-fluid col-md-8 mx-auto d-block\" \/>\n                            <\/p>\n                            <p>\n                                Note that 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 modal and creates triples conforming to another. The construction queries are great for data integration projects.\n                                <pre><code style=\"font-size:1.125rem;background-color:white !important\">\n    PREFIX vcard: &lt;http:\/\/www.w3.org\/2006\/vcard\/ns#&gt;\n    PREFIX sn: &lt;http:\/\/www.snee.com\/hr\/&gt;\n    PREFIX foaf: &lt;http:\/\/xmlns.com\/foaf\/0.1\/&gt;\n    PREFIX rdf: &lt;http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#&gt;\n\n    CONSTRUCT {\n        ?person rdf:type foaf:Person .\n        ?person foaf:givenName ?givenName .\n        ?person foaf:familyName ?familyName .\n        ?person foaf:name ?fullName .\n    }\n    WHERE {\n        ?person vcard:given-name ?givenName .\n        ?person vcard:family-name ?familyName .\n        BIND(concat(?givenName,\" \",?familyName) AS ?fullName)\n    }<\/code><\/pre>\n                            <\/p>\n                            <p>\n                                When we run the above query, we get the following new triples.\n                                <pre><code style=\"font-size:1.125rem;background-color:white !important\">\n            @prefix vcard: &lt;http:\/\/www.w3.org\/2006\/vcard\/ns#&gt; .\n            @prefix sn: &lt;http:\/\/www.snee.com\/hr\/&gt; .\n            @prefix foaf: &lt;http:\/\/xmlns.com\/foaf\/0.1\/&gt;\n            @prefix rdf: &lt;http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#&gt;\n\n            sn:emp1   rdf:type          foaf:Person .\n            sn:emp1   foaf:familyName   \"Peter\" .\n            sn:emp1   foaf:givenName    \"Heidi\"\n            sn:emp1   foaf:name\t\t\"Heidi Peter\"\n\n            sn:emp2   rdf:type          foaf:Person .\n            sn:emp2   foaf:familyName   \"Peter\" .\n            sn:emp2   foaf:givenName    \"John\"\n            sn:emp2   foaf:name\t\t\"John Peter\"\n\n\n            sn:emp2   rdf:type          foaf:Person .\n            sn:emp2   foaf:familyName   \"Asif\" .\n            sn:emp2   foaf:givenName    \"Imran\"\n            sn:emp2   foaf:name\t\t\"Imran Asif\"\n\n            sn:emp2   rdf:type          foaf:Person .\n            sn:emp2   foaf:familyName   \"Walliam\" .\n            sn:emp2   foaf:givenName    \"Duke\"\n            sn:emp2   foaf:name\t\t\"Duke Walliam\"<\/code><\/pre>\n                            <\/p>\n                            <p>\n                                <h4>SPARQL Do More:<\/h4>\n                                Sparql can do a lot more than what we have seen here. You can\n                                <ul>\n                                    <li>Use Data types languages tags, <\/li>\n                                    <li>Sort and aggregate query results <\/li>\n                                    <li>Add, delete and update data<\/li>\n                                    <li>Retrieve JSON, XML, and delimited versions of query results from query processors <\/li>\n                                    <li>Send queries to remote private or public data collections and there are quite a few of those out there. <\/li>\n                                <\/ul>\n                            <\/p>\n                        <h4>References<\/h4>\n                            <hr \/>\n                            <p><a href=\"https:\/\/books.google.co.uk\/books?id=s2RgGxd572QC&amp;dq=Learning+SPARQL&amp;lr=\" target=\"_blank\" rel=\"noopener noreferrer\"> DuCharme, B., 2013. Learning SPARQL: querying and updating with SPARQL 1.1. &#8221; O&#8217;Reilly Media, Inc.&#8221;<\/a>.<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>SPARQL (Sparql Protocol And RDF Query Language) is the W3C standard. The protocol part is usally only an issue for people writing programs that pass SPARQL queries back and forth between different machines. For most people SPARQL greatest value is as a query language for RDF &#8211; another W3C standard. RDF describes data using a &hellip; <a href=\"https:\/\/www.macs.hw.ac.uk\/SWeL\/2019\/10\/28\/sparql-for-beginners\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;SPARQL For Beginners&#8221;<\/span><\/a><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[99,84,87,73,82,86,92,1],"tags":[142,153,151,144,148,152,146,147,150,149],"class_list":["post-1120","post","type-post","status-publish","format-standard","hentry","category-data","category-database","category-graph","category-phd-students","category-rdf","category-semanticweb","category-sparql","category-uncategorized","tag-sparql","tag-sparql-exist","tag-sparql-filter","tag-sparql-for-beginners","tag-sparql-for-dummies","tag-sparql-optional","tag-sparql-queries","tag-sparql-query","tag-sparql-select-clause","tag-sparql-where-clause"],"_links":{"self":[{"href":"https:\/\/www.macs.hw.ac.uk\/SWeL\/wp-json\/wp\/v2\/posts\/1120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.macs.hw.ac.uk\/SWeL\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.macs.hw.ac.uk\/SWeL\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.macs.hw.ac.uk\/SWeL\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.macs.hw.ac.uk\/SWeL\/wp-json\/wp\/v2\/comments?post=1120"}],"version-history":[{"count":24,"href":"https:\/\/www.macs.hw.ac.uk\/SWeL\/wp-json\/wp\/v2\/posts\/1120\/revisions"}],"predecessor-version":[{"id":1287,"href":"https:\/\/www.macs.hw.ac.uk\/SWeL\/wp-json\/wp\/v2\/posts\/1120\/revisions\/1287"}],"wp:attachment":[{"href":"https:\/\/www.macs.hw.ac.uk\/SWeL\/wp-json\/wp\/v2\/media?parent=1120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.macs.hw.ac.uk\/SWeL\/wp-json\/wp\/v2\/categories?post=1120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.macs.hw.ac.uk\/SWeL\/wp-json\/wp\/v2\/tags?post=1120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}