SPARQL Examples

This page contains a collection of basic SPARQL examples which can be applied to data in Nomisma.org. It is not intended to be an introduction to SPARQL as a whole, but a good tutorial can be found on the Jena site.

Querying within Nomisma.org Concepts

List of all Roman Emperors

PREFIX rdf:		<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcterms:		<http://purl.org/dc/terms/>
PREFIX foaf:		<http://xmlns.com/foaf/0.1/>
PREFIX nm:		<http://nomisma.org/id/>
PREFIX nmo:		<http://nomisma.org/ontology#>
PREFIX org:		<http://www.w3.org/ns/org#>
PREFIX skos:		<http://www.w3.org/2004/02/skos/core#>

SELECT ?uri ?label WHERE {
?uri a foaf:Person ;
  skos:prefLabel ?label ;         
  org:hasMembership ?membership .
?membership org:role nm:roman_emperor .
FILTER(langMatches(lang(?label), "EN"))
} 

Querying Coins linked to Nomisma.org Concepts

All weights of Augustan denarii

PREFIX rdf:		<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcterms:		<http://purl.org/dc/terms/>
PREFIX nm:		<http://nomisma.org/id/>
PREFIX nmo:		<http://nomisma.org/ontology#>

SELECT ?type ?weight WHERE {
?type nmo:hasAuthority nm:augustus ;
  nmo:hasDenomination nm:denarius ;
  dcterms:source nm:ric.
?coin nmo:hasTypeSeriesItem ?type .
?coin nmo:hasWeight ?weight
}

Average weight of Augustan denarii

PREFIX rdf:		<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcterms:		<http://purl.org/dc/terms/>
PREFIX nm:		<http://nomisma.org/id/>
PREFIX nmo:		<http://nomisma.org/ontology#>
PREFIX xsd:		<http://www.w3.org/2001/XMLSchema#>

SELECT (AVG(xsd:decimal(?weight)) AS ?average) WHERE {
?type nmo:hasAuthority nm:augustus ;
  nmo:hasDenomination nm:denarius ;
  dcterms:source nm:ric.
?coin nmo:hasTypeSeriesItem ?type .
?coin nmo:hasWeight ?weight
}

Coins of RIC Augustus 1A and 1B

This will also gather measurements data, source collecton (with English label), and thumbnail/references images.

PREFIX rdf:		<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcterms:		<http://purl.org/dc/terms/>
PREFIX nm:		<http://nomisma.org/id/>
PREFIX nmo:		<http://nomisma.org/ontology#>
PREFIX foaf:		<http://xmlns.com/foaf/0.1/>
PREFIX skos:	<http://www.w3.org/2004/02/skos/core#>

