Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Emanuele Della Valle
    @emanueledellavalle

    playing with SPARQL

    DBpedia endpoint

    ex 1

    Find the artist in dbpedia (hint: the URL of artist is http://dbpedia.org/ontology/Artist)
    Emanuele Della Valle
    @emanueledellavalle
    select ?x 
    where { ?x rdf:type dbo:Artist } 
    LIMIT 10
    I wrote dbo:Artist because dbo is the default prefix for http://dbpedia.org/ontology/

    2

    Find the artists born in Paris (hint: Paris in dbpedia is dbr:Paris )
    Emanuele Della Valle
    @emanueledellavalle
    select ?x 
    where { ?x rdf:type dbo:Artist ; dbo:birthPlace dbr:Paris .} 
    LIMIT 10

    ex 3

    What links artists to Paris?
    select distinct ?p
    where { ?x rdf:type dbo:Artist ; ?p dbr:Paris .} 
    LIMIT 10
    Emanuele Della Valle
    @emanueledellavalle
    as yuo noticed in the results there are two properties to say birthPlace
    if yopu want to query for both
    select ?x 
    where { ?x rdf:type dbo:Artist.
            { ?x dbo:birthPlace dbr:Paris }
            UNION
            { ?x dbp:birthPlace dbr:Paris }  
    } 
    LIMIT 10
    UNION expresses OR
    Emanuele Della Valle
    @emanueledellavalle
    Find the artist born in places with more than 1.000.000 people (hints: http://dbpedia.org/ontology/birthPlace http://dbpedia.org/ontology/populationTotal)

    4

    answer

    where can I find more sparql endpoints

    Google also has a querable Knowledge Graph, see its APIs
    Emanuele Della Valle
    @emanueledellavalle
    select ?x ?y ?population 
    where { ?x rdf:type dbo:Artist ;
            dbo:birthPlace ?y .
            ?y dbo:populationTotal ?population 
            FILTER ( ?population >= 1000000)
    }
    LIMIT 100
    however, in the answers we find cities, regions, countries, etc. Can you add a condition to limit the answers to cities?
    Emanuele Della Valle
    @emanueledellavalle
    look into the data, find a city, discover that its type is dbo:City and query for it
    select ?x ?y ?population 
    where { ?x rdf:type dbo:Artist ;
            dbo:birthPlace ?y .
            ?y rdf:type dbo:City ; dbo:populationTotal ?population 
            FILTER ( ?population >= 1000000)
    }
    LIMIT 100

    EX 5

    For every artist tell, if it is available, tell the population of the city where he/she was born
    Emanuele Della Valle
    @emanueledellavalle
    select ?x ?y ?population 
    where { ?x rdf:type dbo:Artist ;
               dbo:birthPlace ?y .
            ?y rdf:type dbo:City 
            OPTIONAL {?y dbo:populationTotal ?population }
    }
    order by asc(?population)
    LIMIT 100
    or if also city is optional
    select ?x ?y ?population 
    where { ?x rdf:type dbo:Artist ;
               dbo:birthPlace ?y .  
            OPTIONAL { ?y rdf:type dbo:City ; dbo:populationTotal ?population }
    }
    order by asc(?population)
    LIMIT 100