Exercise

| Exercise: Which actresses were nominated for more than 3 Academy awards, and how many nominations did each have?

show solution

One way to approach this question is to retrieve items of women who have “actor” as occupation (or a subclass thereof, such as “film actor”), and count the number of Academy Awards they have been nominated for. Note, however, that this includes all Academy Awards.

For example, actress Emma Thompson was also nominated for the Academy Award for Best Writing, Adapted Screenplay.

Another approach is to look at the winners of the “Academy Award for Best Actress” and “Academy Award for Best Supporting Actress”:

Excluding results

FILTER – excluding results

So far we saw modifiers that operated at the SELECT clause or after the WHERE clause. Another useful modifier is FILTER, which can appear within the WHERE clause.
We will demonstrate filtering in two ways: the FILTER function which selects only the items that match the filter condition (i.e., excludes items that do not) and FILTER NOT EXISTS which is a clause that excludes results that match certain patterns.

FILTER function

The FILTER function excludes items based on the expression that appears within the function’s parenthesis: only those results for which the expression in the parenthesis is true are used.

Let’s say we wanted to edit the query about the 10 highest-grossing films that are part of a series, so that the query will return only those films that were released before the year 2000.

On line 8, we added a match pattern to collect the value of P577 property (publication date) with the ?date variable. On the next line we used FILTER to only include items whose publication date is before 01-01-2000.

Note that we put the criterion date (2000-01-01) in quotes and add “^^xsd:dateTime” after to signify that the format of this value is a date.

YEAR function

Another way of writing this query is using the function YEAR. This built-in function returns the year part of a date (or a dateTime value):

FILTER NOT EXISTS

Let’s say we wanted to edit the query about actresses nominated for more than three Academy awards, so that the query will return only those actresses that never received an Academy award.

We add the FILTER NOT EXISTS clause, in which we specify the patterns that should NOT be matched, namely that the actress has a P166 property (award received) that has a value that is an instance (P31) of Academy Awards (Q19020):

In other words, the query excludes items that have statements that match the pattern given within the FILTER NOT EXISTS clause.

Exercise: FILTER

| Exercise: Write a query that shows sovereign states whose head of government was born in 1980 or later

Hint: select sovereign states (Q3624078) that have a head of government (P6) whose date of birth (P569) has the year 1980 or later, or who have their birthday 01-01-1980 or later.

show solution

Another way of writing this query is using the exact date format:

Skip to content