Queries: Difference between revisions

From Semantic Name Authority Repository Cymru
Jump to navigation Jump to search
No edit summary
No edit summary
Line 4: Line 4:
== Federated query with Wikidata ==
== Federated query with Wikidata ==
# Occupations from SNARC with additional information on Subclass from Wikidata (Library of congress ID from both)
# Occupations from SNARC with additional information on Subclass from Wikidata (Library of congress ID from both)
{{SPARQL|query=#Returns a list of Wikidata items for a given list of Wikipedia article names
#List of Wikipedia article names (lemma) is like "WIKIPEDIA ARTICLE NAME"@LANGUAGE CODE with de for German, en for English, etc.
#Language version and project is defined in schema:isPartOF with de.wikipedia.org for German Wikipedia, es.wikivoyage for Spanish Wikivoyage, etc.


SELECT ?lemma ?item WHERE {
<syntaxhighlight lang="sparql">
  VALUES ?lemma {
 
    "Wikipedia"@de
PREFIX wikibase: <http://wikiba.se/ontology#>
    "Wikidata"@de
PREFIX snarcp: <https://snarc-llgc.wikibase.cloud/prop/direct/>
    "Berlin"@de
PREFIX snarcq: <https://snarc-llgc.wikibase.cloud/entity/>
    "Technische Universität Berlin"@de
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
   }
PREFIX wd: <http://www.wikidata.org/entity/>
   ?sitelink schema:about ?item;
PREFIX bd: <http://www.bigdata.com/rdf#>
    schema:isPartOf <https://de.wikipedia.org/>;
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
     schema:name ?lemma.
 
 
SELECT DISTINCT ?item ?itemLabel ?wikidataid ?libcongid  ?subclas ?subclaslabel ?libcongwikidata WHERE {
   
  ?item snarcp:P7 snarcq:Q63 .
   ?item snarcp:P62 ?wikidataid .                             
   ?item snarcp:P11 ?libcongid
 
SERVICE <https://query.wikidata.org/sparql>{
  ?wikidataid wdt:P279 ?subclas.
  ?subclas rdfs:label ?subclaslabel .
FILTER(LANG(?subclaslabel) = "en"). 
  ?subclas wdt:P244 ?libcongwikidata .
}      
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
}
}}
 
</syntaxhighlight>

Revision as of 11:11, 26 November 2022

Enghreifftiau o queries a ddefnyddiwyd i dynnu data o'r gronfa / Examples of queries used to extract data from the database

Federated query with Wikidata

  1. Occupations from SNARC with additional information on Subclass from Wikidata (Library of congress ID from both)
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX snarcp: <https://snarc-llgc.wikibase.cloud/prop/direct/>
PREFIX snarcq: <https://snarc-llgc.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 ?wikidataid ?libcongid  ?subclas ?subclaslabel ?libcongwikidata WHERE {
     
   ?item snarcp:P7 snarcq:Q63 . 
  ?item snarcp:P62 ?wikidataid .                               
  ?item snarcp:P11 ?libcongid
  
SERVICE <https://query.wikidata.org/sparql>{
  ?wikidataid wdt:P279 ?subclas.
  ?subclas rdfs:label ?subclaslabel .
 FILTER(LANG(?subclaslabel) = "en").  
  ?subclas wdt:P244 ?libcongwikidata .
}     
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}