SPARQL examples: Difference between revisions

From Dariah-Lab
Jump to navigation Jump to search
No edit summary
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 68: Line 68:
</syntaxhighlight>
</syntaxhighlight>
[https://prunus-208.man.poznan.pl/wdqs/index.html#%23title%3A%20Osoby%20urodzone%20mi%C4%99dzy%20rokiem%201501%20a%201525%0ASELECT%20DISTINCT%20%3Fitem%20%3FitemLabel%20WHERE%20%7B%0A%20%20%3Fitem%20wdt%3AP47%20wd%3AQ32.%0A%20%20%3Fitem%20wdt%3AP7%20%3Fbirthdate.%0A%20%20FILTER%28%28%3Fbirthdate%20%3E%3D%20%221501-01-01T00%3A00%3A00Z%22%5E%5Exsd%3AdateTime%29%20%26%26%20%28%3Fbirthdate%20%3C%3D%20%221525-12-31T00%3A00%3A00Z%22%5E%5Exsd%3AdateTime%29%29%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D Try it!]
[https://prunus-208.man.poznan.pl/wdqs/index.html#%23title%3A%20Osoby%20urodzone%20mi%C4%99dzy%20rokiem%201501%20a%201525%0ASELECT%20DISTINCT%20%3Fitem%20%3FitemLabel%20WHERE%20%7B%0A%20%20%3Fitem%20wdt%3AP47%20wd%3AQ32.%0A%20%20%3Fitem%20wdt%3AP7%20%3Fbirthdate.%0A%20%20FILTER%28%28%3Fbirthdate%20%3E%3D%20%221501-01-01T00%3A00%3A00Z%22%5E%5Exsd%3AdateTime%29%20%26%26%20%28%3Fbirthdate%20%3C%3D%20%221525-12-31T00%3A00%3A00Z%22%5E%5Exsd%3AdateTime%29%29%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D Try it!]
=== Osoby o nazwisku Tarnowska/Tarnowski ===
<syntaxhighlight lang="SPARQL" class="mw-highlight-lang-sparql">
SELECT DISTINCT ?item ?itemLabel ?title ?tom
WHERE
{
  ?item wdt:P47 wd:Q32 .      # człowiek
  ?item wdt:P17 ?biogram .    # posiadający właściwość opisano w źródle
  ?biogram wdt:P47 wd:Q708 .  # która jest elementem bądącym rozdziałem
  ?biogram wdt:P106 ?title .  # tytuł biogramu
  ?biogram wdt:P167 ?book .  # publikacja, tom PSB
  ?book wdt:P107 ?tom .      # tytuł tomu PSB
  {?item wdt:P183 wd:Q23187 .} # element z właściwością family name = elementowi Tarnowski
  UNION
  {?item wdt:P183 wd:Q4511 . } # element z właściwością family name = elementowi Tarnowska
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?itemLabel
</syntaxhighlight>
[https://prunus-208.man.poznan.pl/wdqs/index.html#%23title%3A%20Osoby%20o%20nazwisku%20Tarnowski%2FTarnowska%0ASELECT%20DISTINCT%20%3Fitem%20%3FitemLabel%20%3Ftitle%20%3Ftom%0AWHERE%20%0A%7B%0A%20%20%3Fitem%20wdt%3AP47%20wd%3AQ32%20.%20%20%20%20%20%20%23%20cz%C5%82owiek%0A%20%20%3Fitem%20wdt%3AP17%20%3Fbiogram%20.%20%20%20%20%23%20posiadaj%C4%85cy%20w%C5%82a%C5%9Bciwo%C5%9B%C4%87%20opisano%20w%20%C5%BAr%C3%B3dle%0A%20%20%3Fbiogram%20wdt%3AP47%20wd%3AQ708%20.%20%20%23%20kt%C3%B3ra%20jest%20elementem%20b%C4%85d%C4%85cym%20rozdzia%C5%82em%0A%20%20%3Fbiogram%20wdt%3AP106%20%3Ftitle%20.%20%20%23%20tytu%C5%82%20biogramu%0A%20%20%3Fbiogram%20wdt%3AP167%20%3Fbook%20.%20%20%20%23%20publikacja%2C%20tom%20PSB%0A%20%20%3Fbook%20wdt%3AP107%20%3Ftom%20.%20%20%20%20%20%20%20%23%20tytu%C5%82%20tomu%20PSB%0A%20%20%7B%3Fitem%20wdt%3AP183%20wd%3AQ23187%20.%7D%20%23%20element%20z%20w%C5%82a%C5%9Bciwo%C5%9Bci%C4%85%20family%20name%20%3D%20elementowi%20Tarnowski%0A%20%20UNION%0A%20%20%7B%3Fitem%20wdt%3AP183%20wd%3AQ4511%20.%20%7D%20%23%20element%20z%20w%C5%82a%C5%9Bciwo%C5%9Bci%C4%85%20family%20name%20%3D%20elementowi%20Tarnowska%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D%0AORDER%20BY%20%3FitemLabel Try it!]
=== Osoby aktywne w XVI wieku lecz bez precyzyjnie określonej daty urodzenia/śmierci ===
<syntaxhighlight lang="SPARQL" class="mw-highlight-lang-sparql">
SELECT DISTINCT ?item ?itemLabel ?fluorit WHERE {
  ?item wdt:P47 wd:Q32.
  ?item wdt:P54 ?fluorit.
  FILTER ((?fluorit >= "+1501-01-01T00:00:00Z"^^xsd:dateTime) && (?fluorit <= "+1600-01-01T00:00:00Z"^^xsd:dateTime))
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
</syntaxhighlight>
[https://prunus-208.man.poznan.pl/wdqs/#%23Osoby%20aktywne%20w%20XVI%20wieku%20%28bez%20precyzyjnej%20daty%20urodzenia%20i%20%C5%9Bmierci%29%0ASELECT%20DISTINCT%20%3Fitem%20%3FitemLabel%20%3Ffluorit%20WHERE%20%7B%0A%20%20%3Fitem%20wdt%3AP47%20wd%3AQ32.%0A%20%20%3Fitem%20wdt%3AP54%20%3Ffluorit.%0A%20%20FILTER%20%28%28%3Ffluorit%20%3E%3D%20%22%2B1501-01-01T00%3A00%3A00Z%22%5E%5Exsd%3AdateTime%29%20%26%26%20%28%3Ffluorit%20%3C%3D%20%22%2B1600-01-01T00%3A00%3A00Z%22%5E%5Exsd%3AdateTime%29%29%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D Try it!]
=== Osoby żyjące w XVI wieku - urodzone, zmarłe lub aktywne ===
<syntaxhighlight lang="SPARQL" class="mw-highlight-lang-sparql">
SELECT * WHERE
{
  {
    SELECT DISTINCT ?item ?itemLabel WHERE {
    ?item wdt:P47 wd:Q32.
    ?item wdt:P7 ?birthdate.
    ?item wdt:P8 ?deathdate.
    FILTER(
          ((?birthdate >= "1501-01-01T00:00:00Z"^^xsd:dateTime) && (?birthdate <= "1600-12-31T00:00:00Z"^^xsd:dateTime))
          ||
          ((?deathdate >= "1501-01-01T00:00:00Z"^^xsd:dateTime) && (?deathdate <= "1600-12-31T00:00:00Z"^^xsd:dateTime))
          )
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }}
  }
UNION
  {
  SELECT DISTINCT ?item ?itemLabel WHERE {
    ?item wdt:P47 wd:Q32.
    ?item wdt:P54 ?fluorit.
    FILTER ((?fluorit >= "+1501-01-01T00:00:00Z"^^xsd:dateTime) && (?fluorit <= "+1600-01-01T00:00:00Z"^^xsd:dateTime))
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }}
  }
 
}
ORDER BY ?itemLabel
</syntaxhighlight>
[https://prunus-208.man.poznan.pl/wdqs/#%23Osoby%20%C5%BCyj%C4%85ce%20w%20XVI%20wieku%20%28zmar%C5%82e%20w%20XVI%20w.%20lub%20urodzone%20w%20XVI%20w.%29%0ASELECT%20%2a%20WHERE%0A%7B%20%0A%20%0A%20%20%7B%20%0A%20%20%20%20SELECT%20DISTINCT%20%3Fitem%20%3FitemLabel%20WHERE%20%7B%0A%20%20%20%20%3Fitem%20wdt%3AP47%20wd%3AQ32.%0A%20%20%20%20%3Fitem%20wdt%3AP7%20%3Fbirthdate.%0A%20%20%20%20%3Fitem%20wdt%3AP8%20%3Fdeathdate.%20%0A%20%20%20%20FILTER%28%0A%20%20%20%20%20%20%20%20%20%20%20%28%28%3Fbirthdate%20%3E%3D%20%221501-01-01T00%3A00%3A00Z%22%5E%5Exsd%3AdateTime%29%20%26%26%20%28%3Fbirthdate%20%3C%3D%20%221600-12-31T00%3A00%3A00Z%22%5E%5Exsd%3AdateTime%29%29%20%0A%20%20%20%20%20%20%20%20%20%20%20%7C%7C%0A%20%20%20%20%20%20%20%20%20%20%20%28%28%3Fdeathdate%20%3E%3D%20%221501-01-01T00%3A00%3A00Z%22%5E%5Exsd%3AdateTime%29%20%26%26%20%28%3Fdeathdate%20%3C%3D%20%221600-12-31T00%3A00%3A00Z%22%5E%5Exsd%3AdateTime%29%29%0A%20%20%20%20%20%20%20%20%20%20%29%20%0A%20%20%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%7D%0A%20%20%7D%0AUNION%0A%20%20%7B%0A%20%20%20SELECT%20DISTINCT%20%3Fitem%20%3FitemLabel%20WHERE%20%7B%0A%20%20%20%20%3Fitem%20wdt%3AP47%20wd%3AQ32.%0A%20%20%20%20%3Fitem%20wdt%3AP54%20%3Ffluorit.%0A%20%20%20%20FILTER%20%28%28%3Ffluorit%20%3E%3D%20%22%2B1501-01-01T00%3A00%3A00Z%22%5E%5Exsd%3AdateTime%29%20%26%26%20%28%3Ffluorit%20%3C%3D%20%22%2B1600-01-01T00%3A00%3A00Z%22%5E%5Exsd%3AdateTime%29%29%0A%20%20%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%7D%0A%20%20%7D%0A%20%20%20%0A%7D%0AORDER%20BY%20%3FitemLabel Try it!]
=== Wiek w chwili śmierci dla osób z datą urodzenia/śmierci znaną co do roku ===
<syntaxhighlight lang="SPARQL" class="mw-highlight-lang-sparql">
SELECT ?item ?itemLabel ?age
WHERE {
        ?item wdt:P47 wd:Q32 .
        ?item p:P7/psv:P7 ?birth_date_node .
        ?item p:P8/psv:P8 ?death_date_node .
        ?birth_date_node wikibase:timeValue ?birth_date.
        ?death_date_node wikibase:timeValue ?death_date.
        ?birth_date_node wikibase:timePrecision ?birth_precision.
        ?death_date_node wikibase:timePrecision ?death_precision.
        BIND( YEAR(?death_date) - YEAR(?birth_date) -
              IF(MONTH(?death_date)<MONTH(?birth_date) ||
                (MONTH(?death_date)=MONTH(?birth_date) && DAY(?death_date)<DAY(?birth_date)),1,0) AS ?age )
        FILTER(?age > 0 && ?age < 110 && ?birth_precision >= 9 && ?death_precision >= 9).
        SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?age)
</syntaxhighlight>
[https://prunus-208.man.poznan.pl/wdqs/#SELECT%20%3Fitem%20%3FitemLabel%20%3Fage%20%0AWHERE%20%7B%0A%20%20%20%20%20%20%20%20%3Fitem%20wdt%3AP47%20wd%3AQ32%20.%0A%20%20%20%20%20%20%20%20%3Fitem%20p%3AP7%2Fpsv%3AP7%20%3Fbirth_date_node%20.%20%0A%20%20%20%20%20%20%20%20%3Fitem%20p%3AP8%2Fpsv%3AP8%20%3Fdeath_date_node%20.%0A%20%20%20%20%20%20%20%20%3Fbirth_date_node%20wikibase%3AtimeValue%20%3Fbirth_date.%0A%20%20%20%20%20%20%20%20%3Fdeath_date_node%20wikibase%3AtimeValue%20%3Fdeath_date.%0A%20%20%20%20%20%20%20%20%3Fbirth_date_node%20wikibase%3AtimePrecision%20%3Fbirth_precision.%0A%20%20%20%20%20%20%20%20%3Fdeath_date_node%20wikibase%3AtimePrecision%20%3Fdeath_precision.%0A%20%20%20%20%20%20%20%20BIND%28%20YEAR%28%3Fdeath_date%29%20-%20YEAR%28%3Fbirth_date%29%20-%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20IF%28MONTH%28%3Fdeath_date%29%3CMONTH%28%3Fbirth_date%29%20%7C%7C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%28MONTH%28%3Fdeath_date%29%3DMONTH%28%3Fbirth_date%29%20%26%26%20DAY%28%3Fdeath_date%29%3CDAY%28%3Fbirth_date%29%29%2C1%2C0%29%20AS%20%3Fage%20%29%0A%20%20%20%20%20%20%20%20FILTER%28%3Fage%20%3E%200%20%26%26%20%3Fage%20%3C%20110%20%26%26%20%3Fbirth_precision%20%3E%3D%209%20%26%26%20%3Fdeath_precision%20%3E%3D%209%29.%20%0A%20%20%20%20%20%20%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D%0AORDER%20BY%20DESC%28%3Fage%29 Try it!]
=== Miejscowości z AHP (XVI w.) w których znajdowała się karczma ===
<syntaxhighlight lang="SPARQL" class="mw-highlight-lang-sparql">
SELECT ?item ?itemLabel ?ahp_id ?coordinate
  WHERE
  {
      ?item wdt:P403 ?ahp_id .
      ?item p:P420 ?statement .
      ?statement pq:P485 ?pointintime .
      ?statement ps:P420 ?coordinate .
      ?item p:P418 ?statement1.
      ?statement1 (ps:P418/(wdt:P56*)) wd:Q233991.
      FILTER(YEAR(?pointintime) = 1600)
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  }
</syntaxhighlight>
[https://prunus-208.man.poznan.pl/wdqs/index.html#SELECT%20%3Fitem%20%3FitemLabel%20%3Fahp_id%20%3Fcoordinate%0A%20%20WHERE%0A%20%20%7B%0A%20%20%20%20%20%20%3Fitem%20wdt%3AP403%20%3Fahp_id%20.%0A%20%20%20%20%20%20%3Fitem%20p%3AP420%20%3Fstatement%20.%0A%20%20%20%20%20%20%3Fstatement%20pq%3AP485%20%3Fpointintime%20.%0A%20%20%20%20%20%20%3Fstatement%20ps%3AP420%20%3Fcoordinate%20.%0A%20%20%20%20%20%20%3Fitem%20p%3AP418%20%3Fstatement1.%0A%20%20%20%20%20%20%3Fstatement1%20%28ps%3AP418%2F%28wdt%3AP56%2a%29%29%20wd%3AQ233991.%0A%20%20%20%20%20%20FILTER%28YEAR%28%3Fpointintime%29%20%3D%201600%29%0A%20%20%20%20%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%20%20%7D%0A Try it!]

Latest revision as of 14:41, 25 October 2023

This page is parsed by the web interface of the query service to fill the query example dialog.


Institutions

  SELECT ?institution ?institutionLabel 
  WHERE
  {
      ?institution wdt:P47 wd:Q467. # instance of Institution
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  }

Try it!

Humans

#Lists all humans with values of selected fields
SELECT ?human ?humanLabel ?fatherLabel ?motherLabel ?date_of_birth WHERE {
  ?human wdt:P47 wd:Q32.
  OPTIONAL { ?human wdt:P66 ?father. }
  OPTIONAL { ?human wdt:P68 ?mother. }
  OPTIONAL { ?human wdt:P7 ?date_of_birth. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Humans without parents

#Lists all humans without parents
SELECT ?human ?humanLabel WHERE {
  ?human wdt:P47 wd:Q32. #find humans
  MINUS {
    ?human wdt:P68 [] . # without father
    ?human wdt:P66 [] . # without mother
    ?human wdt:P65 [] . # without any unspecified parent
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!


Elements from Bogumiłowice

SELECT ?item ?itemLabel WHERE {
  ?item wdt:P30 wd:Q24. # element posiada właściwość miejsca i ta właściwość ma wartość Bogumiłowice
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Osoby urodzone między rokiem 1501 a 1525

SELECT DISTINCT ?item ?itemLabel WHERE {
  ?item wdt:P47 wd:Q32.
  ?item wdt:P7 ?birthdate.
  FILTER((?birthdate >= "1501-01-01T00:00:00Z"^^xsd:dateTime) && (?birthdate <= "1525-12-31T00:00:00Z"^^xsd:dateTime))
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Osoby o nazwisku Tarnowska/Tarnowski

SELECT DISTINCT ?item ?itemLabel ?title ?tom
WHERE 
{
  ?item wdt:P47 wd:Q32 .      # człowiek
  ?item wdt:P17 ?biogram .    # posiadający właściwość opisano w źródle
  ?biogram wdt:P47 wd:Q708 .  # która jest elementem bądącym rozdziałem
  ?biogram wdt:P106 ?title .  # tytuł biogramu
  ?biogram wdt:P167 ?book .   # publikacja, tom PSB
  ?book wdt:P107 ?tom .       # tytuł tomu PSB
  {?item wdt:P183 wd:Q23187 .} # element z właściwością family name = elementowi Tarnowski
  UNION
  {?item wdt:P183 wd:Q4511 . } # element z właściwością family name = elementowi Tarnowska
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?itemLabel

Try it!

Osoby aktywne w XVI wieku lecz bez precyzyjnie określonej daty urodzenia/śmierci

SELECT DISTINCT ?item ?itemLabel ?fluorit WHERE {
  ?item wdt:P47 wd:Q32.
  ?item wdt:P54 ?fluorit.
  FILTER ((?fluorit >= "+1501-01-01T00:00:00Z"^^xsd:dateTime) && (?fluorit <= "+1600-01-01T00:00:00Z"^^xsd:dateTime))
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Osoby żyjące w XVI wieku - urodzone, zmarłe lub aktywne

SELECT * WHERE
{ 
 
  { 
    SELECT DISTINCT ?item ?itemLabel WHERE {
    ?item wdt:P47 wd:Q32.
    ?item wdt:P7 ?birthdate.
    ?item wdt:P8 ?deathdate. 
    FILTER(
           ((?birthdate >= "1501-01-01T00:00:00Z"^^xsd:dateTime) && (?birthdate <= "1600-12-31T00:00:00Z"^^xsd:dateTime)) 
           ||
           ((?deathdate >= "1501-01-01T00:00:00Z"^^xsd:dateTime) && (?deathdate <= "1600-12-31T00:00:00Z"^^xsd:dateTime))
          ) 
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }}
  }
UNION
  {
   SELECT DISTINCT ?item ?itemLabel WHERE {
    ?item wdt:P47 wd:Q32.
    ?item wdt:P54 ?fluorit.
    FILTER ((?fluorit >= "+1501-01-01T00:00:00Z"^^xsd:dateTime) && (?fluorit <= "+1600-01-01T00:00:00Z"^^xsd:dateTime))
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }}
  }
   
}
ORDER BY ?itemLabel

Try it!

Wiek w chwili śmierci dla osób z datą urodzenia/śmierci znaną co do roku

SELECT ?item ?itemLabel ?age 
WHERE {
        ?item wdt:P47 wd:Q32 .
        ?item p:P7/psv:P7 ?birth_date_node . 
        ?item p:P8/psv:P8 ?death_date_node .
        ?birth_date_node wikibase:timeValue ?birth_date.
        ?death_date_node wikibase:timeValue ?death_date.
        ?birth_date_node wikibase:timePrecision ?birth_precision.
        ?death_date_node wikibase:timePrecision ?death_precision.
        BIND( YEAR(?death_date) - YEAR(?birth_date) - 
              IF(MONTH(?death_date)<MONTH(?birth_date) || 
                 (MONTH(?death_date)=MONTH(?birth_date) && DAY(?death_date)<DAY(?birth_date)),1,0) AS ?age )
        FILTER(?age > 0 && ?age < 110 && ?birth_precision >= 9 && ?death_precision >= 9). 
        SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?age)

Try it!

Miejscowości z AHP (XVI w.) w których znajdowała się karczma

SELECT ?item ?itemLabel ?ahp_id ?coordinate
  WHERE
  {
      ?item wdt:P403 ?ahp_id .
      ?item p:P420 ?statement .
      ?statement pq:P485 ?pointintime .
      ?statement ps:P420 ?coordinate .
      ?item p:P418 ?statement1.
      ?statement1 (ps:P418/(wdt:P56*)) wd:Q233991.
      FILTER(YEAR(?pointintime) = 1600)
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  }

Try it!