The following example queries can be viewed below:
You can test these SPARQL queries at the webform at http://lobid.org/test/
Use curl with these SPARQL-Queries
Example:
curl --data-urlencode 'query= prefix bibo: <http://purl.org/ontology/bibo/> SELECT * WHERE { ?s bibo:issn "09437096" } LIMIT 10 ' http://lobid.org/sparql/
Note: through "--data-urlencode" we need not to substitute i.e. a '+' with '%2B'.
Get all organisations, their URIs and their geographical coordinates
Additionally, the distance itself is requested.
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?uri ?nam ?lat ?lon WHERE { GRAPH <http://lobid.org/organisation/> { ?uri geo:location ?loc . ?loc geo:lat ?lat . ?loc geo:long ?lon . ?uri foaf:name ?nam . } }
Get the organisations located within a maximum distance to a specfic place
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?uri ?nam ( ( (50.9341-xsd:float(?lat))*(50.9341-xsd:float(?lat)) + (6.93549-xsd:float(?lon))*(6.93549-xsd:float(?lon))*(0.831939969105-(0.00853595*xsd:float(?lat))) ) AS ?d2brgrad) WHERE { GRAPH <http://lobid.org/organisation/> { ?uri geo:location ?loc . ?loc geo:lat ?lat . ?loc geo:long ?lon . ?uri foaf:name ?nam . FILTER( (50.9341-xsd:float(?lat))*(50.9341-xsd:float(?lat)) + (6.93549-xsd:float(?lon))*(6.93549-xsd:float(?lon))*(0.831939969105-(0.00853595*xsd:float(?lat))) < 0.808779738472242 ) . } }
This query gets all organisations located within a circle of D = 100 km radius around a place at φ = 50.9341º in latitude and λ = 6.93549º in longitude ( a place in Cologne, Germany ).
The other numeric values in the query must be calculated from the geo-coordinates φ and λ of the observer (the "specific place"), the maximum desired distance D and a reference latitude φ 0 as follows:
φ 0 in this example was chosen to be φ 0 = 51.0º
cos(φ 0)·sin(φ 0)·π/180 = 0.00853595
cos(φ 0)·(cos(φ 0) - sin(φ 0)·π/180·(φ -2·φ0)) = 0.831939969105
(D / brgrad) 2 = 0.808779738472242
where brgrad is the mean distance between two latitude circles, brgrad = 111.1949 km.
The variable d2brgrad in the select clause is the square of the distance of the organisation to the observer, d, divided by the square of brgrad.
The calculation in this query is an approximate one. It is only good for locations which are near to the observer point where "near" means that their distance to the observer point is small as compared to the radius of the earth, d < D << R = 6371 km . The reference latitude φ 0 must be chosen to be near the observer point where "near" has the same meaning as above. Within Germany, the approximation is good to better than 0.1% in distance.
Near the poles of the earth, the approximation is not good. For the distance in longitude must be actually also small compared to cos(φ 0)·R , not only to R. At the equator, cos(φ 0) = 1 and it decreases towards the poles. At φ 0 = 60º and φ 0 = -60º, we have cos(φ 0) = ½. Beyond φ 0 = 85º and φ 0 = -85º the approximation should not be used.
The returned valued d2brgrad can be transformed as follows to the distance between the organisation and the observer :
d = SQRT( d2brgrad ) * brgrad .
SPARQL cannot compute the square root, so this last step must be done by some external program.
Get the organisations located at a specific region which are holders of a specific resource
Search for libraries which are not more than 5 km away from a point in Cologne (50.9341º in latitude and 6.93549º in longitude) which have an item of the bibliographic resource http://lobid.org/resource/HT000543651.
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix v: <http://www.w3.org/2006/vcard/ns#> prefix foaf: <http://xmlns.com/foaf/0.1/> prefix hcterms: <http://purl.org/uF/hCard/terms/> prefix dcterms: <http://purl.org/dc/terms/> prefix xsd: <http://www.w3.org/2001/XMLSchema#> prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> prefix frbr: <http://purl.org/vocab/frbr/core#> SELECT ?lib ( ( (50.9341-xsd:float(?lat))*(50.9341-xsd:float(?lat)) + (6.93549-xsd:float(?lon))*(6.93549-xsd:float(?lon))*(0.831939969105-(0.00853595*xsd:float(?lat))) ) AS ?d2brgrad) WHERE { <http://lobid.org/resource/HT000543651> frbr:exemplar ?ex . ?ex frbr:owner ?lib . ?lib geo:location ?loc . ?loc geo:lat ?lat . ?loc geo:long ?lon . ?uri foaf:name ?nam . FILTER( (50.9341-xsd:float(?lat))*(50.9341-xsd:float(?lat)) + (6.93549-xsd:float(?lon))*(6.93549-xsd:float(?lon))*(0.831939969105-(0.00853595*xsd:float(?lat))) < 0.0020219493461806057363177376485694 ) . } LIMIT 10
Get the organisations located at a specific region which are holders of a resource with a specific ISBN
Search for libraries which are not more than 5 km away from a point in Cologne (50.9341º in latitude and 6.93549º in longitude) which have an item of a bibliographic resource with the ISBN "978-3-631-58937-3".
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix v: <http://www.w3.org/2006/vcard/ns#> prefix foaf: <http://xmlns.com/foaf/0.1/> prefix hcterms: <http://purl.org/uF/hCard/terms/> prefix dcterms: <http://purl.org/dc/terms/> prefix xsd: <http://www.w3.org/2001/XMLSchema#> prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> prefix frbr: <http://purl.org/vocab/frbr/core#> prefix bibo: <http://purl.org/ontology/bibo/> SELECT ?lib ( ( (50.9341-xsd:float(?lat))*(50.9341-xsd:float(?lat)) + (6.93549-xsd:float(?lon))*(6.93549-xsd:float(?lon))*(0.831939969105-(0.00853595*xsd:float(?lat))) ) AS ?d2brgrad) WHERE { ?man bibo:isbn13 "9783631589373" . ?man frbr:exemplar ?ex . ?ex frbr:owner ?lib . ?lib geo:location ?loc . GRAPH <http://lobid.org/organisation/> { ?loc geo:lat ?lat . ?loc geo:long ?lon . ?uri foaf:name ?nam . } FILTER( (50.9341-xsd:float(?lat))*(50.9341-xsd:float(?lat)) + (6.93549-xsd:float(?lon))*(6.93549-xsd:float(?lon))*(0.831939969105-(0.00853595*xsd:float(?lat))) < 0.0020219493461806057363177376485694 ) . } LIMIT 10
Get an item of a specific manifestation which is held by a library at a a specific region
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix v: <http://www.w3.org/2006/vcard/ns#> prefix foaf: <http://xmlns.com/foaf/0.1/> prefix hcterms: <http://purl.org/uF/hCard/terms/> prefix dcterms: <http://purl.org/dc/terms/> prefix xsd: <http://www.w3.org/2001/XMLSchema#> prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> prefix frbr: <http://purl.org/vocab/frbr/core#> prefix bibo: <http://purl.org/ontology/bibo/> prefix isbd: <http://iflastandards.info/ns/isbd/elements/> SELECT ?ex ( ( (51.4741995-xsd:float(?lat))*(51.4741995-xsd:float(?lat)) + (7.234396-xsd:float(?lon))*(7.234396-xsd:float(?lon))*(0.831939969105-(0.00853595*xsd:float(?lat))) ) AS ?d2brgrad) WHERE { ?man isbd:P1004 "System und Performanz" . ?man frbr:exemplar ?ex . ?ex frbr:owner ?lib . ?lib geo:location ?loc . GRAPH <http://lobid.org/organisation/> { ?loc geo:lat ?lat . ?loc geo:long ?lon . ?uri foaf:name ?nam . } FILTER( (51.4741995-xsd:float(?lat))*(51.4741995-xsd:float(?lat)) + (7.234396-xsd:float(?lon))*(7.234396-xsd:float(?lon))*(0.831939969105-(0.00853595*xsd:float(?lat))) < 0.0020219493461806057363177376485694 ) .} LIMIT 10
Full text search of names of organisations
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix foaf: <http://xmlns.com/foaf/0.1/> prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> prefix org: <http://www.w3.org/ns/org#> SELECT ?org ?name WHERE { graph <http://lobid.org/organisation/> { ?org foaf:name ?name . FILTER regex(?name, "zentrum", "i") . } }
Search for organizations by organization type
In the example we search for all organization which a classified as central university libraries (see the libtype vocab for information on the underlying classification).
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX libtype: <http://lobid.org/vocab/libtype#> PREFIX org: <http://www.w3.org/ns/org#> SELECT ?x WHERE { ?x org:classification libtype:n60 }
Get postal data and the telephonenumber (not fax) from a specific library
curl --data-urlencode "query= PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX hcterms: <http://purl.org/uF/hCard/terms/> PREFIX v: <http://www.w3.org/2006/vcard/ns#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?uri ?nam ?postal ?street ?city ?email ?tel ?url WHERE { GRAPH <http://lobid.org/organisation/> { ?uri foaf:name ?nam . ?uri hcterms:hasCard ?card . ?card v:adr ?adr . ?adr v:postal-code ?postal . ?card v:email ?email . ?card v:url ?url . ?card v:tel ?tele . ?tele rdf:type v:Voice . ?tele rdf:value ?tel. ?adr v:street-address ?street . ?adr v:locality ?city . FILTER( ?uri = <http://lobid.org/organisation/DE-38> ) . } } " http://lobid.org/sparql/
Get the holders of a manifestation
PREFIX frbr: <http://purl.org/vocab/frbr/core#> SELECT ?owner WHERE { <http://lobid.org/resource/HT001243330> frbr:exemplar ?item . ?item frbr:owner ?owner . }
show me all graphs
curl -d 'query= SELECT DISTINCT ?g WHERE { GRAPH ?g { ?s ?p ?o . } } ' http://lobid.org/sparql/
federated search query
Querying the lobid.org database using an ISBN. The lobid.org resource has a link to dbpedia.org, and thus the dbpedia.org is queried using this link (the example is this lobid-resource). The keyword "SERVICE" enables the federated search, specified by the SPARQL-Endpoints of these "services".
curl -H "Accept: text/turtle" --data-urlencode 'query= DESCRIBE ?dbpedia WHERE { ?s <http://purl.org/ontology/bibo/isbn13> "9780940450004" ; <http://rdvocab.info/RDARelationshipsWEMI/workManifested> ?dbpedia . SERVICE <http://de.dbpedia.org/sparql> { ?dbpedia ?p ?o. } } ' http://lobid.org/sparql/