Monday, August 16, 2010

All Simpson's Blackboard gags - Filtered and Ordered

FILTER AND ORDER THE RESULTS

There are extra rows showing because a season sometimes has more than 1 label assigned to it. We now want to FILTER the rows to just those containing The Simpsons episodes in the season title.

THE SPARQL QUERY - FILTERED AND ORDERED

SELECT distinct ?season_title,?episode,?chalkboard_gag
WHERE 
{
 ?episode
   <http://www.w3.org/2004/02/skos/core#subject>
     ?season
 .
 ?episode
   <http://dbpedia.org/property/blackboard>
     ?chalkboard_gag
 .
     ?season
       <http://www.w3.org/2000/01/rdf-schema#label>
         ?season_title
     .
    FILTER(regex(?season_title,"The Simpsons episodes","i")).
}
ORDER BY ?season_title
Show results

FILTER WITH REGULAR EXPRESSIONS

13)FILTER(regex(?season_title,"The Simpsons episodes","i")).

  • Line 13) FILTER lets us restrict the rows in our output to only those that make our expression true. These are similar to Oracle's where clauses. In this example we used the regex function in a very simple way to search ?season_title for the string, The Simpsons episodes, ignoring any variations in uppercase or lower case letters.

ORDER THE RESULTS

15) ORDER BY ?season_title

Line 15) We would like to order by season title, so we see the gags over time. This command orders the title as a string, at least keeping the seasons together, but putting season 1 and season 11 before season 2.
We could work harder to isolate the number at the end of the season and sort on its
numeric representation, but let's not.
Some episodes have an airdate, the first time the episode was shown, but the data item is too sparse to order all our results. Let's move on.

No comments:

Post a Comment