User:Aeroid/SPARQL Notes

From Wikidata
Jump to navigation Jump to search

Nationalparks

[edit]

[1]

Fragments

[edit]

without german articles

[edit]
  	# look for articles (sitelinks) in English ("de")
  	OPTIONAL { ?sitelink schema:about ?item . ?sitelink schema:inLanguage "de" } 
	# but select items with no such article
	FILTER (!BOUND(?sitelink))
 

within Hamburg

[edit]

The upwards and downwards tree. It collects all territories that have a claim via P131-chains up to Hamburg or(!) via P150-chain down from any of them.

  ?adminTree (wdt:P131)* wd:Q1055 .
  ?adminTree (wdt:P150)* ?territory .
  ?statement wdt:P131 ?territory .
 

The straight forward way. Only those that explicitly claim P131-chains up to Hamburg (ignoring teh reverse via P150). This seems to be very expensive and causes timeout in many combinations.

  ?statement wdt:P131* wd:Q1055 .
 

Alterative notation but also straight forward. Same as the one directly above, but seems not cause performance issues.

  ?statement wdt:P131/wdt:P131* wd:Q1055 .
 

beware of Ranks

[edit]

The Query Service will make use of ranks. Using one of the latter two options allows you to rely on ranking in the P131*-tree to ommit former relations with normal ranks, if the current one is set to preferred. (see Statement types)

See also Alternative query, via Q30 and P6.

Items with claims using qualifiers about Hamburg and its subdivisions

[edit]

The following query uses these:

The following query uses these:

Lists about Hamburg and its subdivisions

[edit]

The following query uses these:

Categories about Hamburg and its subdivisions

[edit]

The following query uses these:

Located in Harburg

[edit]

The following query uses these:

Categories and Lists about Hamburg and subdivisons

[edit]

The following query uses these:

Located in and Categories and Lists about Harburg and subdivisons

[edit]

The following query uses these:

  • Properties: located in the administrative territorial entity (P131)  View with Reasonator View with SQID, contains the administrative territorial entity (P150)  View with Reasonator View with SQID, applies to jurisdiction (P1001)  View with Reasonator View with SQID, instance of (P31)  View with Reasonator View with SQID, category's main topic (P301)  View with Reasonator View with SQID, category combines topics (P971)  View with Reasonator View with SQID
    SELECT DISTINCT ?item ?itemLabel WHERE {
      ## only upward relation P131 which might miss items if the P131-tree is incomplete
      ?territory (wdt:P131)* wd:Q5907 .
      ## alternative: also use downward relation P150 which might lead to unwanted items from former adminstrative relations
      # ?adminTree (wdt:P131)* wd:Q5907 .
      # ?adminTree (wdt:P150)* ?territory .
      ##
      {  
        ?item wdt:P131 ?territory # anything located in 
      } UNION { 
        ?item wdt:P1001 ?territory # or within territorial jurisdiction
      } UNION {
        ?item wdt:P31 wd:Q4167836 . # categories
        {
          ?item wdt:P301 ?territory # with topic
        } UNION {
          ?item wdt:P971 ?territory # or combining topic with something
        }
      } UNION {
        ?item wdt:P31 wd:Q13406463 . #lists
        ?item ?p ?statement .
        ?statement pq:P131 ?territory # with statements having qualifiers located in 
      }
      SERVICE wikibase:label { bd:serviceParam wikibase:language "de" }
    } ORDER BY ( ?itemLabel )
    

Cultural heritage monuments in Hamburg

[edit]

The following query uses these:

German adminstrative units that where abolished in the last 365 days

[edit]

The following query uses these:

  • Properties: instance of (P31)  View with Reasonator View with SQID, subclass of (P279)  View with Reasonator View with SQID, inception (P571)  View with Reasonator View with SQID, dissolved, abolished or demolished date (P576)  View with Reasonator View with SQID
    SELECT DISTINCT ?event ?eventLabel ?date
    WHERE
    {
    	# find admin territories of Germany
    	?event wdt:P31/wdt:P279* wd:Q387917.
            # with founding/inception date
    	#OPTIONAL { ?event wdt:P571 ?date. }
            # abolished date
    	OPTIONAL { ?event wdt:P576 ?date. }
    	# but at least one of those
    	FILTER(BOUND(?date) && DATATYPE(?date) = xsd:dateTime).
    	# calculate age (days, negative are in the future)
    	BIND(NOW() - ?date AS ?age).
    	FILTER(0 <= ?age && ?age < 365).
    	# and get a label as well
    	SERVICE wikibase:label { bd:serviceParam wikibase:language "de" }
    } ORDER BY ( ?eventLabel )
    # limit to 100 results so we don't timeout
    LIMIT 100
    

