User:Battleofalma/Queries I use

Basic

edit

List of/show me all of a thing with one statement

e.g Show me all the things that are an instance of a conspiracy theory.

SELECT ?item ?itemLabel #the labels for the things in the query

WHERE { ?item wdt:P31 wd:Q159535 #instance of a thing with this thing about it
     
      
      
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
       
       }
Try it!

SMG Collections

edit
SELECT ?item ?itemLabel ?groupLabel ?imageLabel ?collection ?collectionLabel WHERE {
  ?item wdt:P8694 ?group .
  ?item wdt:P18 ?image .
  ?item wdt:P195 ?collection .
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!


People, professions with images, articles

edit

Kurdish queries

edit

Things, with images

edit

Other, more complex queries

edit

Random queries

edit

Martin's Queries

edit

Others

edit

Properties and values from single item

edit
SELECT ?prop_id ?prop_label ?prop_val_label WHERE {
  VALUES (?company) {
    (wd:Q208048)
  }
  ?company ?prop_id ?company_item.
  ?wd wikibase:directClaim ?prop_id.
  ?wd rdfs:label ?prop_label.
  OPTIONAL {
    ?company_item rdfs:label ?prop_val.
    FILTER((LANG(?prop_val)) = "en")
  }
  BIND(COALESCE(?prop_val, ?companyItem) AS ?prop_val_label)
  FILTER((LANG(?prop_label)) = "en")
}
Try it!

Properties and values from single item with qualifiers

edit
SELECT ?wdLabel ?ps_Label ?wdpqLabel ?pq_Label {
  VALUES (?company) {(wd:Q95)}

  ?company ?p ?statement .
  ?statement ?ps ?ps_ .

  ?wd wikibase:claim ?p.
  ?wd wikibase:statementProperty ?ps.

  OPTIONAL {
  ?statement ?pq ?pq_ .
  ?wdpq wikibase:qualifier ?pq .
  }

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
} ORDER BY ?wd ?statement ?ps_
Try it!

Properties in English not in Danish (or select another language)

edit
SELECT * WHERE {
  ?property rdf:type wikibase:Property;
    rdfs:label ?english.
  FILTER(NOT EXISTS {
    ?property rdfs:label ?dansk.
    FILTER((LANG(?dansk)) = "da")
  })
  FILTER((LANG(?english)) = "en")
}
Try it!
SELECT
  ?item
  (SAMPLE (?titleL) AS ?title)
  (group_concat(distinct ?creatorL ; separator = ", ") as ?creator)
  (group_concat(distinct ?genreL ; separator = ", ") as ?genre)
  (group_concat(distinct ?placeL ; separator = ", ") as ?place)
  (group_concat(distinct ?arr ; separator = ", ") as ?arrondissement)
  (SAMPLE (?img) AS ?image)
  (SAMPLE (?coord) AS ?coordinates) {

    {
      SELECT DISTINCT ?item { {
        ?item wdt:P136 wd:Q557141 ;     # genre: public art
              wdt:P131 wd:Q90           # located in: Paris
      } UNION { # or
        ?item wdt:P136 wd:Q557141 ;     # genre: public art
              wdt:P131/wdt:P131* wd:Q90 # located in an arrondissement of Paris
      } }
    }
   
    # title
    OPTIONAL { ?item rdfs:label ?titleL filter (lang(?titleL) = "fr") }
   
    # creators
    OPTIONAL { ?item wdt:P170 [rdfs:label ?creatorL] filter (lang(?creatorL) = "fr") }
   
    #genre
    OPTIONAL {
      {
        ?item wdt:P136 ?g filter (STR(?g) != 'http://www.wikidata.org/entity/Q557141')
      } UNION {
        ?item wdt:P31 ?g .
      }
      ?g rdfs:label ?genreL filter (lang(?genreL) = "fr") .
    }
   
    # place
    OPTIONAL {
      ?item wdt:P276 [rdfs:label ?placeL] filter (lang(?placeL) = "fr") .
    }
   
    # arrondissement
    OPTIONAL {
      ?item wdt:P131 [wdt:P131 wd:Q90 ; rdfs:label ?arrL] filter (lang(?arrL) = "fr").
      BIND(REPLACE(?arrL, '^([0-9]+).*$', "$1", "si") AS ?arr)
    }
   
    # image
    OPTIONAL { ?item wdt:P18 ?img }
   
    # coordinates
    OPTIONAL { ?item wdt:P625 ?coord }

} GROUP BY ?item
Try it!

The Zodiac Signs of Japanese Prime Ministers

edit

The following query uses these:

  • Properties: instance of (P31)     , position held (P39)     , date of birth (P569)     
    SELECT DISTINCT ?item ?itemLabel ?dob ?sign 
    {
     ?item wdt:P31 wd:Q5 ; p:P39 ?ps . ?ps ps:P39 ?term .
     ?term wdt:P39* wd:Q274948 .     # all Japanese Prime Ministers
     ?positionStatement ps:P39 wd:Q274948 .
           
           
     ?item p:P569/psv:P569 [         # with a known birthday
       wikibase:timeValue ?dob;
       wikibase:timePrecision 11     # of “day” precision
     ].
      
    BIND( IF(MONTH(?dob) = 3&& DAY(?dob) >=21, "Aries" ,
    IF(MONTH(?dob) = 4&& DAY(?dob) < 20, "Aries" ,
    IF(MONTH(?dob) = 4&& DAY(?dob) >=20, "Taurus" ,
    IF(MONTH(?dob) = 5&& DAY(?dob) < 21, "Taurus" ,
    IF(MONTH(?dob) = 5&& DAY(?dob) >=21, "Gemini" ,
    IF(MONTH(?dob) = 6&& DAY(?dob) < 21, "Gemini" ,
    IF(MONTH(?dob) = 6&& DAY(?dob) >=21, "Cancer" ,
    IF(MONTH(?dob) = 7&& DAY(?dob) < 23, "Cancer" ,
    IF(MONTH(?dob) = 7&& DAY(?dob) >=23, "Leo" ,
    IF(MONTH(?dob) = 8&& DAY(?dob) < 23, "Leo" ,
    IF(MONTH(?dob) = 8&& DAY(?dob) >=23, "Virgo" ,
    IF(MONTH(?dob) = 9&& DAY(?dob) < 23, "Virgo" ,
    IF(MONTH(?dob) = 9&& DAY(?dob) >=23, "Libra" ,
    IF(MONTH(?dob) = 10&& DAY(?dob) < 23, "Libra" ,
    IF(MONTH(?dob) = 10&& DAY(?dob) >=23, "Scorpio" ,
    IF(MONTH(?dob) = 11&& DAY(?dob) < 22, "Scorpio" ,
    IF(MONTH(?dob) = 11&& DAY(?dob) >=23, "Sagittarius" ,
    IF(MONTH(?dob) = 12&& DAY(?dob) < 22, "Sagittarius" ,
    IF(MONTH(?dob) = 12&& DAY(?dob) >=22, "Capricorn" ,
    IF(MONTH(?dob) = 1&& DAY(?dob) < 20, "Capricorn" ,
    IF(MONTH(?dob) = 1&& DAY(?dob) >=20, "Aquarius" ,
    IF(MONTH(?dob) = 2&& DAY(?dob) < 19, "Aquarius" ,
    IF(MONTH(?dob) = 2&& DAY(?dob) >=19, "Pisces" ,
    IF(MONTH(?dob) = 3&& DAY(?dob) < 21, "Pisces" ,
    "unknown (this should never happen)"
    ))))))))))))))))))))))))
       
                      
           AS ?sign)
    
     SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
    }
    

Search by words in label

edit

The following query uses these:

SELECT distinct ?item ?itemLabel ?itemDescription WHERE{  
  ?item ?label "Oak"@en.  
  ?article schema:about ?item .
  ?article schema:inLanguage "en" .
  ?article schema:isPartOf <https://en.wikipedia.org/>.	
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }    
}

Moomin valley location

edit
#defaultView:Map

SELECT ?moomin ?moominLabel ?place ?coords ?coordinateLabel

WHERE { ?moomin wdt:P31 wd:Q200344 .
        ?moomin wdt:P466 ?place .
        ?place wdt:P625 ?coords
                
       
       
       
       SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
      
      
      }
Try it!


[2]

SELECT ?p ?pLabel ?pDescription ?type WHERE {
?p a wikibase:Property; wikibase:propertyType ?t
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
BIND(STRDT(STRAFTER(STR(?p),"/P"),xsd:integer) AS ?pnum)
BIND(STRAFTER(STR(?t),"ontology#") AS ?type)
} ORDER BY ?pnum
Try it!
#title:Replication Crisis by Subject area
#defaultView:BubbleChart
SELECT ?subject ?subjectLabel (COUNT(DISTINCT ?article) AS ?count) WHERE {
?article wdt:P921 wd:Q25303778; wdt:P1433 ?journal .
?journal wdt:P921 ?subject
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} GROUP BY ?subject ?subjectLabel
Replication Crisis by Subject area