03: SPARQL Flashcards
Main Advantages of RDF
- Is a standard model for data interchange on the Web
- Extends the linking structure of the Web to use URIs to name the relationship between things as well as the two ends of the link (e.g. a triplet)
- Facilitates data merging even if the underlying schemas differ
- Specifically supports the evolution of schemas over time without requiring all the data consumers to be changed
- Allows structured and semi-structured data to be mixed, exposed, and shared across different applications
- Is based on an extremely easy concept called “graph view” to comprehend and visualize it
Difference Between XPATH and SPARQL
- XPATH and SPARQL are for searching RDF files
- XPATH works for all XML files, including RDF
- SPARQL cannot search any XML
How does a system process a SPARQL query?
- SPARQL query uses triplet patterns, and each subject, predicate, and object can be a variable
- System finds appropriate values for these variables by matching patterns given to the triplets of the corresponding dataset
- System combines simple patterns into more complex ones
Difference Between SQL and SPARQL Queries
- SQL queries are highly related on how tables have been organized
- SPARQL
- queries focus on what users like to know
- can work on integrated queries
- can concurrently access to several endpoints (data stores)
- is based on HTTP-based transport protocol
Write the following query in SPARQL:
Get all instances of a particular class (e.g. course)
SELECT-FROM-WHERE
- Like SQL SELECT-FROM-WHERE query
- SELECT specifies the project: number and order of retrieved data
- FROM used to specify the source being queried (optional)
- WHERE imposes constraints on possible solutions in the form of graph pattern templates and boolean constraints
Write the following query in SPARQL:
Retrieve all phone numbers of staff members
(SELECT-FROM-WHERE)
SELECT ?x ?y
WHERE
{?x uni:phone ?y .}
(where ?x and ?y are variables, and ?x uni:phone ?y represents a resource-pattern-value triple pattern
Implicit Join
Restricting the second pattern only to those triples, the resource of which is the variable ?x
i.e. Retrieve all lecturers and their phone numbers
SELECT ?x ?y
WHERE {
?x rdf:type uni:Lecturer .
?x uni:phone ?y .
}
Syntax Shortcut in SPARQL
;
A semicolon indicates that the triplet shares its subject with the previous one
i.e. Retrieve all lecturers and their phone numbers
SELECT ?x ?y
WHERE {
?x rdf:type uni:Lecturer ;
uni:phone ?y .
}
is the same as
SELECT ?x ?y
WHERE {
?x rdf:type uni:Lecturer .
?x uni:phone ?y .
}
Write the following query in SPARQL:
Retrieve all lecturers and their phone numbers
(IMPLICIT JOIN)
SELECT ?x ?y
WHERE
{ ?x rdf:type uni:Lecturer ;
uni:phone ?y .}
Write the following query in SPARQL:
Retrieve the name of all courses taught by the lecturer with ID 949352
(EXPLICIT JOIN)
SELECT ?n
WHERE
{ ?x rdf:type uni:Course;
uni:isTaughtBy :949352
?x uni:name ?n .}
Write the following query in SPARQL:
Retrieve the names of lecturers, and if known, also their email address
(OPTIONAL PATTERNS)
SELECT ?name ?email
WHERE
{
?x rdf:type uni:Lecturer ;
uni:name ?name.
OPTIONAL { x? uni:email ?email }
}
Write the following query in SPARQL:
Retrieve the names and emails of every person in the dataset
Write the following query in SPARQL:
Write all the capitals of the countries in Africa
What are the main issues which help developers lower their development cost with respect to using RDF and SPARQL?
- The explicitness of queries
- The techniques used for the fast execution of queries employed by SPARQL
- The flexibility of RDF
- The capability of merging results from multiple data sources in SPARQL