Project:SPARQL/examples: Difference between revisions

From KBTestWikibase
Jump to navigation Jump to search
Tag: Manual revert
 
(21 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Examples==
==Voorbeelden==
<big>''De queries op deze pagina worden in de Voorbeelden-dropdown op https://kbtestwikibase.wikibase.cloud/query/ weergegeven.''</big>


===Alle Ps in deze Wikibase===
=== Overview of properties (Ps) in this Wikibase, with their Labels, Descriptions and Aliases, both in NL and in EN, as well their equivalent properties in Wikidata (if applicable) ===  


<sparql tryit="1">
<sparql tryit="1">
#All properties with descriptions and aliases and types
# Overview of properties in this Wikibase,
# with their Labels, Descriptions and Aliases,
# both in NL and in EN,
# as well their equivalent properties in Wikidata (if applicable)
 
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <https://kbtestwikibase.wikibase.cloud/prop/direct/>
SELECT DISTINCT ?p ?pType
?pLabelNL ?pLabelEN
?pDescriptionNL ?pDescriptionEN
(GROUP_CONCAT(DISTINCT ?pAliasNL ; separator = "|") as ?pAliasesNL )
(GROUP_CONCAT(DISTINCT ?pAliasEN ; separator = "|") as ?pAliasesEN )
?wikidataEquivalentProperty
WHERE {
  ?p wikibase:propertyType ?pType .
  OPTIONAL{?p wdt:P1 ?wikidataEquivalentProperty.}


SELECT ?property ?propertyType ?propertyLabel ?propertyDescription ?propertyAltLabel WHERE {
  OPTIONAL{?p rdfs:label ?pLabelNL FILTER(LANG(?pLabelNL)='nl').}
   ?property wikibase:propertyType ?propertyType .
  OPTIONAL{?p rdfs:label ?pLabelEN FILTER(LANG(?pLabelEN)='en').}
   # or:   ?property rdf:type wikibase:Property
 
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL{?p schema:description ?pDescriptionNL FILTER(LANG(?pDescriptionNL) = "nl"). } 
   OPTIONAL{?p schema:description ?pDescriptionEN FILTER(LANG(?pDescriptionEN) = "en"). }
    
   OPTIONAL{?p skos:altLabel ?pAliasNL FILTER(LANG(?pAliasNL) = "nl"). } 
   OPTIONAL{?p skos:altLabel ?pAliasEN FILTER(LANG(?pAliasEN) = "en"). }    
   
}
}
ORDER BY ASC(xsd:integer(STRAFTER(STR(?property), 'P')))
GROUP BY ?p ?pType ?pLabelNL ?pLabelEN ?pDescriptionNL ?pDescriptionEN ?wikidataEquivalentProperty
ORDER BY ASC(xsd:integer(STRAFTER(STR(?p), 'P')))
</sparql>
</sparql>


=== Alle Qs in deze Wikibase===
=== Overview of items (Qs) in this Wikibase, with their Labels, Descriptions and Aliases, both in NL and in EN, as well their equivalent Q-items en URIs in Wikidata (if applicable) ===


<sparql tryit="1">
<sparql tryit="1">
# All Qnumbers in this Wikibase
# Overview of items (Qs) in this Wikibase,
# with their Labels, Descriptions and Aliases,
# both in NL and in EN,
# as well their equivalent Q-items en URIs in Wikidata (if applicable)
 
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT ?identifier ?identifierLabel ?identifierDescription ?identifierAltLabel
PREFIX wdt: <https://kbtestwikibase.wikibase.cloud/prop/direct/>
 
SELECT DISTINCT ?item ?itemLabelNL ?itemLabelEN
?itemDescriptionNL ?itemDescriptionEN
(GROUP_CONCAT(DISTINCT ?itemAliasNL ; separator = "|") as ?itemAliasesNL )
(GROUP_CONCAT(DISTINCT ?itemAliasEN ; separator = "|") as ?itemAliasesEN )
?wikidataEquivalentURI ?wikidataEquivalentItem
 
WHERE  
WHERE  
{
{
    ?identifier wikibase:identifiers ?b
  ?item wikibase:identifiers ?b
   SERVICE wikibase:label { bd:serviceParam wikibase:language "nl". }
   OPTIONAL{?item wdt:P1 ?wikidataEquivalentURI.}
  OPTIONAL{?item wdt:P4 ?wikidataEquivalentItem.}
 
  OPTIONAL{?item rdfs:label ?itemLabelNL FILTER(LANG(?itemLabelNL)='nl').}
  OPTIONAL{?item rdfs:label ?itemLabelEN FILTER(LANG(?itemLabelEN)='en').}
 
  OPTIONAL{?item schema:description ?itemDescriptionNL FILTER(LANG(?itemDescriptionNL) = "nl"). } 
  OPTIONAL{?item schema:description ?itemDescriptionEN FILTER(LANG(?itemDescriptionEN) = "en"). }
 
  OPTIONAL{?item skos:altLabel ?itemAliasNL FILTER(LANG(?itemAliasNL) = "nl"). } 
  OPTIONAL{?item skos:altLabel ?itemAliasEN FILTER(LANG(?itemAliasEN) = "en"). }    
   
}
}
ORDER BY ASC(xsd:integer(STRAFTER(STR(?identifier), 'Q')))
GROUP BY ?item ?itemLabelNL ?itemLabelEN ?itemDescriptionNL ?itemDescriptionEN ?wikidataEquivalentURI ?wikidataEquivalentItem 
ORDER BY ASC(xsd:integer(STRAFTER(STR(?item), 'Q')))
</sparql>
</sparql>


Line 66: Line 119:
</sparql>
</sparql>


=== Overview of properties in this Wikibase, with their Labels, Descriptions and Aliases, both in NL and in EN, as well their equivalent properties in Wikidata (if applicable) ===  
===Dingen die een instantie (P3) zijn van andere dingen===


<sparql tryit="1">
<sparql tryit="1">
# Overview of properties in this Wikibase,
# Dingen die een instantie (P3) zijn van andere dingen
# with their Labels, Descriptions and Aliases,
PREFIX wd: <https://kbtestwikibase.wikibase.cloud/entity/>
# both in NL and in EN,
PREFIX wdt: <https://kbtestwikibase.wikibase.cloud/prop/direct/>
# as well their equivalent properties in Wikidata (if applicable)
PREFIX wikibase: <http://wikiba.se/ontology#>
 
SELECT ?ding ?dingLabel ?dingDescription  ?IsEen ?IsEenLabel ?IsEenDescription WHERE
{
?ding wdt:P3 ?IsEen
  SERVICE wikibase:label { bd:serviceParam wikibase:language "nl". }
}
</sparql>
 
=== Federated querying: mixing data from this Wikibase with data from Wikidata ===


PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
<sparql tryit="1">
PREFIX schema: <http://schema.org/>
# Federated querying: mixing data from this Wikibase with data from Wikidata
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX kbwdt: <https://kbtestwikibase.wikibase.cloud/prop/direct/>
PREFIX kbwd: <https://kbtestwikibase.wikibase.cloud/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <https://kbtestwikibase.wikibase.cloud/prop/direct/>


SELECT ?p ?pType
SELECT DISTINCT ?item ?itemLabel ?itemDescription
?pLabelNL ?pLabelEN
?wikidataEquivalentURI
?pDescriptionNL ?pDescriptionEN
?wdImage #P18 image from Wikidata
(GROUP_CONCAT(DISTINCT ?pAliasNL ; separator = "|") as ?pAliasesNL )
?wdWorksInCollection ?wdWorksInCollectionLabelNL
(GROUP_CONCAT(DISTINCT ?pAliasEN ; separator = "|") as ?pAliasesEN )
 
?wikidataEquivalentProperty
WHERE
{
  VALUES ?item {kbwd:Q10 kbwd:Q29} # Louis Auguste Gustave Doré + Theun de Vries
  ?item kbwdt:P1 ?wikidataEquivalentURI.
  #Retrieve some data from Wikidata
  SERVICE <https://query.wikidata.org/sparql>{
  OPTIONAL {?wikidataEquivalentURI wdt:P18 ?wdImage.}
  OPTIONAL {?wikidataEquivalentURI wdt:P6379 ?wdWorksInCollection.
          ?wdWorksInCollection rdfs:label ?wdWorksInCollectionLabelNL.
          FILTER(LANG(?wdWorksInCollectionLabelNL) = "nl").} 
}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nl". }
}
ORDER BY ASC(xsd:integer(STRAFTER(STR(?item), 'Q')))
</sparql>
 
