- SPARQL is a query language for retrieving and manipulating data stored in RDF format. It is similar to SQL but for RDF data.
- SPARQL queries contain prefix declarations, specify a dataset using FROM, and include a graph pattern in the WHERE clause to match triples.
- The main types of SPARQL queries are SELECT, ASK, DESCRIBE, and CONSTRUCT. SELECT returns variable bindings, ASK returns a boolean, DESCRIBE returns a description of a resource, and CONSTRUCT generates an RDF graph.
I used these slides for an introductory lecture (90min) to a seminar on SPARQL. This slideset introduces the RDF query language SPARQL from a user's perspective.
SPARQL introduction and training (130+ slides with exercices)Thomas Francart
Full SPARQL training
Covers all SPARQL : basic graph patterns, FILTERs, functions, property paths, optional, negation, assignation, aggregation, subqueries, federated queries.
Does not cover except SPARQL updates.
Includes exercices on DBPedia.
CC BY license
I used these slides for an introductory lecture (90min) to a seminar on SPARQL. This slideset introduces the RDF query language SPARQL from a user's perspective.
SPARQL introduction and training (130+ slides with exercices)Thomas Francart
Full SPARQL training
Covers all SPARQL : basic graph patterns, FILTERs, functions, property paths, optional, negation, assignation, aggregation, subqueries, federated queries.
Does not cover except SPARQL updates.
Includes exercices on DBPedia.
CC BY license
Semantic Web technologies (such as RDF and SPARQL) excel at bringing together diverse data in a world of independent data publishers and consumers. Common ontologies help to arrive at a shared understanding of the intended meaning of data.
However, they don’t address one critically important issue: What does it mean for data to be complete and/or valid? Semantic knowledge graphs without a shared notion of completeness and validity quickly turn into a Big Ball of Data Mud.
The Shapes Constraint Language (SHACL), an upcoming W3C standard, promises to help solve this problem. By keeping semantics separate from validity, SHACL makes it possible to resolve a slew of data quality and data exchange issues.
Presented at the Lotico Berlin Semantic Web Meetup.
Comparison of features between ShEx (Shape Expressions) and SHACL (Shapes Constraint Language)
Changelog:
11/06/17
- Removed slides about compositionality
31/May/2017
- Added slide 30 about validation report
- Added slide 32 about stems
- Changed slides 7 and 8 adapting compact syntax to new operator .
23/05/2017:
Slide 14: Repaired typos in typos in sh:entailment, rdfs:range
21/05/2017:
- Slide 8. Changed the example to be an IRI and a datatype
- Added typically in slide 9
- Slide 10: Removed the phrase: "Target declarations can problematic when reusing/importing shapes"
and created slide 27 to talk about reuability
- Added slide 11 to talk about the differences in triggering validation
- Created slide 14 to talk about inference
- Renamed slide 15 as "Inference and triggering mechanism"
- Added slides 27 and 28 to talk about reuability
- Added slide 29 to talk about annotations
18/05/2017
- Slides 9 now includes an example using ShEx RDF vocabulary
- Slide 10 now says that target declarations are optional
- Slide 13 now says that some RDF Schema terms have special treatment in SHACL
- Example in slide 18 now uses sh:or instead of sh:and
- Added slides 22, 23 and 24 which show some features supported by SHACL but not supported by ShEx (property pair constraints, uniqueLang and owl:imports)
Understanding RDF: the Resource Description Framework in Context (1999)Dan Brickley
Dan Brickley, 3rd European Commission Metadata Workshop, Luxemburg, April 12th 1999
Understanding RDF: the Resource Description Framework in Context
http://ilrt.org/discovery/2001/01/understanding-rdf/
RDF is a general method to decompose knowledge into small pieces, with some rules about the semantics or meaning of those pieces. The point is to have a method so simple that it can express any fact, and yet so structured that computer applications can do useful things with knowledge expressed in RDF.
OWL stands for Web Ontology Language
OWL is built on top of RDF
OWL is for processing information on the web
OWL was designed to be interpreted by computers
OWL was not designed for being read by people
OWL is written in XML
OWL has three sublanguages
- OWL Lite , OWL DL , OWL Full
OWL is a W3C standard
Although RDF is a corner stone of semantic web and knowledge graphs, it has not been embraced by everyday programmers and software architects who need to safely create and access well-structured data. There is a lack of common tools and methodologies that are available in more conventional settings to improve data quality by defining schemas that can later be validated. Two technologies have recently been proposed for RDF validation: Shape Expressions (ShEx) and Shapes Constraint Language (SHACL). In the talk, we will review the history and motivation of both technologies. We will also and enumerate some challenges and future work with regards to RDF validation.
Two graph data models : RDF and Property Graphsandyseaborne
Talk given at ApacheConEU Big Data 2015.
This talk describes the two common graph data approaches, RDF and Property Graphs. It concludes with observations about the different emphasis of each and where each is focused.
Semantic Web technologies (such as RDF and SPARQL) excel at bringing together diverse data in a world of independent data publishers and consumers. Common ontologies help to arrive at a shared understanding of the intended meaning of data.
However, they don’t address one critically important issue: What does it mean for data to be complete and/or valid? Semantic knowledge graphs without a shared notion of completeness and validity quickly turn into a Big Ball of Data Mud.
The Shapes Constraint Language (SHACL), an upcoming W3C standard, promises to help solve this problem. By keeping semantics separate from validity, SHACL makes it possible to resolve a slew of data quality and data exchange issues.
Presented at the Lotico Berlin Semantic Web Meetup.
Comparison of features between ShEx (Shape Expressions) and SHACL (Shapes Constraint Language)
Changelog:
11/06/17
- Removed slides about compositionality
31/May/2017
- Added slide 30 about validation report
- Added slide 32 about stems
- Changed slides 7 and 8 adapting compact syntax to new operator .
23/05/2017:
Slide 14: Repaired typos in typos in sh:entailment, rdfs:range
21/05/2017:
- Slide 8. Changed the example to be an IRI and a datatype
- Added typically in slide 9
- Slide 10: Removed the phrase: "Target declarations can problematic when reusing/importing shapes"
and created slide 27 to talk about reuability
- Added slide 11 to talk about the differences in triggering validation
- Created slide 14 to talk about inference
- Renamed slide 15 as "Inference and triggering mechanism"
- Added slides 27 and 28 to talk about reuability
- Added slide 29 to talk about annotations
18/05/2017
- Slides 9 now includes an example using ShEx RDF vocabulary
- Slide 10 now says that target declarations are optional
- Slide 13 now says that some RDF Schema terms have special treatment in SHACL
- Example in slide 18 now uses sh:or instead of sh:and
- Added slides 22, 23 and 24 which show some features supported by SHACL but not supported by ShEx (property pair constraints, uniqueLang and owl:imports)
Understanding RDF: the Resource Description Framework in Context (1999)Dan Brickley
Dan Brickley, 3rd European Commission Metadata Workshop, Luxemburg, April 12th 1999
Understanding RDF: the Resource Description Framework in Context
http://ilrt.org/discovery/2001/01/understanding-rdf/
RDF is a general method to decompose knowledge into small pieces, with some rules about the semantics or meaning of those pieces. The point is to have a method so simple that it can express any fact, and yet so structured that computer applications can do useful things with knowledge expressed in RDF.
OWL stands for Web Ontology Language
OWL is built on top of RDF
OWL is for processing information on the web
OWL was designed to be interpreted by computers
OWL was not designed for being read by people
OWL is written in XML
OWL has three sublanguages
- OWL Lite , OWL DL , OWL Full
OWL is a W3C standard
Although RDF is a corner stone of semantic web and knowledge graphs, it has not been embraced by everyday programmers and software architects who need to safely create and access well-structured data. There is a lack of common tools and methodologies that are available in more conventional settings to improve data quality by defining schemas that can later be validated. Two technologies have recently been proposed for RDF validation: Shape Expressions (ShEx) and Shapes Constraint Language (SHACL). In the talk, we will review the history and motivation of both technologies. We will also and enumerate some challenges and future work with regards to RDF validation.
Two graph data models : RDF and Property Graphsandyseaborne
Talk given at ApacheConEU Big Data 2015.
This talk describes the two common graph data approaches, RDF and Property Graphs. It concludes with observations about the different emphasis of each and where each is focused.
This is a lecture note #10 for my class of Graduate School of Yonsei University, Korea.
It describes SPARQL to retrieve and manipulate data stored in Resource Description Framework format
This presentation looks in detail at SPARQL (SPARQL Protocol and RDF Query Language) and introduces approaches for querying and updating semantic data. It covers the SPARQL algebra, the SPARQL protocol, and provides examples for reasoning over Linked Data. We use examples from the music domain, which can be directly tried out and ran over the MusicBrainz dataset. This includes gaining some familiarity with the RDFS and OWL languages, which allow developers to formulate generic and conceptual knowledge that can be exploited by automatic reasoning services in order to enhance the power of querying.
Compare and contrast RDF triple stores and NoSQL: are triples stores NoSQL or not?
Talk given 2011-09-08 tot he BigData/NoSQL meetup at Bristol University.
A practical guide on how to query and visualize Linked Open Data with eea.daviz Plone add-on.
In this presentation you will get an introduction to Linked Open Data and where it is applied. We will see how to query this large open data cloud over the web with the language SPARQL. We will then go through real examples and create interactive and live data visualizations with full data tracebility using eea.sparql and eea.daviz.
Presented at the PLOG2013 conference http://www.coactivate.org/projects/plog2013
SuRF is an Object - RDF Mapper based on the popular rdflib python library. It exposes the RDF triple sets as sets of resources and seamlessly integrates them into the Object Oriented paradigm of python in a similar manner as ActiveRDF does for ruby.
Although RDF can be considered the corner stone of semantic web and knowledge graphs, it has not been embraced by everyday programmers and software architects who want to safely create and access well-structured data. There is a lack of common tools and methodologies that are available in more conventional settings to improve data quality by defining schemas that can later be validated. Two technologies have recently been proposed for RDF validation: Shape Expressions (ShEx) and Shapes Constraint Language (SHACL). In the talk, we will briefly introduce both technologies using some examples and compare them. We will also present some challenges and applications related with RDF data shapes.
Talk given at: KTH Royal Institute of Technology, School of Industrial Engineering and Management, Mechatronics Division, 7th February, 2020
Como publicar los datos: datos abiertos y enlazados
Charla impartida en Jornadas Open Data y Transparencia: Ayuntamiento de Oviedo
11 de septiembre de 2017
Charla Linked data - Datos abiertos enlazados impartida en el IV Foro Distrital Buenas Prácticas en Gestión de la Información Geográfica - Bogotá, Colombia, 14 Diciembre 2015
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC
Ellisha Heppner, Grant Management Lead, presented an update on APNIC Foundation to the PNG DNS Forum held from 6 to 10 May, 2024 in Port Moresby, Papua New Guinea.
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBrad Spiegel Macon GA
Brad Spiegel Macon GA’s journey exemplifies the profound impact that one individual can have on their community. Through his unwavering dedication to digital inclusion, he’s not only bridging the gap in Macon but also setting an example for others to follow.
# Internet Security: Safeguarding Your Digital World
In the contemporary digital age, the internet is a cornerstone of our daily lives. It connects us to vast amounts of information, provides platforms for communication, enables commerce, and offers endless entertainment. However, with these conveniences come significant security challenges. Internet security is essential to protect our digital identities, sensitive data, and overall online experience. This comprehensive guide explores the multifaceted world of internet security, providing insights into its importance, common threats, and effective strategies to safeguard your digital world.
## Understanding Internet Security
Internet security encompasses the measures and protocols used to protect information, devices, and networks from unauthorized access, attacks, and damage. It involves a wide range of practices designed to safeguard data confidentiality, integrity, and availability. Effective internet security is crucial for individuals, businesses, and governments alike, as cyber threats continue to evolve in complexity and scale.
### Key Components of Internet Security
1. **Confidentiality**: Ensuring that information is accessible only to those authorized to access it.
2. **Integrity**: Protecting information from being altered or tampered with by unauthorized parties.
3. **Availability**: Ensuring that authorized users have reliable access to information and resources when needed.
## Common Internet Security Threats
Cyber threats are numerous and constantly evolving. Understanding these threats is the first step in protecting against them. Some of the most common internet security threats include:
### Malware
Malware, or malicious software, is designed to harm, exploit, or otherwise compromise a device, network, or service. Common types of malware include:
- **Viruses**: Programs that attach themselves to legitimate software and replicate, spreading to other programs and files.
- **Worms**: Standalone malware that replicates itself to spread to other computers.
- **Trojan Horses**: Malicious software disguised as legitimate software.
- **Ransomware**: Malware that encrypts a user's files and demands a ransom for the decryption key.
- **Spyware**: Software that secretly monitors and collects user information.
### Phishing
Phishing is a social engineering attack that aims to steal sensitive information such as usernames, passwords, and credit card details. Attackers often masquerade as trusted entities in email or other communication channels, tricking victims into providing their information.
### Man-in-the-Middle (MitM) Attacks
MitM attacks occur when an attacker intercepts and potentially alters communication between two parties without their knowledge. This can lead to the unauthorized acquisition of sensitive information.
### Denial-of-Service (DoS) and Distributed Denial-of-Service (DDoS) Attacks
1.Wireless Communication System_Wireless communication is a broad term that i...JeyaPerumal1
Wireless communication involves the transmission of information over a distance without the help of wires, cables or any other forms of electrical conductors.
Wireless communication is a broad term that incorporates all procedures and forms of connecting and communicating between two or more devices using a wireless signal through wireless communication technologies and devices.
Features of Wireless Communication
The evolution of wireless technology has brought many advancements with its effective features.
The transmitted distance can be anywhere between a few meters (for example, a television's remote control) and thousands of kilometers (for example, radio communication).
Wireless communication can be used for cellular telephony, wireless access to the internet, wireless home networking, and so on.
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesSanjeev Rampal
Talk presented at Kubernetes Community Day, New York, May 2024.
Technical summary of Multi-Cluster Kubernetes Networking architectures with focus on 4 key topics.
1) Key patterns for Multi-cluster architectures
2) Architectural comparison of several OSS/ CNCF projects to address these patterns
3) Evolution trends for the APIs of these projects
4) Some design recommendations & guidelines for adopting/ deploying these solutions.
This 7-second Brain Wave Ritual Attracts Money To You.!nirahealhty
Discover the power of a simple 7-second brain wave ritual that can attract wealth and abundance into your life. By tapping into specific brain frequencies, this technique helps you manifest financial success effortlessly. Ready to transform your financial future? Try this powerful ritual and start attracting money today!
2. Jose Emilio Labra Gayo – Universidad de Oviedo
SPARQL
SPARQL (April 2006) query language for RDF data
Similar to SQL, but for RDF
Based on graph patterns
It also describes a REST protocol
SPARQL = SPARQL Protocol And RDF Query Language
SPARQL 1.1 (2013, recommendation)
Updates, federated queries, etc.
3. Jose Emilio Labra Gayo – Universidad de Oviedo
SPARQL Syntax
Similar to Turtle
URIs between <...>
<http://www.example.org/alice>
Namespace prefixes as in Turtle
prefix dc: <http://purl.org/dc/terms/>
dc:creator
Blank nodes
_:node or between square brackets [ ]
Literals between " "
"Alice" "234"^^xsd:integer
Comments start by #
# this is a comment
Variables start by?
?name
6. Jose Emilio Labra Gayo – Universidad de Oviedo
Simple SPARQL query
Search resources created by a Lecturer and order them
by lecturer
prefix dc: <http://purl.org/dc/terms/>
prefix uni: <http://uniovi.es/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?p ?c WHERE {
?p dc:creator ?c .
?c rdf:type uni:Lecturer .
}
ORDER BY ?c
8. Jose Emilio Labra Gayo – Universidad de Oviedo
Playing with SPARQL
Command line tools:
Apache Jena. https://jena.apache.org/
Online:
SHACLex: can be used without endpoint
http://shaclex.herokuapp.com/
YASGUI: can be used to query existing SPARQL endpoints
http://yasgui.org/
Creating SPARQL endpoints
Apache Jena Fuseki: https://jena.apache.org/
Blazegraph: https://www.blazegraph.com/
9. Jose Emilio Labra Gayo – Universidad de Oviedo
Some public SPARQL endpoints
Name URL Description
SPARQLer http://www.sparql.org/sparql.html General purpose query
endpoint
DBpedia http://dbpedia.org/sparql RDF data from wikipedia
Wikidata https://query.wikidata.org/ RDF data from Wikipedia
DBLP http://dblp.rkbexplorer.com/sparql/ Bibliographic data
LinkedMDB http://data.linkedmdb.org/sparql Movie database
bio2rdf http://bio2rdf.org/sparql Linked data for life sciences
List of SPARQL endpoints:
https://www.w3.org/wiki/SparqlEndpoints
10. Jose Emilio Labra Gayo – Universidad de Oviedo
SPARQL query language
11. Jose Emilio Labra Gayo – Universidad de Oviedo
Parts of a query
prefix dc: <...>
prefix uni: <...>
SELECT ...
FROM <...>
FROM NAMED <...>
WHERE {
...
}
ORDER BY ...
HAVING ...
GROUP BY ...
LIMIT ...
OFFSET ...
BINDINGS ...
Graph Pattern
Query modifiers
Prefix declarations
Define dataset
Declare type of query
SELECT, ASK, DESCRIBE, CONSTRUCT
12. Jose Emilio Labra Gayo – Universidad de Oviedo
Prefix declarations
Similar to Turtle
No need to use @prefix, just prefix
No need to end prefix declarations by dot
Common aliases used in these slides:
alias... stands for...
rdf <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
rdfs <http://www.w3.org/2000/01/rdf-schema#>
owl <http://www.w3.org/2002/07/owl#>
xsd <http://www.w3.org/2001/XMLSchema#>
schema <http://schema.org/>
Other common prefixes can be found at: http://prefix.cc
13. Jose Emilio Labra Gayo – Universidad de Oviedo
Parts of a query
prefix dc: <...>
prefix uni: <...>
SELECT ...
FROM <...>
FROM NAMED <...>
WHERE {
...
}
ORDER BY ...
HAVING ...
GROUP BY ...
LIMIT ...
OFFSET ...
BINDINGS ...
Declare type of query
SELECT, ASK, DESCRIBE, CONSTRUCT
Graph Pattern
Query modifiers
Prefix declarations
Define dataset
14. Jose Emilio Labra Gayo – Universidad de Oviedo
Types of SPARQL queries
SELECT return values of variables or expressions
Results are a table of values
Can have several serializations: XML, JSON
ASK return true/false
DESCRIBE return a description of a resource
CONSTRUCT queries can build RDF triples/graphs
15. Jose Emilio Labra Gayo – Universidad de Oviedo
SELECT queries
@prefix : <http://example.org/>.
:alice :name "Alice" ;
:age 31 .
:bob :name "Robert" ;
:age 31 .
SELECT ?n (?age + 1 as ?newAge) WHERE {
?x :name ?n ; :age ?age
}
Project out specific variables or expressions
---------------------
| n | newAge |
=====================
| "Alice" | 32 |
| "Robert" | 32 |
---------------------
SELECT * WHERE {
?x :name ?n ; :age ?age
}
Project out all variables
---------------------------
| x | n | age |
===========================
| :alice | "Alice" | 31 |
| :bob | "Robert" | 31 |
---------------------------
Project out distinct combinations only
SELECT DISTINCT ?age WHERE {
?x :name ?n ; :age ?age
}
-------
| age |
=======
| 31 |
-------
16. Jose Emilio Labra Gayo – Universidad de Oviedo
CONSTRUCT queries
Construct an RDF result
Can be used to transform RDF data
@prefix : <http://example.org/>.
:alice :name "Alice" ;
:age 31 .
:bob :name "Robert" ;
:age 31 .
PREFIX : <http://example.org/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
CONSTRUCT {
?x foaf:name ?name ;
foaf:age ?age
} where {
?x :name ?name ;
:age ?age
}
@prefix : <http://example.org/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
:alice foaf:age 31 ;
foaf:name "Alice" .
:bob foaf:age 31 ;
foaf:name "Robert" .
Result
17. Jose Emilio Labra Gayo – Universidad de Oviedo
ASK queries
ASK return yes or no
Can be used to check errors
Yes
@prefix : <http://example.org/>.
:alice :name "Alice" ;
:age 31 .
:bob :name "Robert" ;
:age 31 .
PREFIX : <http://example.org/>
ASK WHERE {
?x :age ?age
FILTER (?age > 18)
}
Result
18. Jose Emilio Labra Gayo – Universidad de Oviedo
DESCRIBE
Return a description of one or more nodes
@prefix : <http://example.org/>
.
:alice :age 31 ;
:name "Alice" .
PREFIX : <http://example.org/>
DESCRIBE ?x WHERE {
?x :name "Alice" .
}
@prefix : <http://example.org/>.
:alice :name "Alice" ;
:age 31 .
:bob :name "Robert" ;
:age 31 .
Result
19. Jose Emilio Labra Gayo – Universidad de Oviedo
Parts of a query
prefix dc: <...>
prefix uni: <...>
SELECT ...
FROM <...>
FROM NAMED <...>
WHERE {
...
}
ORDER BY ...
HAVING ...
GROUP BY ...
LIMIT ...
OFFSET ...
BINDINGS ...
Graph Pattern
Query modifiers
Prefix declarations
Define dataset
Declare type of query
SELECT, ASK, DESCRIBE, CONSTRUCT
20. Jose Emilio Labra Gayo – Universidad de Oviedo
Define dataset using FROM
FROM declares the URL from which the data is queried
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?n
FROM <http://www.di.uniovi.es/~labra/labraFoaf.rdf>
WHERE { ?x foaf:name ?n }
If several data graphs are declared, they are merged
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?n
FROM <http://www.di.uniovi.es/~labra/labraFoaf.rdf>
FROM <http://www.w3.org/People/Berners-Lee/card>
WHERE {
?x foaf:name ?n
}
-----------------------------------
| n |
===================================
| "Jose Manuel Alonso Cienfuegos" |
| "Timothy Berners-Lee" |
| "Ivan Herman" |
| "Jose Emilio Labra Gayo" |
-----------------------------------
-----------------------------------
| n |
===================================
| "Jose Manuel Alonso Cienfuegos" |
| "Ivan Herman" |
| "Jose Emilio Labra Gayo" |
-----------------------------------
21. Jose Emilio Labra Gayo – Universidad de Oviedo
Named graphs
FROM NAMED asigns a name to the input graph
GRAPH matches with the corresponding graph name
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?n ?g
FROM NAMED <http://www.w3.org/People/Berners-Lee/card>
FROM NAMED <http://www.di.uniovi.es/~labra/labraFoaf.rdf>
WHERE {
GRAPH ?g { ?x foaf:name ?n }
}
------------------------------------------------------------------------------------
| n | g |
====================================================================================
| "Ivan Herman" | <http://www.di.uniovi.es/~labra/labraFoaf.rdf> |
| "Jose Manuel Alonso Cienfuegos" | <http://www.di.uniovi.es/~labra/labraFoaf.rdf> |
| "Jose Emilio Labra Gayo" | <http://www.di.uniovi.es/~labra/labraFoaf.rdf> |
| "Timothy Berners-Lee" | <http://www.w3.org/People/Berners-Lee/card> |
------------------------------------------------------------------------------------
22. Jose Emilio Labra Gayo – Universidad de Oviedo
Parts of a query
prefix dc: <...>
prefix uni: <...>
SELECT ...
FROM <...>
FROM NAMED <...>
WHERE {
...
}
ORDER BY ...
HAVING ...
GROUP BY ...
LIMIT ...
OFFSET ...
BINDINGS ...
Graph Pattern
Query modifiers
Prefix declarations
Define dataset
Declare type of query
SELECT, ASK, DESCRIBE, CONSTRUCT
23. Jose Emilio Labra Gayo – Universidad de Oviedo
Query patterns
Query patterns are made from triple patterns
Triple pattern = RDF triples which can contain variables
Examples of triple patterns
uni:biology dc:creator ?c resources that are dc:creator's of uni:biology
?r dc:creator :alice resources whose dc:creator is :alice
?r dc:creator ?c all resources related by dc:creator property
uni:biology ?p :alice properties that relate uni:biology with :alice
?x ?p ?y all statements
24. Jose Emilio Labra Gayo – Universidad de Oviedo
Basic graph patterns
Basic graph pattern = sequence of triple patterns
The matching process combines the values of variables
Example:
The values of variables must be the same in the results
SELECT ?p ?c WHERE {
?p dc:creator ?c .
?c rdf:type uni:Lecturer .
}
ORDER BY ?c
25. Jose Emilio Labra Gayo – Universidad de Oviedo
Basic graph patterns can have filters
FILTER limits the set of returned values
PREFIX : <http://example.org/>
SELECT ?n ?e WHERE {
?x :name ?n .
?x :age ?e
FILTER (?e > 18)
}
@prefix : <http://example.org/>.
:alice :name "Alice" .
:alice :age 31 .
:bob :name "Robert" .
:bob :age 12 .
:carol :name "Carol" .
:carol :age 25 .
| n | e |
=================
| "Carol" | 25 |
| "Alice" | 31 |
Try it: https://tinyurl.com/y8odenvm
27. Jose Emilio Labra Gayo – Universidad de Oviedo
Convert/create datatypes
str(arg): converts its argument to a string
NOTE: URIs must be converted to strings to treat them as such
datatype(arg): returns datatype of a literal
IF ?x = "123"^^xsd:integer
THEN datatype(?x) = xsd:integer
lang(arg): returns the language of a literal
IF ?x = "University"@en
THEN: lang(?x) = "en"
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?label WHERE {
?x rdfs:label ?label .
FILTER (lang(?label) ="en")
}
Example
Try it: https://tinyurl.com/y8m3xlyg
28. Jose Emilio Labra Gayo – Universidad de Oviedo
Create datatypes
uri(arg), iri(arg): convert their argument to URI/IRI
bnode(arg): generates a blank node
strdt(literal,datatype): generates a literal with a
datatype
strdt("123","xsd:integer") = "123"^^<xsd:integer>
strlang(literal,lang): generates a literal with some
language
strlang("University","en") = "University"@"en"
29. Jose Emilio Labra Gayo – Universidad de Oviedo
Check datatypes
isNumeric(arg) = true if the argument is a number
isBlank(arg) = true if the argumento is a blank node
isLiteral(arg) = true if the argument is a literal
isIRI(arg) = true if the argument is an IRI
30. Jose Emilio Labra Gayo – Universidad de Oviedo
Conditions
bound(arg) = true if the argument has a value
exists(pattern) = true if the pattern is satisfied
not exists(pattern) = true si if the pattern is not satisfied
if(cond,expr1,expr2) = if cond = true, returns expr1,
otherwise, returns expr2
coalesce(e1,e2,...) = returns the first expression that is
evaluated without error
32. Jose Emilio Labra Gayo – Universidad de Oviedo
Functions with strings
strlen(str) = length of str
ucase(str) converts to uppercase
lcase(str) converts to lowercase
substr(str,start,size?)= substring from start with some size
substr('camino',3,2)='mi'
strstarts(str1,str2) = true if str1 starts with str2
strends(str1,str2) = true if str1 ends with str2
contains(str1,str2) = true if str1 contains str2
encode_for_uri(str) = result of encoding str as a uri
concat(str1,...strN) = concatenates strings
langMatches(str,lang) = true if a string matches some language lang
regex(str,p,flags) = true if string matches regular expression p with flags
34. Jose Emilio Labra Gayo – Universidad de Oviedo
Regex
REGEX invokes regular expression matching
It is based on XPath 2.0 functions
regex(?Expr, ?Pattern [, ?Flags])
?Expr = expression to match
?Pattern = regular expression pattern
?Flags = matching options
Try it: https://tinyurl.com/yd29xsyz
@prefix : <http://example.org/>.
:alice :firstName "Alice" ;
:lastName "Cooper" .
:bob :firstName "Robert" ;
:lastName "Smith" .
:carol :firstName "Carol" ;
:lastName "King" .
PREFIX : <http://example.org/>
SELECT ?firstName WHERE {
?x :firstName ?firstName .
FILTER (regex(?firstName,"^[ABC](.*)"))
} -------------
| firstName |
=============
| "Alice" |
| "Carol" |
-------------
35. Jose Emilio Labra Gayo – Universidad de Oviedo
Regex
Regular expressions
^ = start of string
$ = end of string
. = any character
d = dígit
? = optional, * = 0 or more, + = 1 or more
X{n} = matches X n times
X{m,n} = matches X from m to n times
Flags:
i = ignore case
m = multiple lines
s = simple line
x = removes white spaces
36. Jose Emilio Labra Gayo – Universidad de Oviedo
Numeric functions
abs(n) = absolute value
round(n) = rounds a number n
floor(n) = rounds n down
ceil(n) = rounds n up
rand() = random number between 0 y 1
37. Jose Emilio Labra Gayo – Universidad de Oviedo
Functions with dates
now() = returns current instant
year(i) = returns the year of some instant i
year("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime) = 2011
month(i), day(i), hours(i), minutes(i), seconds(i), timezone(i), tz(i) =
similar but return other components
@prefix : <http://example.org/> .
:alice :age 23 ;
:name "Alice" .
:bob :age 20 ;
:name "Robert" .
PREFIX : <http://example.org/>
SELECT (year(now()) - ?age as ?birthYear) WHERE {
?x :age ?age .
}
-------------
| birthYear |
=============
| 1994 |
| 1997 |
-------------
38. Jose Emilio Labra Gayo – Universidad de Oviedo
HASH functions
md5(str) = applies MD5 algorithm to a str
sha1(str), sha224(str),sha256(str),sha384(str),
sha512(str) = compute hash of str using the
corresponding variations of SHA algorithm
PREFIX : <http://example.org/>
SELECT ?name
(SHA1(?email) AS ?sha1Email)
WHERE {
?x :name ?name .
?x :email ?email .
}
@prefix : <http://example.org/> .
:alice :name "Alice" ;
:email "alice@email.com" .
:bob :name "Robert" ;
:email "bob@example.com" .
---------------------------------------------------------
| name | sha1Email |
=========================================================
| "Alice" | "14bf670833d4d7daca31afce1011752c80691459" |
| "Robert" | "a460e37bf4d8e893f8fd39536997d5da8d21eebe" |
---------------------------------------------------------
39. Jose Emilio Labra Gayo – Universidad de Oviedo
@prefix : <http://example.org/>.
:alice :name "Alice" ;
:age 23 .
:bob :firstName "Robert" ;
:age 20 .
Graph union
UNION combines results from several graphs
PREFIX : <http://example.org/>
SELECT ?n WHERE {
{ ?x :name ?n }
UNION
{ ?y :firstName ?n }
}
------------
| n |
============
| "Alice" |
| "Robert" |
------------
40. Jose Emilio Labra Gayo – Universidad de Oviedo
Optional
OPTIONAL allows to define triples which match
information if exists, but don't fail if it doesn't exist
@prefix : <http://example.org/>.
:alice :name "Alice" ;
:age 23 .
:bob :name "Robert" .
:carol :name "Carol" ;
:age 33 .
PREFIX : <http://example.org/>
SELECT ?name ?age WHERE {
?x :name ?name .
?x :age ?age
}
PREFIX : <http://example.org/>
SELECT ?name ?age WHERE {
?x :name ?name
OPTIONAL { ?x :age ?age }
}
-----------------
| name | age |
=================
| "Alice" | 23 |
| "Carol" | 33 |
-----------------
------------------
| name | age |
==================
| "Alice" | 23 |
| "Robert" | |
| "Carol" | 33 |
------------------
without optional
with optional
41. Jose Emilio Labra Gayo – Universidad de Oviedo
Minus
Removes solutions that are compatible with a pattern
@prefix : <http://example.org/>.
:alice :name "Alice" ;
:age 23 .
:bob :name "Robert" .
:carol :name "Carol" ;
:age 33 .
prefix : <http://example.org/>
SELECT ?name WHERE {
?x :name ?name
MINUS {
?x :age 33
}
}
------------
| name |
============
| "Alice" |
| "Robert" |
------------
42. Jose Emilio Labra Gayo – Universidad de Oviedo
Parts of a query
prefix dc: <...>
prefix uni: <...>
SELECT ...
FROM <...>
FROM NAMED <...>
WHERE {
...
}
ORDER BY ...
HAVING ...
GROUP BY ...
LIMIT ...
OFFSET ...
BINDINGS ...
Graph Pattern
Query modifiers
Prefix declarations
Define dataset
Declare type of query
SELECT, ASK, DESCRIBE, CONSTRUCT
43. Jose Emilio Labra Gayo – Universidad de Oviedo
Query modifiers
DISTINCT removes duplicate results
ORDER BY specifies the order of results (ASC, DESC…)
LIMIT n limits the number of results
OFFSET m declares from which result to start
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?n
WHERE {
?x foaf:knows ?y .
?y foaf:name ?n .
}
ORDER BY ASC(?n)
LIMIT 5
OFFSET 2
44. Jose Emilio Labra Gayo – Universidad de Oviedo
Bindings
BIND expr AS v = Asigns value of expr to variable v
@prefix : <http://example.org/>.
:apples :name "Apples" ;
:amount 3 ;
:price 3 .
:oranges :name "Oranges" ;
:amount 4 ;
:price 2 .
prefix : <http://example.org/>
SELECT ?name ?totalPrice
WHERE {
?x :name ?name ;
:amount ?amount ;
:price ?price .
BIND ((?amount * ?price) AS ?totalPrice)
}
--------------------------
| name | totalPrice |
==========================
| "Oranges" | 8 |
| "Apples" | 9 |
--------------------------
45. Jose Emilio Labra Gayo – Universidad de Oviedo
Bindings in SELECT clause
It is possible to do the binding directly in the SELECT
@prefix : <http://example.org/>.
:apples :name "Apples" ;
:amount 3 ;
:price 3 .
:oranges :name "Oranges" ;
:amount 4 ;
:price 2 .
prefix : <http://example.org/>
SELECT ?name
((?amount * ?price) AS ?totalPrice)
WHERE {
?x :name ?name ;
:amount ?amount ;
:price ?price .
}
--------------------------
| name | totalPrice |
==========================
| "Oranges" | 8 |
| "Apples" | 9 |
--------------------------
46. Jose Emilio Labra Gayo – Universidad de Oviedo
Aggregation functions:
AVG, SUM, COUNT, SAMPLE
@prefix : <http://example.org/>.
:alice :name "Alice" ;
:age 23 .
:bob :name "Robert" ;
:age 25 .
:carol :name "Carol" ;
:age 33 .
PREFIX : <http://example.org/>
SELECT (AVG(?age) AS ?average)
(SUM(?age) AS ?sum)
(COUNT(?age) AS ?count)
(SAMPLE(?age) AS ?sample)
WHERE {
?x :age ?age .
}
----------------------------------
| average | sum | count | sample |
==================================
| 27.0 | 81 | 3 | 23 |
----------------------------------
47. Jose Emilio Labra Gayo – Universidad de Oviedo
Aggregation functions:
MAX, MIN
@prefix : <http://example.org/>.
:alice :name "Alice" ;
:age 23 .
:bob :name "Robert" ;
:age 25 .
:carol :name "Carol" ;
:age 33 .
PREFIX : <http://example.org/>
SELECT (MAX(?age) AS ?max)
(MIN(?age) AS ?min)
WHERE {
?x :age ?age .
}
-----------------
| max | min |
=================
| 33 | 23 |
-----------------
52. Jose Emilio Labra Gayo – Universidad de Oviedo
Property paths
Properties can use a path (similar to regular expressions)
p Match property p
(e) Path grouped in parenthesis
^e Inverse path e
!p Doesn't match property p
e1 / e2 Path e1 followed by e2
e1 | e2 Path e1 or e2
e* 0 or more e
e+ 1 or more e
e? 0 or 1 e
58. Jose Emilio Labra Gayo – Universidad de Oviedo
Graph operations
Update
INSERT DATA = insert triples
DELETE/INSERT… = delete/insert triples conditionally
DELETE DATA = delete triples
LOAD = load triples from a uri
CLEAR = delete all triples from a graph
Graph management
CREATE = create named graph
DROP = drop graph
COPY…TO… = copy graph
MOVE…TO… = move graph
ADD = insert all elements from a graph in another one
59. Jose Emilio Labra Gayo – Universidad de Oviedo
Insert
INSERT DATA can be used to insert triples
prefix : <http://example.org/>.
prefix foaf: <http://xmlns.com/foaf/0.1/>.
INSERT DATA {
:ana foaf:name "Ana" ;
foaf:age 18 ;
:salary 1500 .
:bob foaf:name "Robert" ;
foaf:age 20 ;
:salary 2000 .
}
60. Jose Emilio Labra Gayo – Universidad de Oviedo
Insert in a graph
INSERT DATA into a named graph
prefix : <http://example.org/>
prefix foaf: <http://xmlns.com/foaf/0.1/>
INSERT DATA {
GRAPH <http://example.org/graph1> {
:alice foaf:name "Alice" ;
foaf:age 18 ;
:salary 1500 .
}
}
61. Jose Emilio Labra Gayo – Universidad de Oviedo
Insert
INSERT can insert triples in a graph
Requires the WHERE clause
PREFIX : <http://example.org/>
INSERT {
?p :value "GoodSalary".
} WHERE {
?p :salary ?salary .
FILTER (?salary >= 4000)
}
62. Jose Emilio Labra Gayo – Universidad de Oviedo
Graph load
LOAD uri = loads all triples from a graph available at uri
LOAD <http://www.di.uniovi.es/~labra/labraFoaf.rdf>
63. Jose Emilio Labra Gayo – Universidad de Oviedo
Delete data
DELETE DATA removes all triples in a graph
PREFIX : <http://example/org/>
DELETE DATA {
:alice :age 18 .
}
NOTA: DELETE DATA does not allow variables
64. Jose Emilio Labra Gayo – Universidad de Oviedo
Delete...where
DELETE WHERE removes triples in a graph specifying a
condition
PREFIX : <http://example.org/>
DELETE {
?x :age ?age .
} WHERE {
?x :age ?age .
FILTER (?age >= 60)
}
65. Jose Emilio Labra Gayo – Universidad de Oviedo
Updating information
DELETE/INSERT pattern can be used to update triples
in a graph
PREFIX : <http://example.org/>
DELETE { ?x :age ?age }
INSERT { ?x :age ?newAge }
WHERE {
?x :age ?age .
BIND((?age + 1) AS ?newAge)
}
Example: increment age
66. Jose Emilio Labra Gayo – Universidad de Oviedo
Deleting
CLEAR deletes all triples
It is possible to declare datasets
CLEAR g = Deletes graph g
CLEAR DEFAULT = Deletes default graph
CLEAR ALL = Deletes all graphs
67. Jose Emilio Labra Gayo – Universidad de Oviedo
Universal query
Obtain all triples in all graphs
PREFIX e: <http://ejemplo.org#>
SELECT * WHERE {
{ ?x ?p ?y . }
UNION
{ GRAPH ?g {
?x ?p ?y .
}
}
}
68. Jose Emilio Labra Gayo – Universidad de Oviedo
Remote services
SERVICE uri = Runs query from a SPARQL endpoint uri
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?name WHERE {
SERVICE <http://dbpedia.org/sparql> {
SELECT ?name WHERE {
?pais rdf:type dbo:Country .
?pais rdfs:label ?name .
FILTER (lang(?name)='es')
}
}
}
Some SPARQL endpoints:
http://esw.w3.org/topic/SparqlEndpoints
71. Jose Emilio Labra Gayo – Universidad de Oviedo
SPARQL Protocol
Defines the actions: query and update and their
parameters and their formats
query action
2 verbs: GET, POST
Parameters:
query: Encoded query
default-graph-uri: Default graph (optional)
named-graph-uri: Named graph (optional)
update action
Only POST with 3 parameters
update: Update query
using-graph-uri: Default graph (optional)
using-named-graph-uri: Named graph (optional)
72. Jose Emilio Labra Gayo – Universidad de Oviedo
Validating RDF using SPARQL?
73. Jose Emilio Labra Gayo – Universidad de Oviedo
Negation by failure pattern in SPARQL
Combining FILTER, OPTIONAL and !BOUND
Example: Search people not married
@prefix : <http://example.org/>.
:alice :isMarriedWith :Bob ;
:name "Alice" .
:bob :isMarriedWith :alice ;
:name "Robert" .
:carol :name "Carol" .
:dave :isMarriedWith :emily ;
:name "Dave" .
PREFIX : <http://example.org/>
SELECT ?n WHERE {
?x :name ?n
OPTIONAL {?x :isMarriedWith ?y }
FILTER ( !BOUND(?y) )
}
Does it really return people not married?
-----------
| n |
===========
| "Carol" |
-----------
74. Jose Emilio Labra Gayo – Universidad de Oviedo
Validating RDF with SPARQL
Example:
A person has age (integer) and one or more names (string)
Person__
foaf:age xsd:integer
foaf:name xsd:string+
:john foaf:age 23;
foaf:name "John" .
:bob foaf:age 34;
foaf:name "Bob", "Robert" .
RDF examples
:mary foaf:age 50, 65 .
75. Jose Emilio Labra Gayo – Universidad de Oviedo
Example of SPARQL query
ASK {
{ SELECT ?Person {
?Person foaf:age ?o .
} GROUP BY ?Person HAVING (COUNT(*)=1)
}
{ SELECT ?Person {
?Person foaf:age ?o .
FILTER ( isLiteral(?o) &&
datatype(?o) = xsd:integer )
} GROUP BY ?Person HAVING (COUNT(*)=1)
}
{ SELECT ?Person (COUNT(*) AS ?Person_c0) {
?Person foaf:name ?o .
} GROUP BY ?Person HAVING (COUNT(*)>=1)
}
{ SELECT ?Person (COUNT(*) AS ?Person_c1) {
?Person foaf:name ?o .
FILTER (isLiteral(?o) &&
datatype(?o) = xsd:string)
} GROUP BY ?Person HAVING (COUNT(*)>=1)
} FILTER (?Person_c0 = ?Person_c1)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Person__
foaf:age xsd:integer
foaf:name xsd:string+
76. Jose Emilio Labra Gayo – Universidad de Oviedo
Is it possible to add recursión to the model?
Example:
A person has age (integer), one or more names (string)
and knows 0 or more values which conform to person
Person__
foaf:age xsd:integer
foaf:name xsd:string+
0..*
foaf:knows
77. Jose Emilio Labra Gayo – Universidad de Oviedo
Validating RDF technologies
ShEx and SHACL can be used to validate RDF
<Person> {
foaf:age xsd:integer ;
foaf:name xsd:string+
foaf:knows @<Person>
}
Example in ShEx (see http://shex.io)
78. Jose Emilio Labra Gayo – Universidad de Oviedo
References
SPARQL by example
SPARQL by example cheatsheet
Learning SPARQL, book by Bob Ducharme
SPARQL 1.1 spec