SELECT ?object ?type ?diameter ?weight ?axis ?type ?collection ?obvThumb ?revThumb ?obvRef ?revRef ?comThumb ?comRef WHERE {
	{?object nmo:hasTypeSeriesItem <http://numismatics.org/ocre/id/ric.1(2).aug.1A> }
	UNION { ?object nmo:hasTypeSeriesItem <http://numismatics.org/ocre/id/ric.1(2).aug.1B> }
	?object rdf:type nmo:NumismaticObject .
	OPTIONAL { ?object nmo:hasWeight ?weight }
	OPTIONAL { ?object nmo:hasDiameter ?diameter }
	OPTIONAL { ?object nmo:hasAxis ?axis }
	OPTIONAL { ?object dcterms:identifier ?identifier }
	OPTIONAL { ?object nmo:hasCollection ?colUri .
		?colUri skos:prefLabel ?collection FILTER(langMatches(lang(?collection), "EN"))}
	OPTIONAL { ?object foaf:thumbnail ?comThumb }
	OPTIONAL { ?object foaf:depiction ?comRef }
	OPTIONAL { ?object nmo:hasObverse ?obverse .
		?obverse foaf:thumbnail ?obvThumb }
	OPTIONAL { ?object nmo:hasObverse ?obverse .
		?obverse foaf:depiction ?obvRef }
	OPTIONAL { ?object nmo:hasReverse ?reverse .
		?reverse foaf:thumbnail ?revThumb }
	OPTIONAL { ?object nmo:hasReverse ?reverse .
		?reverse foaf:depiction ?revRef }
}

Average Diameter of RIC Augustus 1A

PREFIX rdf:		<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcterms:		<http://purl.org/dc/terms/>
PREFIX nm:		<http://nomisma.org/id/>
PREFIX nmo:		<http://nomisma.org/ontology#>
PREFIX xsd:		<http://www.w3.org/2001/XMLSchema#>

SELECT (AVG(xsd:decimal(?diameter)) AS ?average) WHERE {
?object nmo:hasTypeSeriesItem <http://numismatics.org/ocre/id/ric.1(2).aug.1A> ;
  nmo:hasDiameter ?diameter
}

All findspots for RIC Augustus 1A

This will query all coins with individual finds and all coins linked to hoards or hoards with contents containing Augustus 1A. This query makes use of the current Nomisma findspot data model (implemented April 2020). See documentation for further details.

PREFIX rdf:      <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcmitype:	<http://purl.org/dc/dcmitype/>
PREFIX dcterms:  <http://purl.org/dc/terms/>
PREFIX nm:       <http://nomisma.org/id/>
PREFIX nmo:	<http://nomisma.org/ontology#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf:	<http://xmlns.com/foaf/0.1/>
PREFIX skos:      <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs:	<http://www.w3.org/2000/01/rdf-schema#>
PREFIX crm:	<http://www.cidoc-crm.org/cidoc-crm/>

SELECT ?object ?title ?findspot ?placeName ?hoard ?hoardLabel ?lat ?long ?type ?burial WHERE {
{ ?object a nmo:NumismaticObject ;
 nmo:hasTypeSeriesItem <http://numismatics.org/ocre/id/ric.1(2).aug.1A>}
UNION { ?broader skos:broader+ <http://numismatics.org/ocre/id/ric.1(2).aug.1A> .
?object nmo:hasTypeSeriesItem ?broader ;
  a nmo:NumismaticObject }
UNION { ?contents a dcmitype:Collection ; 
  nmo:hasTypeSeriesItem <http://numismatics.org/ocre/id/ric.1(2).aug.1A> .
?object dcterms:tableOfContents ?contents }
?object dcterms:title|skos:prefLabel ?title .			
{ ?object nmo:hasFindspot/crm:P7_took_place_at/crm:P89_falls_within ?findspot }
UNION { ?object dcterms:isPartOf ?hoard .
        ?hoard a nmo:Hoard ;
        skos:prefLabel ?hoardLabel ;
        nmo:hasFindspot/crm:P7_took_place_at/crm:P89_falls_within ?findspot .
   		OPTIONAL {?hoard nmo:hasClosingDate ?burial . FILTER isLiteral(?burial)}
        OPTIONAL {?hoard nmo:hasClosingDate ?closing .
                 ?closing nmo:hasEndDate ?burial}}
?findspot rdfs:label ?placeName ;
          geo:location ?loc .
?loc geo:lat ?lat ;
     geo:long ?long .
OPTIONAL { ?object rdf:type ?type FILTER (?type != skos:Concept)} 
OPTIONAL { ?object nmo:hasClosingDate ?burial . FILTER isLiteral(?burial) }}

All coins found in Northamptonshire, ordered chronologically by issue

This query uses property paths to look for children of (crm:P89_falls_within) of the Wikidata URI for Northamptonshire, England (http://www.wikidata.org/entity/Q23115).

PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX dcmitype: <http://purl.org/dc/dcmitype/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX nm: <http://nomisma.org/id/>
PREFIX nmo: <http://nomisma.org/ontology#>
PREFIX org: <http://www.w3.org/ns/org#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?coin ?type ?date ?place WHERE {
?coin nmo:hasFindspot/crm:P7_took_place_at/crm:P89_falls_within ?place ;
      nmo:hasTypeSeriesItem ?type ;
      a nmo:NumismaticObject .
?place crm:P89_falls_within+ <http://www.wikidata.org/entity/Q23115> .
?type nmo:hasEndDate ?date .
} ORDER BY ASC(?date) LIMIT 100