Deliverable 1 : Write five complex queries in SPARQL

  • Bubble chart display of the total number of wins by a country at the 2016 Rio Olympics

    The following query uses these -
    Items : 2016 Summer Olympics(Q8613)
    Properties : has part(P527), winner(P1346), country for sport(P1532), country(P17), country of citizenship(P27)

    ##defaultView:BubbleChart
    #
    SELECT ?country ?countryLabel (COUNT(?m_event) AS ?count)
    WHERE
    {
      wd:Q8613 wdt:P527 ?event.
      ?event wdt:P527 ?m_event.
      ?m_event wdt:P1346 ?person.
      OPTIONAL {?person wdt:P1532 ?country.}
      OPTIONAL {?person wdt:P17 ?country.}
      OPTIONAL {?person wdt:P27 ?country.}
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
    }
    GROUP BY ?country ?countryLabel
    ORDER BY DESC(?count)
    

    ?event is an event that was part of the 2016 Summer Olympics. ?m_event is the sub categories in ?event. For example if ?event resulted in Tennis, then ?m_event would refer to its categories like Men's Singles, Women's Singles, Men's Doubles and so on. ?person points to the winner of each sub-category of the event. To find out which country the winner belongs to, the query extracts information from three fields - country of sport, country or country of citizenship. The three optional statements add the logic of populating the country field only if the respective property exist. The first OPTIONAL statement find if the property country of sport exists for the winner. If it does then it maps ?country to the value of that property and further OPTIONAL statements do not bind their results to the ?country variable.
    The GROUP BY clause combines the results by the country and the COUNT aggregates the number of events that map to the country.
    The defaultView tag specifies the result representation method. It can be images, charts, graphs or even maps.
    The SERVICE keyword

    Bubble chart for country wins
  • Total population in the Bay Area

    The following query uses these -
    Items : San Francisco Bay Area (Q213205), metropolitan area (Q1907114)
    Properties : part of (P361), population (P1082), instance of (P31), has part (P527)

    SELECT distinct ?area ?areaLabel (SUM(?popn) AS ?total_popn)
    WHERE {
     
      ?item wdt:P361 wd:Q213205.
      ?item wdt:P1082 ?popn. 
      ?area wdt:P31 wd:Q1907114.
      ?area wdt:P527 ?item.
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }
    GROUP BY ?area ?areaLabel
    

    ?item is mapped as an area part of the San Francisco Bay Area with population ?popn. ?area is a metropolitan area that has regions as ?item. The GROUP BY clause aggregates the areas and calculates the sum of all areas in it.

    Population in San Francisco Bay Area
  • Lexemes that mean apple in different languages

    The following query uses these -
    Items : apple (Q89)
    Properties : item for this sense (P5137)

    SELECT ?l ?sense ?lemma ?languageLabel 
    WHERE {
      ?l a ontolex:LexicalEntry ; 
           ontolex:sense ?sense ; 
           dct:language ?language ; 
           wikibase:lemma ?lemma. 
      ?sense wdt:P5137 wd:Q89 .
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }
    ORDER BY (LCASE(?languageLabel))
    

    A Lexeme is a lexical element of a language, such as a word, a phrase, or a prefix. ontolex and dct are prefixes that refer to lexicographical data ontologies as : ontolex: http://www.w3.org/ns/lemon/ontolex# dct: http://purl.org/dc/terms/ ?l refers to a lexeme that has the same sense as the word apple in all languages.

    Apple lexemes in different languages
  • Places within 1km distance of San Jose State University

    The following query uses these -
    Items : San Jose State University (Q498526),
    Properties : coordinate location (P625), instance of (P31)

    SELECT ?place ?placeLabel ?instanceLabel ?dist
    WHERE
    {
      wd:Q498526 wdt:P625 ?loc .
      SERVICE wikibase:around {
          ?place wdt:P625 ?location .
          bd:serviceParam wikibase:center ?loc .
          bd:serviceParam wikibase:radius "1" .
      }
      OPTIONAL {    ?place wdt:P31 ?instance  }
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
      BIND(geof:distance(?loc, ?location) AS ?dist)
    } ORDER BY ?dist
    
    Places within 1km radius of SJSU
  • List the count of translations for a disease from the the disease ontology

    The following query uses these -
    Properties : Disease Ontology ID (P699)

    SELECT ?disease ?doid ?enLabel (COUNT(?language) AS ?languages)
    WHERE
    {
      ?disease wdt:P699 ?doid ;
                 rdfs:label ?label ;
                 rdfs:label ?enLabel .
        FILTER (lang(?enLabel) = "en")
       
        BIND (lang(?label) AS ?language)
    }
    GROUP BY ?disease ?doid ?enLabel
    ORDER BY desc(?languages)
    
    Diseases and translation count