Examples

Example 1

Find all B/W Italian movies which soundtrack composer was born in a Trentino Alto Adige city with less than 40,000 inhabitants.

We will provide a set of incremental complexity SPARQL queries.

Let’s start looking at all Italian produced movies (Run Query QA).

SELECT * WHERE {
 ?movie a
     <http://dbpedia.org/ontology/Film> .
 ?movie <http://dbpedia.org/ontology/country> 
     <http://it.dbpedia.org/resource/Italia> .
}

Then extend the query looking for Italian produce movies in B/W (Run Query QB).

SELECT * WHERE {
 ?movie a
     <http://dbpedia.org/ontology/Film> .
 ?movie <http://dbpedia.org/ontology/country>
     <http://it.dbpedia.org/resource/Italia> .
 ?movie <http://dbpedia.org/ontology/filmColourType> ?colour .
 FILTER ( ?colour in ("B/N"@it, "bianco/nero"@it ) )
}

Let’s look now for soundtrack composers of such Italian produced movies (Run Query QC).

SELECT * WHERE {
 ?movie a
     <http://dbpedia.org/ontology/Film> .
 ?movie <http://dbpedia.org/ontology/country>
     <http://it.dbpedia.org/resource/Italia> .
 ?movie <http://dbpedia.org/ontology/filmColourType> ?colour .
 ?movie <http://dbpedia.org/ontology/musicComposer>  ?composer .
 FILTER ( ?colour in ("B/N"@it, "bianco/nero"@it ) )
}

To end let’s filter among composers born in Trentino Alto Adige region in a location with population lesser than 40,000 inhabitants (Run Query QD).

SELECT * WHERE {
 ?movie a
    <http://dbpedia.org/ontology/Film> .
 ?movie <http://dbpedia.org/ontology/country>
    <http://it.dbpedia.org/resource/Italia> .
 ?movie <http://dbpedia.org/ontology/filmColourType> ?colour .
 ?movie <http://dbpedia.org/ontology/musicComposer>  ?composer .
 
 ?composer   <http://dbpedia.org/ontology/birthPlace>
    ?birthplace .
 ?birthplace <http://dbpedia.org/ontology/administrativeDistrict> 
    <http://it.dbpedia.org/resource/Trentino-Alto_Adige> .
 ?birthplace <http://dbpedia.org/ontology/populationTotal>
    ?population
 FILTER ( ?colour in ("B/N"@it, "bianco/nero"@it) AND ?population < 40000 )
}

Example 2

Find all women artist with max age 40 that were born in a city with less than 40k people.

We will provide a set of incremental complexity SPARQL queries.

Let’s start retrieving all people it DBPedia Italy having a name and surname expressed as literal (Q1).


SELECT * WHERE {
  FILTER( isLiteral(?name) AND isLiteral(?surname) )
}

Let’s select then among these people that ones having artist as profession (Q2).

SELECT * WHERE {
  ?person <http://it.dbpedia.org/property/attività> “artista”@it
  FILTER( isLiteral(?name) AND isLiteral(?surname) )
}

Let’s filter only people of gender female and age not over 40 (Q3).


SELECT * WHERE {
  ?person <http://it.dbpedia.org/property/attività> “artista”@it .
  ?person <http://it.dbpedia.org/property/sesso> “F”@it .
  FILTER( isLiteral(?name) AND isLiteral(?surname) AND ?birth >= “1972-01-01″^^xsd:date)
}

 

Let’s identify the birthplace of all selected artists and filter on the population size (Q4).


SELECT * WHERE {
  ?person <http://it.dbpedia.org/property/attività> “artista”@it .
  ?person <http://it.dbpedia.org/property/sesso> “F”@it .
  ?city rdfs:label ?birthplace .
  FILTER( isLiteral(?name) AND isLiteral(?surname) AND ?birth >= “1972-01-01″^^xsd:date AND ?population < 40000)
}

 

That’s finally what we were looking for.

Example 3

13 Vertical: Archeologist and writer of the last century (6 letters).

Look for all archeologists that have been also writers born on 19th century with a surname of exactly 6 letters (Q5).

SELECT str(?surname), ?p WHERE {
  ?p <http://it.dbpedia.org/property/attività> “scrittore”@it .
  ?p <http://it.dbpedia.org/property/attività> “archeologo”@it .
  ?p <http://it.dbpedia.org/property/epoca>   “1900”^^xsd:int .
  FILTER( strlen(?surname) = 6 )
}