=== Federated querying: mixing data from this Wikibase with data from the NTA in data.bibliotheken.nl (via the PPN) -- TODO!!!!!!!!! ===


WHERE {
<sparql tryit="1">
# Federated querying: mixing data from this Wikibase with data from the NTA in data.bibliotheken.nl (via the PPN)
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX kbwdt: <https://kbtestwikibase.wikibase.cloud/prop/direct/>
PREFIX kbwd: <https://kbtestwikibase.wikibase.cloud/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>


  ?p wikibase:propertyType ?pType .
SELECT DISTINCT ?item ?itemLabel ?itemDescription
  OPTIONAL{?p wdt:P1 ?wikidataEquivalentProperty.}
?wikidataEquivalentURI
?wdImage #P18 image from Wikidata
?wdWorksInCollection ?wdWorksInCollectionLabelNL


   OPTIONAL{?p rdfs:label ?pLabelNL FILTER(LANG(?pLabelNL)='nl').}
WHERE
   OPTIONAL{?p rdfs:label ?pLabelEN FILTER(LANG(?pLabelEN)='en').}
{
    
   VALUES ?item {kbwd:Q10 kbwd:Q29} # Louis Auguste Gustave Doré + Theun de Vries
   OPTIONAL{?p schema:description ?pDescriptionNL FILTER(LANG(?pDescriptionNL) = "nl"). }
   ?item kbwdt:P1 ?wikidataEquivalentURI.
   OPTIONAL{?p schema:description ?pDescriptionEN FILTER(LANG(?pDescriptionEN) = "en"). }
  #Retrieve some data from data.bibliotheken.nl
 
   SERVICE <https://query.wikidata.org/sparql>{
  OPTIONAL{?p skos:altLabel ?pAliasNL FILTER(LANG(?pAliasNL) = "nl"). }   
   OPTIONAL {?wikidataEquivalentURI wdt:P18 ?wdImage.}
   OPTIONAL{?p skos:altLabel ?pAliasEN FILTER(LANG(?pAliasEN) = "en"). }    
   OPTIONAL {?wikidataEquivalentURI wdt:P6379 ?wdWorksInCollection.
   
          ?wdWorksInCollection rdfs:label ?wdWorksInCollectionLabelNL.
          FILTER(LANG(?wdWorksInCollectionLabelNL) = "nl").}   
}
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nl". }  
}
}
GROUP BY ?p ?pType ?pLabelNL ?pLabelEN ?pDescriptionNL ?pDescriptionEN ?wikidataEquivalentProperty
ORDER BY ASC(xsd:integer(STRAFTER(STR(?item), 'Q')))
ORDER BY ASC(xsd:integer(STRAFTER(STR(?p), 'P')))
</sparql>
</sparql>

