« SPARQL Protocol and RDF Query Language/Requêtes d'exportation » : différence entre les versions
Contenu supprimé Contenu ajouté
m Robot : Changement de type cosmétique |
|||
Ligne 117 :
=== Avec une Requête CONSTRUCT ===
Une requête CONSTRUCT retourne un graphe RDF/XML par défaut. Le graphe obtenu est construit en fonction du patron qui est indiqué dans la clause CONSTRUCT.
Prenons par exemple la requête : [http://en.sparql.pro/wiki/Find_school_in_england Les écoles de Birmingham laïques pour les élèves de 15 ans avec moins de 300 élèves].
On veut importer les résultats dans un autre triplestore. Ce triplestore peut prendre en entrée un fichier RDF/XML (format de sauvegarde et d'importation massive). Sans savoir fabriquer un document RDF/XML, je fabrique la requête SPARQL où je remplace la définition SELECT par une définition CONSTRUCT où j'indique la structure des données que je veux obtenir.
<source lang="sql">
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sch-ont: <http://education.data.gov.uk/def/school/>
PREFIX
CONSTRUCT {
<http://solution/1> <http://solution/goodschool> ?school.
?school a sch-ont:School;
sch-ont:establishmentName ?name;
sch-ont:websiteAddress ?web .
}
WHERE {
?school a sch-ont:School;
sch-ont:establishmentName ?name;
sch-ont:schoolCapacity ?capacity ;
sch-ont:religiousCharacter sch-ont:ReligiousCharacter_Does_not_apply ;
sch-ont:statutoryHighAge ?ageMax ;
sch-ont:statutoryLowAge ?ageMin ;
geo:long ?long;
geo:lat ?lat;
sch-ont:districtAdministrative ?da .
?da rdfs:label "Birmingham".
OPTIONAL {?school sch-ont:websiteAddress ?web .}
OPTIONAL {
?school sch-ont:address ?address.
?address sch-ont:address1 ?address1;
sch-ont:postcode ?postcode;
sch-ont:town ?town.
OPTIONAL {?address sch-ont:address2 ?address2. }
}
FILTER (?capacity < 300 && ?ageMax >= 15 && ?ageMin <= 15 )
}
ORDER BY DESC(?capacity)
LIMIT 2
</source>
<source lang="xml">
<?xml version="1.0"?>
▲ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
<p:goodschool xmlns:p="http://solution/" rdf:resource="http://education.data.gov.uk/id/school/134908" />
▲ rdf:about="http://example.org/ns#x">
<rdf:Description rdf:about="http://education.data.gov.uk/id/school/134908">
<p:type xmlns:p="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:resource="http://education.data.gov.uk/def/school/School" />
</rdf:Description>▼
<p:establishmentName xmlns:p="http://education.data.gov.uk/def/school/">Elmhurst School for Dance In Association With Birmingham Royal Ballet</p:establishmentName>
<rdf:Description rdf:about="http://solution/1">
<p:goodschool xmlns:p="http://solution/" rdf:resource="http://education.data.gov.uk/id/school/135378" />
<rdf:Description rdf:about="http://education.data.gov.uk/id/school/135378">
<p:type xmlns:p="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:resource="http://education.data.gov.uk/def/school/School" />
</rdf:Description>
<rdf:Description rdf:about="http://education.data.gov.uk/id/school/135378">
<p:establishmentName xmlns:p="http://education.data.gov.uk/def/school/">Sz School</p:establishmentName>
</rdf:Description>
</rdf:RDF>
</source>
Comme pour une requête SELECT, CONSTRUCT retourne un graphe RDF en XML ou bien en Turtle ou en N3, etc. C'est en fonction du paramètre output (dans une requête HTTP POST ou GET). Attention, le format de sortie est en fonction du triplestore utilisé mais le format RDF/XML est celui indiqué dans la recommendation.
=== Avec une requête DESCRIBE ===
|