Database Reference
In-Depth Information
{
?house mm_address:hasHouseNumber ?number.
?house mm_address:hasStreet “Troglodyte Street”.
}
This graph pattern is the set of triples concerning houses (or actually any resource)
that have a house number and are in Troglodyte Street. That is, if a variable appears
in multiple triples within a graph pattern, it must be bound to the same value in all
the triple patterns.
8.3.1 SparQl Select
Now, we move on to some example SPARQL queries. First, to select a number of
triples from the RDF graph, we use the following query structure:
1. base < http://data.mereamaps.gov.me/administrativeRegions.rdf >
2. prefix admin: < http://data.mereamaps.gov.me/administrativeRegions/ >
3. select *
4. from < http://data.mereamaps.gov.me/administrativeRegions.rdf >
5. where
6. {
7. ?region a admin:Region;
8. :contains ?y.
9. ?y a admin:City;
10. admin:hasPlaceName 'Medina'.
11. }
Line 1 specifies the base Uniform Resource Identifier (URI) to which all URIs
further in the query will be relative, and line 2 provides a shortcut to represent the
namespace of Merea Maps' administrative regions using just the prefix admin .
Line 3 is known as the “result clause” and specifies what we want to return; in this
case, we want to select everything (denoted by *) from the RDF graph stated in line 4,
according to the conditions in lines 7-10. Lines 7 and 8 are asking for instances
of the class admin:Region that contain something (stored in variable  ?y ). Note
that the SPARQL keyword a is an abbreviation for rdf:type , stating that we are
looking for answers that are of the type admin:Region (line 7). Then, lines  9
and 10 further specify that the ?y we are looking for is an instance of the class
admin:City , which has the name “Medina.” So, the whole query will return all the
information in the Administrative Regions RDF graph about the region that contains
the city of Medina.
As with other data query languages such as SQL, the keyword DISTINCT can
be added after the SELECT to only return unique results, avoiding duplicates.
Solution modifiers can be added after the conditional where clause. For example,
ORDER BY sorts results in ascending or descending order of one of the variables,
LIMIT limits the number of results returned, and OFFSET n skips the first n results.
The F I LT ER keyword allows you to exclude results whose values do not meet the
specified constraints (e.g., to drop small areas from a query where the interest was
Search WWH ::




Custom Search