Latest revision as of 13:27, 22 March 2023

Voorbeelden

De queries op deze pagina worden in de Voorbeelden-dropdown op https://kbtestwikibase.wikibase.cloud/query/ weergegeven.

Overview of properties (Ps) in this Wikibase, with their Labels, Descriptions and Aliases, both in NL and in EN, as well their equivalent properties in Wikidata (if applicable)

# Overview of properties in this Wikibase, 
# with their Labels, Descriptions and Aliases, 
# both in NL and in EN, 
# as well their equivalent properties in Wikidata (if applicable) 

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <https://kbtestwikibase.wikibase.cloud/prop/direct/>

SELECT DISTINCT ?p ?pType 
?pLabelNL ?pLabelEN 
?pDescriptionNL ?pDescriptionEN 
(GROUP_CONCAT(DISTINCT ?pAliasNL ; separator = "|") as ?pAliasesNL )
(GROUP_CONCAT(DISTINCT ?pAliasEN ; separator = "|") as ?pAliasesEN )
?wikidataEquivalentProperty

WHERE {

  ?p wikibase:propertyType ?pType .
  OPTIONAL{?p wdt:P1 ?wikidataEquivalentProperty.} 

  OPTIONAL{?p rdfs:label ?pLabelNL FILTER(LANG(?pLabelNL)='nl').}
  OPTIONAL{?p rdfs:label ?pLabelEN FILTER(LANG(?pLabelEN)='en').}
  
  OPTIONAL{?p schema:description ?pDescriptionNL FILTER(LANG(?pDescriptionNL) = "nl"). }  
  OPTIONAL{?p schema:description ?pDescriptionEN FILTER(LANG(?pDescriptionEN) = "en"). }
  
  OPTIONAL{?p skos:altLabel ?pAliasNL FILTER(LANG(?pAliasNL) = "nl"). }  
  OPTIONAL{?p skos:altLabel ?pAliasEN FILTER(LANG(?pAliasEN) = "en"). }     
    
}
GROUP BY ?p ?pType ?pLabelNL ?pLabelEN ?pDescriptionNL ?pDescriptionEN ?wikidataEquivalentProperty
ORDER BY ASC(xsd:integer(STRAFTER(STR(?p), 'P')))

