SPARQL Queries
Queries
Filter on a specific class and start of signature
SELECT distinct ?id ?identifier WHERE {
?id rdf:type/(rdfs:subClassOf)* ubbont:Charter ;
dct:identifier ?identifier .
FILTER(strStarts (?identifier, "ubb-diplom"))
}
ORDER BY ASC(?id)
LIMIT 1000
Run the query (opens in a new tab)
Count all properties used on a class
SELECT ?predicate (COUNT(*) AS ?frequency)
WHERE {
?subject a event:Event ;
?predicate ?object .
}
GROUP BY ?predicate
ORDER BY DESC(?frequency)
Run the query (opens in a new tab)
Get all classes, all used properties and a sample value
SELECT DISTINCT ?type ?property (SAMPLE(?o) AS ?sample)
WHERE {
?s a ?type .
?s ?property ?o .
}
GROUP BY ?type ?property
ORDER BY ?type ?property
Run the query (opens in a new tab)
Get same as above but as json objects
CONSTRUCT {
?type ?property ?sample .
}
WHERE {
SELECT DISTINCT ?type ?property (SAMPLE(?o) AS ?sample)
WHERE {
#VALUES ?type {foaf:Person}
?s a ?type .
?s ?property ?o .
}
GROUP BY ?type ?property
ORDER BY ?type ?property
}
Run the query (opens in a new tab)
Find all props with english language
SELECT ?s ?p ?localizedString WHERE {
?s ?p ?localizedString .
filter(lang(?localizedString) = 'en')
}
Run the query (opens in a new tab)
Find all descriptions in no and en, plus internalNote for the Jørgen Grinde collection
PREFIX ubbont: <http://data.ub.uib.no/ontology/>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT ?uri ?id ?desc_no ?desc_en ?alt_text WHERE {
values ?col {'ubb-jg-'}
?s dct:identifier ?id ;
dct:description ?desc .
OPTIONAL{ ?s ubbont:internalNote ?alt } .
filter(STRSTARTS (?id, ?col))
bind(if(contains(?alt, "ALT"), ?alt, ?_ ) as ?alt_text)
bind(if(langMatches(lang(?desc),"en"),?desc,?_) as ?desc_en)
bind(if(langMatches(lang(?desc),""),?desc,?_) as ?desc_no)
bind(uri(replace(str(?s), "data.ub", "marcus")) as ?uri)
}
Run the query (opens in a new tab)
Count the content in all collections
SELECT ?s (count(?part) as ?total) WHERE {
values ?col {<http://purl.org/ontology/bibo/Collection>}
?s a ?col ;
dct:hasPart ?part .
?part dct:identifier ?partId .
}
group by ?s
order by desc(?total)
kRun the query (opens in a new tab)
Get the top level collections
SELECT DISTINCT ?uri ?label ?description ?logo WHERE {
GRAPH <urn:x-arq:UnionGraph> {
?uri a bibo:Collection .
OPTIONAL { ?uri rdfs:label ?label . }
OPTIONAL { ?uri dct:title ?label . }
OPTIONAL { ?uri dct:description ?description . }
OPTIONAL { ?uri foaf:logo ?logo . }
FILTER NOT EXISTS { ?uri dct:isPartOf ?partOf . }
}
}
ORDER BY ?label
Run the query (opens in a new tab)
Create a search IIIF collection for ... collections
CONSTRUCT
{
?uri iiif_prezi:summary ?count .
?item rdf:type ?itemType .
?item rdfs:label ?itemLabel .
?item dct:identifier ?itemId .
}
WHERE
{
{ SELECT ?uri (COUNT(?part) AS ?count)
WHERE
{ VALUES ?id { "ubb-kk-" }
?uri dct:identifier ?id ;
dct:hasPart ?part .
?part rdf:type/(rdfs:subClassOf)* bibo:Document .
}
GROUP BY ?uri
}
UNION
{ SELECT DISTINCT ?item ?itemId ?itemType ?itemLabel
WHERE
{ SELECT DISTINCT ?item ?itemId ?itemType
(GROUP_CONCAT( concat('"',?itemLabels,'"@',lang(?itemLabels)); separator="|" ) as ?itemLabel)
WHERE
{ VALUES ?id { "ubb-kk-" }
?uri dct:identifier ?id .
?item dct:isPartOf ?uri ;
rdf:type ?itemType .
?itemType (rdfs:subClassOf)* bibo:Document .
?item dct:identifier ?itemId ;
dct:title ?itemLabels .
}
GROUP BY ?item ?itemType ?itemId ?itemLabel
ORDER BY ?itemId
}
OFFSET 0
LIMIT 10
}
}
ORDER BY ?itemId
Run the query (opens in a new tab)
Get the objects with the most props
SELECT ?id (COUNT(distinct ?p) AS ?props)
WHERE {
?id rdf:type/(rdfs:subClassOf)* bibo:Document ;
?p ?o .
}
GROUP BY ?id
ORDER BY DESC(?props)
Run the query (opens in a new tab)
Get all concept schemes
CONSTRUCT {
?id a skos:ConceptScheme .
?id ?p ?o .
?o ?p2 ?o2 .
}
WHERE {
?id a skos:ConceptScheme .
?id ?p ?o .
?o ?p2 ?o2 .
FILTER(?p2 != ubbont:isSubjectOf && ?p2 != ubbont:cataloguedBy && ?p2 != skos:narrower)
}
Get a csv of all concepts
SELECT
?c
(GROUP_CONCAT(DISTINCT ?prefLabel;separator=", ") AS ?label)
(GROUP_CONCAT(DISTINCT ?oType;separator=", ") AS ?type)
?id
WHERE {
?c skos:inScheme ?cs .
?c a ?class .
?c skos:prefLabel ?prefLabel .
OPTIONAL {
?c dct:identifier ?id .
}
?class rdfs:label ?oClass .
BIND(str(?oClass) AS ?oType)
}
GROUP BY ?c ?id
Get all authorities
SELECT DISTINCT
?id
?url
(GROUP_CONCAT(DISTINCT ?classLabel;separator="||") AS ?type)
?identifier
(GROUP_CONCAT(DISTINCT ?prefLabelNo0;separator="||") AS ?labelNo)
(GROUP_CONCAT(DISTINCT ?prefLabelEn0;separator="||") AS ?labelEn)
(GROUP_CONCAT(DISTINCT ?firstName0;separator="||") AS ?firstName)
(GROUP_CONCAT(DISTINCT ?familyName0;separator="||") AS ?familyName)
(GROUP_CONCAT(DISTINCT ?birth;separator="||") AS ?birthDate)
(GROUP_CONCAT(DISTINCT ?death;separator="||") AS ?deathDate)
(GROUP_CONCAT(DISTINCT ?profession0;separator="||") AS ?profession)
(GROUP_CONCAT(DISTINCT ?schemaName0;separator="||") AS ?schemaName)
(GROUP_CONCAT(DISTINCT ?match0;separator="||") AS ?match)
?existsBroader
?existsNarrower
(GROUP_CONCAT(DISTINCT ?available0;separator="||") AS ?available)
(GROUP_CONCAT(DISTINCT ?modified0;separator="||") AS ?modified)
?source
WHERE {
VALUES ?class {
<http://purl.org/NET/c4dm/event.owl#Event>
<http://data.ub.uib.no/ontology/Cataloguer>
<http://dbpedia.org/ontology/Company>
<http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing>
<http://data.ub.uib.no/ontology/Ship>
<http://xmlns.com/foaf/0.1/Person>
<http://schema.org/Country>
<http://lexvo.org/ontology#Language>
<http://data.ub.uib.no/ontology/PhotographicTechnique>
<http://xmlns.com/foaf/0.1/Organization>
<http://data.ub.uib.no/ontology/Vessel>
<http://vocab.lenka.no/geo-deling#Grunneiendom>
<http://data.ub.uib.no/ontology/Family>
<http://data.ub.uib.no/ontology/Location>
<http://www.w3.org/2003/01/geo/wgs84_pos#Point>
<http://data.ub.uib.no/ontology/Technique>
<http://vocab.lenka.no/geo-deling#Kommune>
<http://data.ub.uib.no/ontology/Building>
<http://vocab.lenka.no/geo-deling#Fylke>
<http://data.ub.uib.no/ontology/Publisher>
<http://www.w3.org/2004/02/skos/core#Concept>
<http://data.ub.uib.no/ontology/Parish>
ubbont:Monument
}
{
?id a ?class .
OPTIONAL {
?id skos:prefLabel|foaf:name|rdfs:label ?prefLabelNo0 .
FILTER((LANG(?prefLabelNo0)) = "" || (LANG(?prefLabelNo0)) = "no" || (LANG(?prefLabelNo0)) = "nn" || (LANG(?prefLabelNo0)) = "nb")
}
OPTIONAL {
?id skos:prefLabel|foaf:name|rdfs:label ?prefLabelEn0 .
FILTER((LANG(?prefLabelEn0)) = "en")
}
OPTIONAL { ?id foaf:familyName ?familyName0 . }
OPTIONAL { ?id foaf:firstName ?firstName0 . }
OPTIONAL { ?id dct:identifier ?identifier . }
OPTIONAL {
?id skos:inScheme ?inScheme .
?inScheme skos:prefLabel ?csClass .
BIND(str(?csClass) AS ?schemaName0)
}
OPTIONAL {?id dbo:birthDate ?birth }
OPTIONAL {?id dbo:deathDate ?death }
OPTIONAL {?id dbo:profession ?profession0 }
OPTIONAL { ?id foaf:page/ubbont:hasURI ?match0 }
OPTIONAL { ?id dct:available ?available0 . }
OPTIONAL { ?id dct:modified ?modified0 . }
OPTIONAL { ?class rdfs:label ?classLabel . }
#FILTER(STRLEN(?classLabel) != 0)
FILTER(langMatches(lang(?classLabel), "en"))
BIND(EXISTS { ?id skos:broader ?broader } as ?existsBroader)
BIND(EXISTS { ?id skos:narrower ?narrower } as ?existsNarrower)
BIND("marcus" as ?source)
BIND(replace(str(?id), "data.ub", "marcus") as ?url0)
BIND(iri(?url0) as ?url)
} UNION {
SERVICE <https://sparql.ub.uib.no/skeivtarkiv/query> {
?id a ?class .
OPTIONAL {
?id skos:prefLabel|foaf:name|rdfs:label ?prefLabelNo0 .
FILTER((LANG(?prefLabelNo0)) = "" || (LANG(?prefLabelNo0)) = "no" || (LANG(?prefLabelNo0)) = "nn" || (LANG(?prefLabelNo0)) = "nb")
}
OPTIONAL {
?id skos:prefLabel|foaf:name|rdfs:label ?prefLabelEn0 .
FILTER((LANG(?prefLabelEn0)) = "en")
}
OPTIONAL { ?id foaf:familyName ?familyName0 . }
OPTIONAL { ?id foaf:firstName ?firstName0 . }
OPTIONAL { ?id dct:identifier ?identifier . }
OPTIONAL {
?id skos:inScheme ?inScheme .
?inScheme skos:prefLabel ?csClass .
BIND(str(?csClass) AS ?schemaName0)
}
OPTIONAL {?id dbo:birthDate ?birth }
OPTIONAL {?id dbo:deathDate ?death }
OPTIONAL {?id dbo:profession ?profession0 }
OPTIONAL { ?id foaf:page/ubbont:hasURI|ubbont:kulturnavId ?match0 }
OPTIONAL { ?id dct:available ?available0 . }
OPTIONAL { ?id dct:modified ?modified0 . }
OPTIONAL { ?class rdfs:label ?classLabel . }
#FILTER(STRLEN(?classLabel) != 0)
FILTER(langMatches(lang(?classLabel), "en"))
BIND(EXISTS { ?id skos:broader ?broader } as ?existsBroader)
BIND(EXISTS { ?id skos:narrower ?narrower } as ?existsNarrower)
BIND("skeivtarkiv" as ?source)
BIND(replace(str(?id), "data.ub.uib", "katalog.skeivtarkiv") as ?url0)
BIND(iri(?url0) as ?url)
}}
}
GROUP BY ?id ?url ?identifier ?type ?schemaName ?match ?existsBroader ?existsNarrower ?available ?modified ?source
Find all datatypes per property
SELECT ?p (COUNT(?o) AS ?dTypeCount) (MAX(?datatype) AS ?dtype)
{
?s ?p ?o.
BIND (datatype(?o) AS ?datatype)
FILTER (isLiteral(?o))
}
GROUP BY datatype(?o) ?p
Instances with multiple bibo:pages
select ?homepage ?id (GROUP_CONCAT(?o;SEPARATOR=", ") as ?pages) where {
?s bibo:pages ?o ;
dct:identifier ?id .
BIND(iri(REPLACE(str(?s), "http://data.ub.uib.no","https://marcus.uib.no","i")) as ?homepage)
}
GROUP BY ?homepage ?id
HAVING(count(?o) > 1)
Prefixes
PREFIX muna: <http://muna.xyz/model/0.1/>
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX ecrm: <http://erlangen-crm.org/current/>
PREFIX ubbont: <http://data.ub.uib.no/ontology/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX schema: <http://schema.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX bibo: <http://purl.org/ontology/bibo/>
PREFIX mo: <http://purl.org/ontology/mo/>
PREFIX geo-deling: <http://vocab.lenka.no/geo-deling#>
PREFIX wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dcmitype: <http://purl.org/dc/dcmitype/>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geonames: <http://www.geonames.org/ontology#>
PREFIX exif: <http://www.w3.org/2003/12/exif/ns#>
PREFIX edm: <http://www.europeana.eu/schemas/edm/>
PREFIX org: <http://www.w3.org/ns/org#>
PREFIX bio: <http://purl.org/vocab/bio/0.1/>
PREFIX frbr: <http://vocab.org/frbr/core#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX ore: <http://www.openarchives.org/ore/terms/>
PREFIX nie: <http://www.semanticdesktop.org/ontologies/nie/#>
PREFIX locah: <http://data.archiveshub.ac.uk/def/>
PREFIX lexvo: <http://lexvo.org/ontology#>
PREFIX cc: <http://creativecommons.org/ns#>
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX ecrm: <http://erlangen-crm.org/current/>
PREFIX ubbont: <http://data.ub.uib.no/ontology/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX schema: <http://schema.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX bibo: <http://purl.org/ontology/bibo/>
PREFIX mo: <http://purl.org/ontology/mo/>
PREFIX geo-deling: <http://vocab.lenka.no/geo-deling#>
PREFIX wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dcmitype: <http://purl.org/dc/dcmitype/>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geonames: <http://www.geonames.org/ontology#>
PREFIX exif: <http://www.w3.org/2003/12/exif/ns#>
PREFIX edm: <http://www.europeana.eu/schemas/edm/>
PREFIX org: <http://www.w3.org/ns/org#>
PREFIX bio: <http://purl.org/vocab/bio/0.1/>
PREFIX frbr: <http://vocab.org/frbr/core#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX ore: <http://www.openarchives.org/ore/terms/>
PREFIX nie: <http://www.semanticdesktop.org/ontologies/nie/#>
PREFIX locah: <http://data.archiveshub.ac.uk/def/>
PREFIX lexvo: <http://lexvo.org/ontology#>
PREFIX cc: <http://creativecommons.org/ns#>
PREFIX iiif_prezi: <http://iiif.io/api/presentation/3#>