User:Deryck Chan/SPARQL

Qualifiers edit

Get all property-qualifier-target combinations that use a particular qualifier edit

SELECT DISTINCT ?property ?propertyLabel ?asObject ?asObjectLabel
WHERE
{
  ?prop pq:P794 ?asObject .
  hint:Query hint:optimizer "None" .	
  ?item ?p ?prop . 
  ?property wikibase:claim ?p .  
  ?property wikibase:statementProperty ?ps .
  ?prop ?ps ?value .      
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en"  }    
}
ORDER BY ASC(?propertyLabel) 
LIMIT 1000
Try it!

Get all statements that use a particular property-qualifier combination edit

SELECT DISTINCT ?item ?itemLabel ?property ?propertyLabel ?value ?asObject ?asObjectLabel
WHERE
{
  ?prop pq:P31 ?asObject .
  hint:Query hint:optimizer "None" .	
  ?item ?p ?prop . 
  ?property wikibase:claim ?p .  
  ?property wikibase:statementProperty ?ps .
  ?prop ?ps ?value .
  wd:P69 wikibase:claim ?p .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,bg"  }    
}
ORDER BY ASC(?value) 
LIMIT 10000
Try it!

Stats for a particular property-qualifier combination edit

SELECT (COUNT(DISTINCT ?item) as ?countitem) (COUNT(DISTINCT ?asObject) as ?counttarget)
WHERE
{
  ?prop pq:P31 ?asObject .
  hint:Query hint:optimizer "None" .	
  ?item ?p ?prop . 
  ?property wikibase:claim ?p .  
  ?property wikibase:statementProperty ?ps .
  ?prop ?ps ?value .
  wd:P18 wikibase:claim ?p .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,bg"  }    
}
Try it!

Get all qualifiers that qualify a particular property edit

SELECT DISTINCT  ?qualifier ?qualifierLabel ?asObject ?asObjectLabel
WHERE
{
  wd:P3990 wikibase:claim ?p .
  ?qualifier wikibase:qualifier ?q .
  ?item ?p ?prop . 
  ?prop ?q ?asObject .
  ?property wikibase:statementProperty ?ps .
  ?prop ?ps ?value .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,bg"  }    
}
ORDER BY ASC(?value) 
LIMIT 1000
Try it!

Limit the domain of the target edit

SELECT DISTINCT ?item ?itemLabel ?value ?valueLabel ?asObject ?asObjectLabel
WHERE
{
  wd:P1448 wikibase:claim ?p .
  wd:P794 wikibase:qualifier ?q .
  ?item ?p ?prop . 
  ?prop ?q ?asObject .
  ?asObject wdt:P31/wdt:P279* wd:Q176799. #limit to military groups  
  ?property wikibase:statementProperty ?ps .
  ?prop ?ps ?value .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,bg"  }    
}
ORDER BY ASC(?asObjectLabel) 
LIMIT 1000
Try it!

Limit the domain of both the object and the target edit

SELECT DISTINCT ?item ?itemLabel ?value ?valueLabel ?asObject ?asObjectLabel
WHERE
{
  wd:P767 wikibase:claim ?p .
  wd:P794 wikibase:qualifier ?q .
  ?item ?p ?prop . 
  ?prop ?q ?asObject .
  ?property wikibase:statementProperty ?ps .
  ?prop ?ps ?value .
  ?value wdt:P31/wdt:P279* wd:Q5 . #object is a human
  ?asObject wdt:P31/wdt:P279* wd:Q12737077 . #target is an occupation
  SERVICE wikibase:label { bd:serviceParam wikibase:language "yue,en,sv,de,zh,ja,bg,ru"  }    
}
ORDER BY ASC(?itemLabel) 
LIMIT 4000
Try it!

All qualifiers that use a particular target edit

SELECT DISTINCT ?item ?itemLabel ?property ?propertyLabel ?value ?valueLabel ?qualifier ?qualifierLabel
WHERE
{
  ?property wikibase:claim ?p .
  ?qualifier wikibase:qualifier ?q .
  ?item ?p ?prop . 
  ?prop ?q wd:Q10578722 .
  ?property wikibase:statementProperty ?ps .
  ?prop ?ps ?value .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,bg"  }    
}
ORDER BY ASC(?qualifierLabel) 
LIMIT 1000
Try it!

Places edit

SELECT DISTINCT ?District ?DistrictLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?District (wdt:P131/wdt:P131*) wd:Q23092.
  ?District (wdt:P31/wdt:P279*) wd:Q717478.
}
LIMIT 100
Try it!

Date formatting edit

Shortlink: https://w.wiki/S69

SELECT * WHERE {
  VALUES ?lang { 'yue' 'zh' 'ja' } .
  ?item wdt:P31 wd:Q47018478;
        wdt:P585 ?date .
  OPTIONAL { ?item rdfs:label ?label FILTER( LANG( ?label ) = ?lang ) } .
  BIND( STRLANG( CONCAT( STR(YEAR(?date)), '年', STR(MONTH(?date)), '月' ), ?lang ) AS ?new ) .
  FILTER( !BOUND( ?label )|
Try it!