Try it!


Overview of items (Qs) in this Wikibase, with their Labels, Descriptions and Aliases, both in NL and in EN, as well their equivalent Q-items en URIs in Wikidata (if applicable)

# Overview of items (Qs) in this Wikibase, 
# with their Labels, Descriptions and Aliases, 
# both in NL and in EN, 
# as well their equivalent Q-items en URIs in Wikidata (if applicable) 

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <https://kbtestwikibase.wikibase.cloud/prop/direct/>

SELECT DISTINCT ?item ?itemLabelNL ?itemLabelEN 
?itemDescriptionNL ?itemDescriptionEN 
(GROUP_CONCAT(DISTINCT ?itemAliasNL ; separator = "|") as ?itemAliasesNL )
(GROUP_CONCAT(DISTINCT ?itemAliasEN ; separator = "|") as ?itemAliasesEN )
?wikidataEquivalentURI ?wikidataEquivalentItem 

WHERE 
{
  ?item wikibase:identifiers ?b
  OPTIONAL{?item wdt:P1 ?wikidataEquivalentURI.} 
  OPTIONAL{?item wdt:P4 ?wikidataEquivalentItem.} 

  OPTIONAL{?item rdfs:label ?itemLabelNL FILTER(LANG(?itemLabelNL)='nl').}
  OPTIONAL{?item rdfs:label ?itemLabelEN FILTER(LANG(?itemLabelEN)='en').}
  
  OPTIONAL{?item schema:description ?itemDescriptionNL FILTER(LANG(?itemDescriptionNL) = "nl"). }  
  OPTIONAL{?item schema:description ?itemDescriptionEN FILTER(LANG(?itemDescriptionEN) = "en"). }
  
  OPTIONAL{?item skos:altLabel ?itemAliasNL FILTER(LANG(?itemAliasNL) = "nl"). }  
  OPTIONAL{?item skos:altLabel ?itemAliasEN FILTER(LANG(?itemAliasEN) = "en"). }     
    
}
GROUP BY ?item ?itemLabelNL ?itemLabelEN ?itemDescriptionNL ?itemDescriptionEN ?wikidataEquivalentURI ?wikidataEquivalentItem  
ORDER BY ASC(xsd:integer(STRAFTER(STR(?item), 'Q')))

Try it!


Alle Ps en Qs samen

# All Ps and Qs in this Wikibase
PREFIX wikibase: <http://wikiba.se/ontology#>

SELECT  ?statement ?statementLabel ?statementDescription ?statementAltLabel
WHERE 
{
   ?statement wikibase:statements ?b
  SERVICE wikibase:label { bd:serviceParam wikibase:language "nl". }
}
ORDER BY ?statement

Try it!


Claim ids (GUID) for Qnumbers in this Wikibase

