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

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> }
OPTIONAL { ?object nmo:hasWeight ?weight }
OPTIONAL { ?object nmo:hasDiameter ?diameter }
OPTIONAL { ?object nmo:hasAxis ?axis }
?object rdf:type ?type .
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 dcterms:		<http://purl.org/dc/terms/>
PREFIX nm:		<http://nomisma.org/id/>
PREFIX nmo:		<http://nomisma.org/ontology#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>

SELECT ?object ?title ?findspot ?lat ?long ?type ?burial WHERE {
{ ?object nmo:hasTypeSeriesItem <typeUri> }
UNION { ?contents nmo:hasTypeSeriesItem <http://numismatics.org/ocre/id/ric.1(2).aug.1A> .
?object dcterms:tableOfContents ?contents }
?object dcterms:title ?title .			
?object nmo:hasFindspot ?findspot .
{?findspot geo:lat ?lat .
?findspot geo:long ?long }
UNION {
 ?findspot nmo:hasFindspot ?loc .
 ?loc geo:lat ?lat.
 ?loc geo:long ?long			 
 OPTIONAL { ?findspot nmo:hasClosingDate ?burial }
}
OPTIONAL { ?object rdf:type ?type }
OPTIONAL { ?object nmo:hasClosingDate ?burial }}