You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SPARQL query to retrieve all rock groups, and their English labels, from Wikidata. - SPARQL
SELECT ?item ?itemLabel
WHERE {
?item wdt:P31 wd:Q5741069.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
HTTP request retrieving rock groups from the Wikidata SPARQL endpoint service - direct link
GET https://query.wikidata.org/sparql?query=SELECT%20%3Fitem%20%3FitemLabel%20%0AWHERE%20%0A%7B%0A%20%20%3Fitem%20wdt%3AP31%20wd%3AQ5741069.%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D
Using curl to transfer HTTP data about rock groups from the Wikidata SPARQL endpoint. We set the HTTP header Accept to ask the endpoint to send back the response in JSON format. - bash file
curl -H'Accept: application/json' -X GET "https://query.wikidata.org/sparql?query=SELECT%20%3Fitem%20%3FitemLabel%20%0AWHERE%20%0A%7B%0A%20%20%3Fitem%20wdt%3AP31%20wd%3AQ5741069.%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D"
Send a SPARQL query to Wikidata via HTTP using the Python library requests. - Python Script
// Define the DBO namespacevarDBO=Namespace("http://dbpedia.org/ontology/");varRDFS=Namespace("http://www.w3.org/2000/01/rdf-schema#");// The store is the object that contains all triplesvarstore=$rdf.graph();varband=$rdf.sym('http://dbpedia.org/resource/AC/DC');// Insert triples in the storestore.add(band,RDFS('label'),'AC/DC');store.add(band,DBO('genre'),$rdf.sym('http://dbpedia.org/resource/Hard_rock'));store.add(band,DBO('genre'),$rdf.sym("http://dbpedia.org/resource/Rock_and_roll"));// Retrieve all (each) or one (any) results, using wildcardsvargenres=store.each(band,DBO('genre'),undefined)for(vargenreofgenres)console.log(genre.uri);
const{ PathFactory }=require('ldflex');const{default: ComunicaEngine}=require('@ldflex/comunica');const{ namedNode }=require('@rdfjs/data-model');// The context maps properties and URIsconstcontext={"@context": {"@vocab": "http://dbpedia.org/ontology/","label": "http://www.w3.org/2000/01/rdf-schema#label",}};// The query engine interact with the SPARQL endpointconstendpoint='http://dbpedia.org/sparql';constqueryEngine=newComunicaEngine(endpoint);// The PathFactory is the access point to the dataconstpath=newPathFactory({ context, queryEngine });// define the band node as subject for queriesconstband=path.create({subject: namedNode('http://dbpedia.org/resource/AC/DC')});getGenres(band);asyncfunctiongetGenres(band){// Under the hood, SPARQL queries are executedconsole.log(`This band is ${awaitband.label}`);console.log(`${awaitband.label} usually plays:`);forawait(constgenreofband.genre.label)console.log(`- ${genre}`);}