03: SPARQL Flashcards

1
Q

Main Advantages of RDF

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Difference Between XPATH and SPARQL

A
  • XPATH and SPARQL are for searching RDF files
    • XPATH works for all XML files, including RDF
    • SPARQL cannot search any XML
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does a system process a SPARQL query?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Difference Between SQL and SPARQL Queries

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Write the following query in SPARQL:

Get all instances of a particular class (e.g. course)

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

SELECT-FROM-WHERE

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Write the following query in SPARQL:

Retrieve all phone numbers of staff members

(SELECT-FROM-WHERE)

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Implicit Join

A

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 .

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Syntax Shortcut in SPARQL

A

;

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 .

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Write the following query in SPARQL:

Retrieve all lecturers and their phone numbers

(IMPLICIT JOIN)

A

SELECT ?x ?y

WHERE

{ ?x rdf:type uni:Lecturer ;

uni:phone ?y .}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Write the following query in SPARQL:

Retrieve the name of all courses taught by the lecturer with ID 949352

(EXPLICIT JOIN)

A

SELECT ?n

WHERE

{ ?x rdf:type uni:Course;

uni:isTaughtBy :949352

?x uni:name ?n .}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Write the following query in SPARQL:

Retrieve the names of lecturers, and if known, also their email address

(OPTIONAL PATTERNS)

A

SELECT ?name ?email

WHERE

{

?x rdf:type uni:Lecturer ;

uni:name ?name.

OPTIONAL { x? uni:email ?email }

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Write the following query in SPARQL:

Retrieve the names and emails of every person in the dataset

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Write the following query in SPARQL:

Write all the capitals of the countries in Africa

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the main issues which help developers lower their development cost with respect to using RDF and SPARQL?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the results of these two queries based on the data set with 3 RDF literals?

SELECT ?v WHERE { ?v ?p “cat”@en. }

and

SELECT ?v WHERE { ?v ?p 42 }

A

v

http://example.org/ns#x

and

v

http://example.org/ns#y

(**but with pointy brackets on each but brainscape sucks and won’t let me make tags)

17
Q

In an RDF dataset, what does “_:” represent?

A

blank nodes

18
Q

Based on the RDF data set, what is the result of the following query?

PREFIX foaf: http://xmlns.com/foaf/0.1

SELECT ?name ?mbox WHERE

{

?x foaf:name ?name .

?x foaf:mbox ?mbox .

}

A
19
Q

Based on the RDF data set, what is the result of the following query?

PREFIX foaf: http://xmlns.com/foaf/0.1

SELECT ?x ?name

{

?x foaf:name ?name

}

A
20
Q

Based on the RDF data set, what is the result of the following query?

PREFIX dc: http://purl.org/dc/elements/1.1

SELECT ?title WHERE

{

?x dc:title ?title.

FILTER regex(?title, “SPARQL”)

}

A

title

“SPARQL tutorial”

21
Q

Based on the RDF data set, what is the result of the following query?

PREFIX dc: http://purl.org/dc/elements/1.1

SELECT ?title WHERE

{

?x dc:title ?title.

FILTER regex(?title, “web”, “i”)

}

A

title

“The Semantic Web”

22
Q

Based on the RDF data set, what is the result of the following query?

PREFIX dc: http://purl.org/dc/elements/1.1

PREFIX ns: http://example.org/ns#

SELECT ?title ?price WHERE

{

?x ns:price ?price .

?x dc:title ?title .

FILTER(?price < 30.5)

}

A

title

“The Semantic Web”

price

23

23
Q

Based on the RDF data set, what is the result of the following query?

PREFIX foaf: http://xmlns.com/foaf/0.1

SELECT DISTINCT ?name WHERE

{

?x foaf:name ?name .

}

A

name

“Alice”

24
Q

Write a SPARQL command for writing the name of all movies and their directors for every movie in which MacWin has played, sorted based on the names of movies.

A

SELECT ?movie ?director WHERE

{

:MacWin played-in ?movie .

?director directed ?movie .

}

ORDER BY ?movie

(correct, but in practice we usually create a resource for MacWin then set its name-property to MacWin)

25
Q

Write a SPARQL command for writing the number of movies in which MacWin has played.

(hint: use COUNT)

A

SELECT (COUNT(?movie) AS ?movieCount) WHERE

{

:MacWin played-in ?movie

}

26
Q

Write a SPARQL command for writing the number of movies in which each actor has played

(hint: use GROUP BY)

A

SELECT ?actor (COUNT(?movie) as ?movieCount) WHERE

{

?actor played-in ?movie

}

GROUP BY ?actor

27
Q

Write a SPARQL command for writing the number of movies in which each actor has played. Your command should only display those who have played in more than 6 movies

(hint: use HAVING)

A

SELECT ?actor (COUNT(?movie) AS ?movieCount) WHERE

{

?actor played-in ?movie

}

GROUP BY ?actor

HAVING (movieCount > 6)