Learning SPARQL Querying and Updating with SPARQL 1.1
책 뿐만 아니라 계속 업데이트 되는 기사도 있다.
Learning SPARQL Querying and Updating with SPARQL 1.1
책 뿐만 아니라 계속 업데이트 되는 기사도 있다.
console
curl -G https://wdqs-beta.wmflabs.org/bigdata/namespace/wdq/sparql --data-urlencode query='
select distinct ?type where {
?thing a ?type
}
limit
Federated SPARQL Query, incorporating data from both DBpedia & Wikidata
```sparql PREFIX wd: http://www.wikidata.org/entity/ PREFIX wdt: http://www.wikidata.org/prop/direct/ PREFIX wikibase: http://wikiba.se/ontology# PREFIX p: http://www.wikidata.org/prop/ PREFIX ps: http://www.wikidata.org/prop/statement/ PREFIX pq: http://www.wikidata.org/prop/qualifier/ PREFIX bd: http://www.bigdata.com/rdf# PREFIX owl: http://www.w3.org/2002/07/owl# PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema# PREFIX foaf: http://xmlns.com/foaf/0.1/ PREFIX dct: http://purl.org/dc/terms/SELECT DISTINCT ?dbpediaID AS ?href xsd:string(?label) AS ?name ?description ?subjectText ?item AS ?wikidataID ?dbpediaID ?image ?picture WHERE { SERVICE http://query.wikidata.org/sparql { SELECT DISTINCT ?item ?itemLabel ?numero ( SAMPLE(?pic) AS ?picture ) WHERE { ?item p:P528 ?catalogStatement . ?catalogStatement ps:P528 ?numero . ?catalogStatement pq:P972 wd:Q14530 . OPTIONAL { ?item wdt:P18 ?pic } . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } GROUP BY ?item ?itemLabel ?numero ORDER BY ?numero }
SERVICE <http://dbpedia.org/sparql>
{
SELECT ?item
?dbpediaID
?label
?image
?description
?subjectText
FROM <http://dbpedia.org>
WHERE
{
?dbpediaID owl:sameAs ?item ;
rdfs:label ?label ;
foaf:depiction ?image ;
rdfs:comment ?description ;
dct:subject
[ rdfs:label ?subjectText ] .
FILTER ( LANG(?label) = "en" )
FILTER ( LANG(?description) = "en" )
}
}
} ```
```sparql PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema# PREFIX owl: http://www.w3.org/2002/07/owl#
SELECT ?superclass ?subclass FROM http://dbpedia.org WHERE {?superclass a owl:Class ; rdfs:subClassOf+ ?subclass }
LIMIT 100 ```
```sparql PREFIX pm20: http://purl.org/pressemappe20/folder/ PREFIX p: http://www.wikidata.org/prop/ PREFIX pq: http://www.wikidata.org/prop/qualifier/ PREFIX skos: http://www.w3.org/2004/02/skos/core# PREFIX wdt: http://www.wikidata.org/prop/direct/ PREFIX wd: http://www.wikidata.org/entity/
SELECT ?wd ?skosRelation ?pm20
where { service https://query.wikidata.org/sparql { # wd items with PM20 ID ?wd wdt:P4293 ?pm20Id . filter(isLiteral(?pm20Id)) # # mapping relation optional { ?wd p:P4293/pq:P4390 ?relation . # URL of the equivalent skos property ?relation wdt:P2699 ?skosRelation1 . } } # bind as URIs bind(uri(concat('http://purl.org/pressemappe20/folder/', ?pm20Id)) as ?pm20) bind(if(bound(?skosRelation1), ?skosRelation1, uri('http://www.w3.org/2004/02/skos/core#exactMatch')) as ?skosRelation) } ```
For example, when merging four different datasets, you can use the following query on DBpedia to select everything about Sofia:
sparql
SELECT * {
{
<http://dbpedia.org/resource/Sofia> ?p ?o .
}
UNION
{
<http://data.nytimes.com/nytimes:N82091399958465550531> ?p ?o .
}
UNION
{
<http://sws.geonames.org/727011/> ?p ?o .
}
UNION
{
<http://rdf.freebase.com/ns/m/0ftjx> ?p ?o .
}
}
sparql
SELECT * {
?s ?p ?o
FILTER (?s IN (
<http://dbpedia.org/resource/Sofia>,
<http://data.nytimes.com/nytimes:N82091399958465550531>,
<http://sws.geonames.org/727011/>,
<http://rdf.freebase.com/ns/m/0ftjx>))
}
```bash
GET /sparql/ HTTP/1.1 Host: www.example
HTTP/1.1 200 OK Date: Fri, 09 Oct 2009 17:31:12 GMT Server: Apache/1.3.29 (Unix) PHP/4.3.4 DAV/1.0.3 Connection: close Content-Type: application/rdf+xml
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sd="http://www.w3.org/ns/sparql-service-description#" xmlns:prof="http://www.w3.org/ns/owl-profile/" xmlns:void="http://rdfs.org/ns/void#"> <sd:Service> <sd:endpoint rdf:resource="http://www.example/sparql/"/> <sd:supportedLanguage rdf:resource="http://www.w3.org/ns/sparql-service-description#SPARQL11Query"/> <sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/RDF_XML"/> <sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/Turtle"/> <sd:feature rdf:resource="http://www.w3.org/ns/sparql-service-description#DereferencesURIs"/> <sd:defaultEntailmentRegime rdf:resource="http://www.w3.org/ns/entailment/RDFS"/> <sd:extensionFunction> <sd:Function rdf:about="http://example.org/Distance"/> </sd:extensionFunction> <sd:defaultDataset> <sd:Dataset> <sd:defaultGraph> <sd:Graph> <void:triples rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">100</void:triples> </sd:Graph> </sd:defaultGraph> <sd:namedGraph> <sd:NamedGraph> <sd:name rdf:resource="http://www.example/named-graph"/> <sd:entailmentRegime rdf:resource="http://www.w3.org/ns/entailment/OWL-RDF-Based"/> <sd:supportedEntailmentProfile rdf:resource="http://www.w3.org/ns/owl-profile/RL"/> <sd:graph> <sd:Graph> <void:triples rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">2000</void:triples> </sd:Graph> </sd:graph> </sd:NamedGraph> </sd:namedGraph> </sd:Dataset> </sd:defaultDataset> </sd:Service> </rdf:RDF> ```
sparql
SELECT ?type (COUNT(DISTINCT ?oeuvre) AS ?c) WHERE {
VALUES ?type { wd:Q838948 }
?oeuvre wdt:P31 ?type.
{ ?oeuvre ?link ?museum. } union { ?museum ?link ?oeuvre. }
?museum wdt:P31 wd:Q33506.
}
GROUP BY ?type
ORDER BY DESC (?c)
sparql
SELECT ?type (COUNT(DISTINCT ?oeuvre) AS ?c)
WHERE {
VALUES ?type {
<http://schema.org/CreativeWork>
<http://schema.org/Painting>
<http://dbpedia.org/ontology/Artwork>
<http://dbpedia.org/ontology/Painting>
}
?oeuvre a ?type .
}
GROUP BY ?type
ORDER BY desc(?c)
```sparql PREFIX wd: http://www.wikidata.org/entity/ PREFIX gist: https://ontologies.semanticarts.com/gist/ PREFIX dcterms: http://purl.org/dc/terms/
SELECT DISTINCT ?commitTitle ?commitTime ?filename ?textLine WHERE {
?commit a wd:Q20058545 ; # it's a commit gist:hasPart ?part ; dcterms:subject ?commitSubject ; gist:atDateTime ?commitTime .
?commitSubject dcterms:title ?commitTitle .
?part gist:produces ?contiguousLines .
?contiguousLines gist:occursIn ?file ; http://example.com/containedTextContainer ?textContainer .
?file gist:name ?filename . ?textContainer ?line ?textLine .
FILTER(contains(?textLine,"music")) } ```
kit_wikidata PigmentosBIOcolores
SPARQL
bash
curl -H 'Accept: application/ld+json' https://musicbrainz.org/artist/20ff3303-4fe2-4a47-a1b6-291e26aa3438
Servizi
Forse evidenzierei di già la possibilità di usare standard come SPARQL per accedere ai dati. Mentre per accedere ai dati in CSV (o dati su database) ho necessità di creare delle interfacce ad-hoc
```sparql PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema# PREFIX i: http://learningsparql.com/ns/instrument/ PREFIX s: http://learningsparql.com/ns/schema/ PREFIX b: http://www.bobdc.com/ns/beatles/
SELECT ?britishGroup WHERE { ?bassist b:favoriteBritishGroup ?britishGroup . SERVICE https://dydra.com/bobdc/beatles-musicians/sparql { SELECT ?bassist WHERE { ?song a s:Song ; rdfs:label "The Long And Winding Road" ; i:bass ?bassist . } } } ```
sparql
PREFIX osmt: <https://wiki.openstreetmap.org/wiki/Key:>
SELECT * WHERE {
?museum osmt:addr:city "New York";
osmt:tourism "museum";
osmt:wikidata ?wikidataID .
}
```sparql PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# PREFIX skos: http://www.w3.org/2004/02/skos/core# PREFIX schema: http://schema.org/ prefix owl: http://www.w3.org/2002/07/owl# prefix rdfs: http://www.w3.org/2000/01/rdf-schema#
CONSTRUCT { http://schema.org/ a skos:ConceptScheme ; skos:hasTopConcept schema:Thing . ?child a skos:Concept ; skos:broaderTransitive ?parent ; skos:broader ?ancestors ; skos:prefLabel ?label ; skos:definition ?desc ; skos:inScheme ?ext . ?parent skos:narrowerTransitive ?child . ?ancestors skos:narrower ?child .<br /> } WHERE { ?child rdfs:subClassOf ?parent . ?child rdfs:subClassOf+ ?ancestors . OPTIONAL { ?child rdfs:label ?label } OPTIONAL { ?child rdfs:comment ?desc } OPTIONAL { ?child schema:isPartOf ?ext } } ```
sparql
PREFIX food: <https://data.lirmm.fr/ontologies/food#>
SELECT ?s ?code WHERE {
?s <https://www.w3.org/1999/02/22-rdf-syntax-ns#type> food:FoodProduct .
?s food:containsIngredient ?i .
?i food:food <https://fr.openfoodfacts.org/ingredient/sucre> .
?i food:rank "1"
OPTIONAL { ?s food:code ?code } .
}
Zusätzlich bietet die Abfragesprache SPARQL die Möglichkeit,RDF-kodierte semantische Daten strukturiert abzufragen, wobei bereits (beschränkter)Gebrauch der Möglichkeit logischer Schlussfolgerungen gemacht werden kann.
SPARQL = Abfragesprache von RDF
sql
use "http://triplr.org/sparyql/sparql.xml" as sparql;
select * from sparql where query="PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT $nick $name FROM <http://www.dajobe.org/foaf.rdf> WHERE { $x a foaf:Person . $x foaf:nick $nick . $x foaf:name $name }"
and service="http://sparql.org/sparql"
```xml <iq to='crschmidt@crschmidt.net/sparql' type='get' id='2'> <query xmlns='http://www.w3.org/2005/09/xmpp-sparql-binding'> SELECT ?a WHERE { ?a &http://xmlns.com/foaf/0.1/nick> "crschmidt". } </query> </iq>
<iq to='crschmidt@crschmidt.net/sparql' type='result' id='2' from='crschmidt@crschmidt.net/sparql'> <query xmlns='http://www.w3.org/2005/09/xmpp-sparql-binding'> <meta /> <sparql xmlns='http://www.w3.org/2001/sw/DataAccess/rf1/result'> <head> <variable name='a'/> </head> <results> <result> </result> <result> </result> <result> </result> </results> </sparql> </query> </iq> ```
Grappa : A GraphQL-SPARQL-Bridge test tool
Flexible SPARQL and GraphQL over decentralized RDF on the Web.
Note that variables cannot appear in the predicate position.