# Find claim ids (GUID) for Qnumbers in this Wikibase
# https://kbtestwikibase.wikibase.cloud/w/api.php?action=help&modules=wbgetclaims
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX p: <https://kbtestwikibase.wikibase.cloud/prop/>
PREFIX ps: <https://kbtestwikibase.wikibase.cloud/prop/statement/>

SELECT  ?item ?itemLabel ?itemDescription ?claim ?IsEenLabel
WHERE 
{
    ?item wikibase:identifiers ?b.
    ?item p:P3 ?claim.            
    ?claim ps:P3 ?IsEen.           

  SERVICE wikibase:label { bd:serviceParam wikibase:language "nl". }
}
ORDER BY ASC(xsd:integer(STRAFTER(STR(?item), 'Q')))
LIMIT 35

Try it!


Dingen die een instantie (P3) zijn van andere dingen

# Dingen die een instantie (P3) zijn van andere dingen
PREFIX wd: <https://kbtestwikibase.wikibase.cloud/entity/>
PREFIX wdt: <https://kbtestwikibase.wikibase.cloud/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>

SELECT ?ding ?dingLabel ?dingDescription  ?IsEen ?IsEenLabel ?IsEenDescription WHERE
{
?ding wdt:P3 ?IsEen 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "nl". }
}

Try it!


Federated querying: mixing data from this Wikibase with data from Wikidata

# Federated querying: mixing data from this Wikibase with data from Wikidata 
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX kbwdt: <https://kbtestwikibase.wikibase.cloud/prop/direct/>
PREFIX kbwd: <https://kbtestwikibase.wikibase.cloud/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?item ?itemLabel ?itemDescription
?wikidataEquivalentURI
?wdImage #P18 image from Wikidata
?wdWorksInCollection ?wdWorksInCollectionLabelNL

WHERE 
{
  VALUES ?item {kbwd:Q10 kbwd:Q29} # Louis Auguste Gustave Doré + Theun de Vries 
  ?item kbwdt:P1 ?wikidataEquivalentURI.
  #Retrieve some data from Wikidata
  SERVICE <https://query.wikidata.org/sparql>{
  OPTIONAL {?wikidataEquivalentURI wdt:P18 ?wdImage.}
  OPTIONAL {?wikidataEquivalentURI wdt:P6379 ?wdWorksInCollection.
           ?wdWorksInCollection rdfs:label ?wdWorksInCollectionLabelNL.
           FILTER(LANG(?wdWorksInCollectionLabelNL) = "nl").}  
 }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nl". } 
}
ORDER BY ASC(xsd:integer(STRAFTER(STR(?item), 'Q')))

Try it!


Federated querying: mixing data from this Wikibase with data from the NTA in data.bibliotheken.nl (via the PPN) -- TODO!!!!!!!!!

# Federated querying: mixing data from this Wikibase with data from the NTA in data.bibliotheken.nl (via the PPN)
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX kbwdt: <https://kbtestwikibase.wikibase.cloud/prop/direct/>
PREFIX kbwd: <https://kbtestwikibase.wikibase.cloud/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?item ?itemLabel ?itemDescription
?wikidataEquivalentURI
?wdImage #P18 image from Wikidata
?wdWorksInCollection ?wdWorksInCollectionLabelNL

WHERE 
{
  VALUES ?item {kbwd:Q10 kbwd:Q29} # Louis Auguste Gustave Doré + Theun de Vries 
  ?item kbwdt:P1 ?wikidataEquivalentURI.
  #Retrieve some data from data.bibliotheken.nl
  SERVICE <https://query.wikidata.org/sparql>{
  OPTIONAL {?wikidataEquivalentURI wdt:P18 ?wdImage.}
  OPTIONAL {?wikidataEquivalentURI wdt:P6379 ?wdWorksInCollection.
           ?wdWorksInCollection rdfs:label ?wdWorksInCollectionLabelNL.
           FILTER(LANG(?wdWorksInCollectionLabelNL) = "nl").}  
 }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nl". } 
}
ORDER BY ASC(xsd:integer(STRAFTER(STR(?item), 'Q')))

Try it!