Solving the problem of former P131 to interfere with lists

[edit]

P131 with No Value and have been abolished

[edit]

The following query uses these:

Gemeindeschlüssel DE-NI

[edit]

The following query uses these:

siehe [2], [3], [4] (LSN-Online: Tabelle A100001G Landesamt für Statistik Niedersachsen, Bevölkerung und Katasterfläche 1) in Niedersachsen (Gebietsstand: 1.1.2015))

Einwohnerzahlen mit Datum

[edit]

The following query uses these:

  • Properties: population (P1082)  View with Reasonator View with SQID, point in time (P585)  View with Reasonator View with SQID
    SELECT ?population ?pointInTime WHERE {
       wd:Q2773 p:P1082 ?statement.
       OPTIONAL {
         ?statement psv:P1082/wikibase:quantityAmount  ?population.
         ?statement pq:P585 ?pointInTime.
       }
       SERVICE wikibase:label {
         bd:serviceParam wikibase:language "en" .
       }
    } ORDER BY ( ?pointInTime )
    

Brücken in Deutschland sortiert nach normalisierter Länge

[edit]

siehe [5]

The following query uses these:

  • Properties: instance of (P31)  View with Reasonator View with SQID, subclass of (P279)  View with Reasonator View with SQID, date of official opening (P1619)  View with Reasonator View with SQID, inception (P571)  View with Reasonator View with SQID, start time (P580)  View with Reasonator View with SQID, length (P2043)  View with Reasonator View with SQID, longest span (P2787)  View with Reasonator View with SQID
    SELECT DISTINCT (ROUND(?normalizedLengthMeter) AS ?length) (ROUND(?normalizedLongestSpanMeter) AS ?span) ?opening ?inception ?start ?itemLabel ?item WHERE {
      ?item wdt:P31/wdt:P279* wd:Q12280.
      ?item p:P2043/psn:P2043/wikibase:quantityAmount ?normalizedLengthMeter.
      OPTIONAL { ?item p:P2787/psn:P2787/wikibase:quantityAmount ?normalizedLongestSpanMeter. }
      OPTIONAL { ?item wdt:P1619 ?opening. }.
      OPTIONAL { ?item wdt:P571 ?inception. }.
      OPTIONAL { ?item wdt:P580 ?start. }.
      SERVICE wikibase:label { bd:serviceParam wikibase:language "de" }
    }
    ORDER BY DESC( ?normalizedLengthMeter )
    

Städte mit normalisierter Fläche

[edit]

siehe List vun de gröttsten Städer in Mekelnborg-Vörpommern. wikibase:BestRank sorgt hier für "Truthy" Properties, da es hier durchaus Mehrfachangaben zu den geänderten Flächen gibt. Über das Row-Template werden aus Quadratmetern Quadratkilometer und Einheit. Leider noch mal Dezimalpunkt, statt -komma.

The following query uses these:

  • Properties: located in the administrative territorial entity (P131)  View with Reasonator View with SQID, instance of (P31)  View with Reasonator View with SQID, subclass of (P279)  View with Reasonator View with SQID, population (P1082)  View with Reasonator View with SQID, area (P2046)  View with Reasonator View with SQID
    SELECT DISTINCT ?item ?itemLabel ?_population ?normalizedAreaSquaremeter WHERE {
     ?item wdt:P131 ?territory.
     ?territory wdt:P131* wd:Q1196.
     ?item (wdt:P31/wdt:P279*) wd:Q262166.
     ?item wdt:P1082 ?_population.
     SERVICE wikibase:label { bd:serviceParam wikibase:language "nds". }
     OPTIONAL {
       ?item p:P2046 [
         a wikibase:BestRank;
         psn:P2046/wikibase:quantityAmount ?normalizedAreaSquaremeter
       ].
     }
    }
    ORDER BY DESC(?_population)
    LIMIT 25