« Project:SPARQL query service/examples » : différence entre les versions

De Référentiels d’autorité Biblissima
Aller à la navigation Aller à la recherche
Aucun résumé des modifications
Ligne 351 : Ligne 351 :


[https://data-dev.biblissima.fr/query/#SELECT%20DISTINCT%20%3Fentity%20%0A%28GROUP_CONCAT%28%3Fidbbma%3B%20separator%3D%22%23%23%23%22%29%20AS%20%3Fid_portail_biblissima%29%0A%28GROUP_CONCAT%28%3Fidbibale%3B%20separator%3D%22%23%23%23%22%29%20AS%20%3Fid_bibale%29%0A%28GROUP_CONCAT%28%3Fidjonas%3B%20separator%3D%22%23%23%23%22%29%20AS%20%3Fid_jonas%29%0A%28GROUP_CONCAT%28%3Fidpinakes%3B%20separator%3D%22%23%23%23%22%29%20AS%20%3Fid_pinakes%29%0A%28GROUP_CONCAT%28%3Fidinitiale%3B%20separator%3D%22%23%23%23%22%29%20AS%20%3Fid_initiale%29%0AWHERE%0A%7B%0A%20%20%20%20%3Fentity%20wdt%3AP2%20wd%3AQ168%20.%0A%20%20%20%20OPTIONAL%20%7B%20%3Fentity%20wdt%3AP129%20%3Fidbbma%20%7D%0A%20%20%20%20OPTIONAL%20%7B%20%3Fentity%20wdt%3AP140%20%3Fidjonas%20%7D%0A%20%20%20%20OPTIONAL%20%7B%20%3Fentity%20wdt%3AP131%20%3Fidbibale%20%7D%0A%20%20%20%20OPTIONAL%20%7B%20%3Fentity%20wdt%3AP145%20%3Fidpinakes%20%7D%0A%20%20%20%20OPTIONAL%20%7B%20%3Fentity%20wdt%3AP139%20%3Fidinitiale%20%7D%0A%20%20%20%20FILTER%28%3Fidjonas%20%21%3D%20%22%22%20%7C%7C%20%3Fidbibale%20%21%3D%20%22%22%20%7C%7C%20%3Fidpinakes%20%21%3D%20%22%22%20%7C%7C%20%3Fidinitiale%20%21%3D%20%22%22%29%0A%7D%0AGROUP%20BY%20%3Fentity Try it!]
[https://data-dev.biblissima.fr/query/#SELECT%20DISTINCT%20%3Fentity%20%0A%28GROUP_CONCAT%28%3Fidbbma%3B%20separator%3D%22%23%23%23%22%29%20AS%20%3Fid_portail_biblissima%29%0A%28GROUP_CONCAT%28%3Fidbibale%3B%20separator%3D%22%23%23%23%22%29%20AS%20%3Fid_bibale%29%0A%28GROUP_CONCAT%28%3Fidjonas%3B%20separator%3D%22%23%23%23%22%29%20AS%20%3Fid_jonas%29%0A%28GROUP_CONCAT%28%3Fidpinakes%3B%20separator%3D%22%23%23%23%22%29%20AS%20%3Fid_pinakes%29%0A%28GROUP_CONCAT%28%3Fidinitiale%3B%20separator%3D%22%23%23%23%22%29%20AS%20%3Fid_initiale%29%0AWHERE%0A%7B%0A%20%20%20%20%3Fentity%20wdt%3AP2%20wd%3AQ168%20.%0A%20%20%20%20OPTIONAL%20%7B%20%3Fentity%20wdt%3AP129%20%3Fidbbma%20%7D%0A%20%20%20%20OPTIONAL%20%7B%20%3Fentity%20wdt%3AP140%20%3Fidjonas%20%7D%0A%20%20%20%20OPTIONAL%20%7B%20%3Fentity%20wdt%3AP131%20%3Fidbibale%20%7D%0A%20%20%20%20OPTIONAL%20%7B%20%3Fentity%20wdt%3AP145%20%3Fidpinakes%20%7D%0A%20%20%20%20OPTIONAL%20%7B%20%3Fentity%20wdt%3AP139%20%3Fidinitiale%20%7D%0A%20%20%20%20FILTER%28%3Fidjonas%20%21%3D%20%22%22%20%7C%7C%20%3Fidbibale%20%21%3D%20%22%22%20%7C%7C%20%3Fidpinakes%20%21%3D%20%22%22%20%7C%7C%20%3Fidinitiale%20%21%3D%20%22%22%29%0A%7D%0AGROUP%20BY%20%3Fentity Try it!]
==== Données sur les items numérisés ====
<syntaxhighlight lang="SPARQL">
SELECT ?entity ?idbbma
(GROUP_CONCAT(DISTINCT ?surrogates; SEPARATOR = "###") AS ?surrogate)
(GROUP_CONCAT(DISTINCT ?manifests; SEPARATOR = "###") AS ?manifest)
(GROUP_CONCAT(DISTINCT ?digitTypeLabel; SEPARATOR = "###") AS ?type_label)
(GROUP_CONCAT(DISTINCT ?dsTypeLabel; SEPARATOR = "###") AS ?ds_type_label)
WHERE {
  VALUES ?filter {
    wd:Q32810
    wd:Q113619
  }
  ?entity wdt:P129 ?uncleaned_idbbma;
    wdt:P2 ?filter;
    wdt:P197 ?surrogates;
  OPTIONAL {
    ?entity p:P197 ?ds_stmt.
    ?ds_stmt pq:P279 ?dsType.
    ?dsType rdfs:label ?_dsTypeLabel.
    FILTER((LANG(?_dsTypeLabel)) = "fr")
  }
  OPTIONAL {
    ?entity wdt:P196 ?manifests ;
    OPTIONAL {
      ?entity p:P196 ?manifest_stmt.
      ?manifest_stmt pq:P279 ?digitType.
      ?digitType rdfs:label ?_digitTypeLabel.
      FILTER((LANG(?_digitTypeLabel)) = "fr")
    }
  }
  BIND(REPLACE(?uncleaned_idbbma, '^[im]data', '') AS ?idbbma)
  BIND(COALESCE(?_dsTypeLabel, "<no label>") AS ?dsTypeLabel)
  BIND(COALESCE(?_digitTypeLabel, "<no label>") AS ?digitTypeLabel).
}
GROUP BY ?entity ?idbbma
ORDER BY ?entity
LIMIT 20000
</syntaxhighlight>
[https://data-dev.biblissima.fr/query/#SELECT%20%3Fentity%20%3Fidbbma%20%0A%28GROUP_CONCAT%28DISTINCT%20%3Fsurrogates%3B%20SEPARATOR%20%3D%20%22%23%23%23%22%29%20AS%20%3Fsurrogate%29%20%0A%28GROUP_CONCAT%28DISTINCT%20%3Fmanifests%3B%20SEPARATOR%20%3D%20%22%23%23%23%22%29%20AS%20%3Fmanifest%29%20%0A%28GROUP_CONCAT%28DISTINCT%20%3FdigitTypeLabel%3B%20SEPARATOR%20%3D%20%22%23%23%23%22%29%20AS%20%3Ftype_label%29%0A%28GROUP_CONCAT%28DISTINCT%20%3FdsTypeLabel%3B%20SEPARATOR%20%3D%20%22%23%23%23%22%29%20AS%20%3Fds_type_label%29%20%0A%0AWHERE%20%7B%0A%20%20VALUES%20%3Ffilter%20%7B%0A%20%20%20%20wd%3AQ32810%0A%20%20%20%20wd%3AQ113619%0A%20%20%7D%0A%20%20%3Fentity%20wdt%3AP129%20%3Funcleaned_idbbma%3B%0A%20%20%20%20wdt%3AP2%20%3Ffilter%3B%0A%20%20%20%20wdt%3AP197%20%3Fsurrogates%3B%0A%20%20OPTIONAL%20%7B%0A%20%20%20%20%3Fentity%20p%3AP197%20%3Fds_stmt.%0A%20%20%20%20%3Fds_stmt%20pq%3AP279%20%3FdsType.%0A%20%20%20%20%3FdsType%20rdfs%3Alabel%20%3F_dsTypeLabel.%0A%20%20%20%20FILTER%28%28LANG%28%3F_dsTypeLabel%29%29%20%3D%20%22fr%22%29%0A%20%20%7D%0A%20%20OPTIONAL%20%7B%0A%20%20%20%20%3Fentity%20wdt%3AP196%20%3Fmanifests%20%3B%0A%20%20%20%20OPTIONAL%20%7B%0A%20%20%20%20%20%20%3Fentity%20p%3AP196%20%3Fmanifest_stmt.%0A%20%20%20%20%20%20%3Fmanifest_stmt%20pq%3AP279%20%3FdigitType.%0A%20%20%20%20%20%20%3FdigitType%20rdfs%3Alabel%20%3F_digitTypeLabel.%0A%20%20%20%20%20%20FILTER%28%28LANG%28%3F_digitTypeLabel%29%29%20%3D%20%22fr%22%29%0A%20%20%20%20%7D%0A%20%20%7D%0A%0A%20%20BIND%28REPLACE%28%3Funcleaned_idbbma%2C%20%27%5E%5Bim%5Ddata%27%2C%20%27%27%29%20AS%20%3Fidbbma%29%0A%20%20BIND%28COALESCE%28%3F_dsTypeLabel%2C%20%22%3Cno%20label%3E%22%29%20AS%20%3FdsTypeLabel%29%0A%20%20BIND%28COALESCE%28%3F_digitTypeLabel%2C%20%22%3Cno%20label%3E%22%29%20AS%20%3FdigitTypeLabel%29.%0A%0A%7D%0AGROUP%20BY%20%3Fentity%20%3Fidbbma%0AORDER%20BY%20%3Fentity%0ALIMIT%2020000 Try it!]

Version du 25 novembre 2021 à 16:05

Exemples de requêtes SPARQL

Cette page liste des exemples de requêtes SPARQL permettant d'interroger en profondeur les données RDF des Référentiels Biblissima. Chaque requête peut être lancée en cliquant sur le lien "Try it!" qui ouvre une interface de requête dédiée et outillée.

Requêtes générales

Vue globale des types d'entités

SELECT ?label(count(?entity) as ?count)
WHERE {
  VALUES ?filter {
    wd:Q168
    wd:Q26719
    wd:Q32795
    wd:Q167
    wd:Q32810
    wd:Q113619
    wd:Q120865
    wd:Q120869
    wd:Q120868
  }
  {
   ?entity wdt:P2 ?filter .
   ?filter rdfs:label ?label .
  }
  UNION { ?entity wdt:P2 ?label }
  FILTER(LANG(?label) = "fr")
  #SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}
GROUP BY ?label
ORDER BY DESC(?count)

Try it!

Lieux (liste complète)

SELECT ?entity ?entityLabel ?categoryLabel ?countryLabel ?typeLabel ?idBbma
WHERE
{
  ?entity wdt:P2 wd:Q26719 .
  #wd:P129 wdt:P108 ?formatterUrl .
  OPTIONAL {
     ?type wdt:P2 wd:Q26718 .
     ?entity wdt:P2 ?type .
  }
  OPTIONAL { ?entity wdt:P172 ?country }
  OPTIONAL { ?entity wdt:P169 ?category }
  OPTIONAL { ?entity wdt:P129 ?idBbma }
  # BIND(IRI(REPLACE(?idBbma, '^(.+)$', ?formatterUrl)) AS ?url).
  # (URI(REPLACE(?p1630,'\\$1',?id)) AS ?url)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}
ORDER BY ?entityLabel

Try it!

Lieux géolocalisés (carte)

#defaultView:Map
SELECT ?entity ?entityLabel ?coord
WHERE
{
  ?entity wdt:P2 wd:Q26719 ;
          p:P276 ?coordinate .
  ?coordinate ps:P276 ?coord .
  ?coordinate psv:P276 ?coordinate_node .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}

Try it!

Personnes physiques (liste complète)

SELECT ?entity ?entityLabel ?sexLabel (year(?dateBirth) as ?YearBirth) (year(?dateDeath) as ?YearDeath) ?idBbma
WHERE
{
  ?entity wdt:P2 wd:Q168 ;
  OPTIONAL { ?entity wdt:P95 ?sex }
  OPTIONAL { ?entity wdt:P57 ?dateBirth }
  OPTIONAL { ?entity wdt:P62 ?dateDeath }
  OPTIONAL { ?entity wdt:P129 ?idBbma }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}
ORDER BY ?entityLabel

Try it!

Organisations (liste complète)

SELECT ?entity ?entityLabel ?placeLabel ?idBbma
WHERE
{
  ?entity wdt:P2 wd:Q167 ;
  OPTIONAL { ?entity wdt:P201 ?place }
  OPTIONAL { ?entity wdt:P129 ?idBbma }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}
ORDER BY ?entityLabel

Try it!

Variante avec GROUP_CONCAT pour gérer les lignes dupliquées (car deux localisations possibles pour la même entité : ex. Q80035 et Q81293)

SELECT ?entity ?entityLabel (GROUP_CONCAT(DISTINCT(?place); separator=", ") AS ?places) (GROUP_CONCAT(DISTINCT(?label); separator=", ") AS ?place_labels) ?idBbma
WHERE
{
  ?entity wdt:P2 wd:Q167 .
  OPTIONAL { ?entity wdt:P201 ?place }
  OPTIONAL { ?entity wdt:P129 ?idBbma }
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "fr".
    ?place rdfs:label ?label .
  }
}
GROUP BY ?entity ?entityLabel ?idBbma
ORDER BY ?entityLabel

Try it!

Manuscrits (liste complète)

SELECT ?entity ?entityLabel ?digitUrl ?manifestUrl ?idBbma
WHERE
{
  ?entity wdt:P2 wd:Q32810 ;
          wdt:P195 ?shelfmark .
  OPTIONAL { ?entity wdt:P197 ?digitUrl }
  OPTIONAL { ?entity wdt:P196 ?manifestUrl }
  #OPTIONAL { ?entity wdt:P194 ?collection }
  OPTIONAL { ?entity wdt:P129 ?idBbma }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}
ORDER BY ?entityLabel

Try it!

Manuscrits (répartition par bibliothèque)

#defaultView:BubbleChart
SELECT ?collectionLabel (COUNT(?entity) AS ?count)
WHERE
{
  { ?entity wdt:P2 wd:Q32810 } UNION { ?entity wdt:P2 wd:Q113619 }
  ?entity wdt:P194 ?collection .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}
GROUP BY ?collectionLabel
ORDER BY ?count

Try it!

Manuscrits numérisés (répartition par bibnum)

#defaultView:BubbleChart
SELECT ?digital_library (COUNT(?entity) AS ?number_of_digitized_objects)
WHERE
{
  { ?entity wdt:P2 wd:Q32810 } UNION { ?entity wdt:P2 wd:Q113619 }
  ?entity p:P197 ?digiStmt .
  ?digiStmt ps:P197 ?digitUrl ;
            pq:P191 ?digiLib .
  
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "fr".
    ?digiLib rdfs:label ?digital_library .
  }
}
GROUP BY ?digital_library

Try it!

Bibliothèques numériques IIIF

SELECT ?entity ?entityLabel (GROUP_CONCAT(DISTINCT(?operatorLabel); separator="; ") AS ?institution) ?website ?licenseLabel ?iiifcollectionUrl ?seeAlsoFormat
WHERE
{
  ?entity wdt:P2 wd:Q32805 ;
          wdt:P193 wd:Q32808 .
  OPTIONAL { ?entity wdt:P200 ?operator }
  OPTIONAL { ?entity wdt:P188 ?website }
  OPTIONAL { ?entity wdt:P187 ?license }
  OPTIONAL { ?entity wdt:P189 ?iiifcollectionUrl }
  OPTIONAL { ?entity wdt:P192 ?seeAlsoFormat }
  #FILTER EXISTS { ?entity wdt:P193 wd:Q32808 }
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "fr" .
    ?operator rdfs:label ?operatorLabel .
    ?entity rdfs:label ?entityLabel .
    ?license rdfs:label ?licenseLabel .
  }
}
GROUP BY ?entity ?entityLabel ?website ?licenseLabel ?iiifcollectionUrl ?seeAlsoFormat
ORDER BY ?institution

Try it!

Requêtes spécifiques

Personnes avec 2 ID bbma

SELECT ?entity ?entityLabel (count(?idBbma) as ?id)
WHERE
{
  ?entity wdt:P2 wd:Q168 ;
          wdt:P129 ?idBbma .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}
GROUP BY ?entity ?entityLabel ?id
HAVING (?id > 1)

Try it!

Organisations avec RCR et disposant de moins de 20 cotes

SELECT ?org ?orgLabel ?placeLabel (count(?item) as ?count)
WHERE
{
  { ?item wdt:P2 wd:Q32810 } UNION { ?item wdt:P2 wd:Q113619 }
  ?item wdt:P194 ?org .
  ?org wdt:P2 wd:Q167 ;
       wdt:P201 ?place ;
       wdt:P202 ?rcr .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}
GROUP BY ?org ?orgLabel ?placeLabel
HAVING (?count < 20)
ORDER BY ?orgLabel

Try it!

Manuscrits détruits

SELECT ?item ?itemLabel
WHERE
{
  ?item p:P2 [
        ps:P2 wd:Q32810 ;
        pq:P281 wd:Q120866
  ] .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}

Try it!

Entités alignées vers le catalogue BnF

SELECT ?entity ?bnfId ?bnfUri ?entityLabel
WHERE {
  ?entity wdt:P109 ?bnfId .
  wd:P109 wdt:P108 ?formatterUrl .
  BIND(IRI(REPLACE(?bnfId, '^(.+)$', ?formatterUrl)) AS ?bnfUri).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}

Try it!

Entités alignées avec la DNB

SELECT ?entity ?gndId ?gndUri ?entityLabel
WHERE {
  ?entity wdt:P111 ?gndId .
  wd:P111 wdt:P108 ?formatterUrl .
  BIND(IRI(REPLACE(?gndId, '^(.+)$', ?formatterUrl)) AS ?gndUri).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}

Try it!


Entités alignées avec Persée ou IdRef

SELECT ?entity ?entityLabel (GROUP_CONCAT(DISTINCT(?typeLabel); separator=", ") AS ?typeLabel) (GROUP_CONCAT(DISTINCT(?uri); separator="###") AS ?uri)
WHERE {
  ?entity ?property ?Id ;
          wdt:P2 ?type .
  ?type rdfs:label ?typeLabel .
  ?prop wikibase:directClaim ?property ;
        rdf:type wikibase:Property ;
        wikibase:propertyType wikibase:ExternalId ;
        wdt:P108 ?formatterUrl .
  FILTER ( CONTAINS(?formatterUrl, "persee") || CONTAINS(?formatterUrl, "idref") ) .
  BIND(IRI(REPLACE(?Id, '^(.+)$', ?formatterUrl)) AS ?uri) .
  FILTER(LANG(?typeLabel) = "fr") .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}
GROUP BY ?entity ?entityLabel

Try it!

Entités personnes issues des bases de l'IRHT

SELECT DISTINCT ?entity 
(GROUP_CONCAT(?idbbma; separator="###") AS ?id_portail_biblissima)
(GROUP_CONCAT(?idbibale; separator="###") AS ?id_bibale)
(GROUP_CONCAT(?idjonas; separator="###") AS ?id_jonas)
(GROUP_CONCAT(?idpinakes; separator="###") AS ?id_pinakes)
(GROUP_CONCAT(?idinitiale; separator="###") AS ?id_initiale)
WHERE
{
    ?entity wdt:P2 wd:Q168 .
    OPTIONAL { ?entity wdt:P129 ?idbbma }
    OPTIONAL { ?entity wdt:P140 ?idjonas }
    OPTIONAL { ?entity wdt:P131 ?idbibale }
    OPTIONAL { ?entity wdt:P145 ?idpinakes }
    OPTIONAL { ?entity wdt:P139 ?idinitiale }
    FILTER(?idjonas != "" || ?idbibale != "" || ?idpinakes != "" || ?idinitiale != "")
}
GROUP BY ?entity

Try it!

Données sur les items numérisés

SELECT ?entity ?idbbma 
(GROUP_CONCAT(DISTINCT ?surrogates; SEPARATOR = "###") AS ?surrogate) 
(GROUP_CONCAT(DISTINCT ?manifests; SEPARATOR = "###") AS ?manifest) 
(GROUP_CONCAT(DISTINCT ?digitTypeLabel; SEPARATOR = "###") AS ?type_label)
(GROUP_CONCAT(DISTINCT ?dsTypeLabel; SEPARATOR = "###") AS ?ds_type_label) 

WHERE {
  VALUES ?filter {
    wd:Q32810
    wd:Q113619
  }
  ?entity wdt:P129 ?uncleaned_idbbma;
    wdt:P2 ?filter;
    wdt:P197 ?surrogates;
  OPTIONAL {
    ?entity p:P197 ?ds_stmt.
    ?ds_stmt pq:P279 ?dsType.
    ?dsType rdfs:label ?_dsTypeLabel.
    FILTER((LANG(?_dsTypeLabel)) = "fr")
  }
  OPTIONAL {
    ?entity wdt:P196 ?manifests ;
    OPTIONAL {
      ?entity p:P196 ?manifest_stmt.
      ?manifest_stmt pq:P279 ?digitType.
      ?digitType rdfs:label ?_digitTypeLabel.
      FILTER((LANG(?_digitTypeLabel)) = "fr")
    }
  }

  BIND(REPLACE(?uncleaned_idbbma, '^[im]data', '') AS ?idbbma)
  BIND(COALESCE(?_dsTypeLabel, "<no label>") AS ?dsTypeLabel)
  BIND(COALESCE(?_digitTypeLabel, "<no label>") AS ?digitTypeLabel).

}
GROUP BY ?entity ?idbbma
ORDER BY ?entity
LIMIT 20000

Try it!