Quelle anzeigen

The following example queries can be viewed below:

{toc}

_You can test these SPARQL queries at the webform at [http://lobid.org/test/]_

h2. Use *curl* with these SPARQL-Queries
Example:
{code} curl --data-urlencode 'query=
prefix bibo: <http://purl.org/ontology/bibo/>
SELECT * WHERE {
?s bibo:issn "09437096"
} LIMIT 10
' http://lobid.org/sparql/
{code}
Note: through "--data-urlencode" we need not to substitute i.e. a '+' with '%2B'.

h2. Get all organisations, their URIs and their geographical coordinates

Additionally, the distance itself is requested.

{code}
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 .
}
}
{code}

h2. Get the organisations located within a maximum distance to a specfic place
{code}
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 ) .
}
}
{code}
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.

h2. 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].

{code}
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
{code}

h2. 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".

{code}
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
{code}

h2. Get an item of a specific manifestation which is held by a library at a a specific region

{code}
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
{code}

h2. Full text search of names of organisations
{code}
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") .
}
}
{code}

h2. 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|http://lobid.org/vocab/libtype.rdf] for information on the underlying classification).

{code}
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
}
{code}

h2. Get postal data and the telephonenumber (not fax) from a specific library
{code}
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/
{code}

h2. Get the holders of a manifestation

{code}
PREFIX frbr: <http://purl.org/vocab/frbr/core#>

SELECT ?owner WHERE {
<http://lobid.org/resource/HT001243330> frbr:exemplar ?item .
?item frbr:owner ?owner .
}
{code}

h2. show me all graphs
{code}
curl -d 'query=

SELECT DISTINCT ?g
WHERE {
GRAPH ?g {
?s ?p ?o .
}
}
' http://lobid.org/sparql/

{code}

h2. 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|http://lobid.org/resource/HT002189125]). The keyword "SERVICE" enables the federated search, specified by the SPARQL-Endpoints of these "services"._
{code}
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/
{code}