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"))
} 

Spatial Queries

The Apache Fuseki triplestore and SPARQL endpoint has been extended to support spatial queries by interacting with a Solr search index. For further documentation for spatial queries in SPARQL, see http://jena.apache.org/documentation/query/spatial-query.html

All hoards found within 50 km of Goranu, Romania

The format of spatial:nearby is (lat long distance 'unit')

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

SELECT * WHERE {
   ?loc spatial:nearby (45.10523 24.38431 50 'km') .
   ?hoard nmo:hasFindspot ?loc ;
          a nmo:Hoard ;
          dcterms:title ?label .
          OPTIONAL {?hoard nmo:hasClosingDate ?date}
  FILTER langMatches (lang(?label), 'en')
}

All mints found within 50 km of Athens

The format of spatial:nearby is (lat long distance 'unit').

PREFIX rdf:	<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcterms:	<http://purl.org/dc/terms/>
PREFIX geo:	<http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX nm:	<http://nomisma.org/id/>
PREFIX nmo:	<http://nomisma.org/ontology#>
PREFIX skos:	<http://www.w3.org/2004/02/skos/core#>
PREFIX spatial: <http://jena.apache.org/spatial#>
PREFIX xsd:	<http://www.w3.org/2001/XMLSchema#>

SELECT * WHERE {
   ?loc spatial:nearby (37.974722 23.7225 50 'km') ;
        geo:lat ?lat ;
        geo:long ?long .
   ?mint geo:location ?loc ;
         skos:prefLabel ?label ;
         a nmo:Mint
  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

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#>

SELECT ?object ?title ?findspot ?hoard ?placeName ?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 ?title .			
{ ?object nmo:hasFindspot ?findspot }
  UNION { ?object dcterms:isPartOf ?hoard .
        ?hoard a nmo:Hoard ;
        skos:prefLabel ?hoardLabel ;
        nmo:hasFindspot ?findspot .
   		OPTIONAL {?hoard nmo:hasClosingDate ?burial . FILTER isLiteral(?burial)}
        OPTIONAL {?hoard nmo:hasClosingDate ?closing .
                 ?closing nmo:hasEndDate ?burial}}
?findspot geo:lat ?lat .
?findspot geo:long ?long .
OPTIONAL {?findspot foaf:name ?placeName}
OPTIONAL {?findspot rdfs:label ?placeName}
OPTIONAL {?findspot skos:prefLabel ?placeName FILTER(langMatches(lang(?placeName), "en"))}
OPTIONAL { ?object rdf:type ?type } 
OPTIONAL { ?object nmo:hasClosingDate ?burial . FILTER isLiteral(?burial) }}