Skip to main content

Sample Queries

This page contains links to pre-written SPARQL queries, organized according to the information they return.

Using the Sample Queries

Prefixes

This query starts with listing the prefixes of all the ontologies to be used (cwrc, rdf, rdfs, data, skos, and oa).

PREFIX cwrc: <http://sparql.cwrc.ca/ontologies/cwrc#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX data: <http://cwrc.ca/cwrcdata/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX oa: <http://www.w3.org/ns/oa#>

Return Variables

The variables that are being returned are the object that we're searching for, in this case the name of Fiennes's father, and the snippet from which this information is derived from.

SELECT ?name ?snippet

GRAPH

This query also shows the graph that is being searched (biography) and specifies the context (cwrc:FamilyContext), which is listed after rdf:type.

The name of the person whose information is being searched is in bold. In this case, the person is Celia Fiennes. If you would like to search for another person, a name can be chosen from http://orlando.cambridge.org

GRAPH <http://sparql.cwrc.ca/data/orlando/biography> {
?context ?pred ?obj;
cwrc:contextFocus ?person;
oa:hasTarget ?target;
rdf:type cwrc:FamilyContext.
?person rdfs:label "Fiennes, Celia".
?obj rdfs:label ?name.
}

Predicates

Outside of the graph section, the query searches for the snippet of text that the data is stored as. The last line is what we're searching for; it allows us to specify the relationship between the subject and the object.

The other data in bold is the predicate which connects the subject and object. There are a variety of predicates in the CWRC Ontology, any of which may be used to construct a query.

?target oa:hasSelector/oa:refinedBy/oa:exact ?snippet.
?pred cwrc:subjectCentricPredicate cwrc:hasFather.

The Query

All together, the query is written as:

PREFIX cwrc: <http://sparql.cwrc.ca/ontologies/cwrc#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX data: <http://cwrc.ca/cwrcdata/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX oa: <http://www.w3.org/ns/oa#>

SELECT distinct ?name ?snippet WHERE {
GRAPH <http://sparql.cwrc.ca/data/orlando> {
?context ?pred ?obj;
cwrc:contextFocus ?person;
oa:hasTarget ?target;
rdf:type cwrc:FamilyContext.
?person rdfs:label "Fiennes, Celia".
?obj rdfs:label ?name.
}

?target oa:hasSelector/oa:refinedBy/oa:exact ?snippet.
?pred cwrc:subjectCentricPredicate cwrc:hasFather.
}

Family & Friends & Intimate Relationships

Who was the father of an author?

Who was the mother of an author?

Who was the brother of an author?

Notice the queries above only differ slightly. They each specify a different person and have a different predicate following the cwrc:subjectCentricPredicate, but are otherwise identical.

The predicate following 'cwrc:' can be replaced with many others which are listed on the CWRC website. Some examples include:

Who were the family members of a particular author?

Who were the siblings of a particular author?

Location

How many authors lived in London?

You will notice something different about the query above. Most of the other queries had the following included under GRAPH:

?context ?pred ?obj

This query had specified the object rather than leaving it as a variable. The object was taken from the GeoNames ontology. If you would like to specify a different location, search for a place on https://www.geonames.org/v3/ and replace the number in the URI to reflect your desired location.

?context ?pred <http://sws.geonames.org/2643743/>

Where did a particular author travel to?

What places has an author visited?

Did a particular author immigrate anywhere?

Occupation

How many people held each job?

What was the most popular job?

How many authors were also teachers?

Notice how the query above returned a small number of people who were also teachers. There were certainly more than 45 teachers, so why was the result so small? This has to do with the specifics of your query. In the data teachers are not only grouped by hasOccupation but also by hasPaidOccupation, hasVolunteerOccupation, etc.

Using hasPaidOccupation and hasVolunteerOccupation alone would look like the following:

So you can see that the hasOccupation predicate can be replaced by others to modify queries. However, all of these predicates are also subproperties of the predicate Occupation. You can search for these subproperties by using the rdfs:subPropertyOf* constraint to return results for every author who was a teacher. The query below is an example of this:

Education

Where did a particular author go to school?

What subjects were studied by a particular author?

What were the schools attended by a particular author?

Birth

When was a particular author born?

Where was a particular author born?

Death

When did a particular author die?

What was the cause of death of a particular author?

Where did a particular author die?

Where was a particular author buried?

Politics

What was a particular person’s political affiliation?

What political organizations was a particular author associated with?

Health

What context can be given about a particular author's health?

Violence

What are a particular author's connections to violence?

Wealth

Relates Economically To

Leisure and society

What hobbies did a person enjoy?