Thursday, July 29, 2010

The Simpson's Blackboard gags for Season 12

Let's expand your first query and get all the blackboard gags from the 12th Simpson season.

STARTING FROM ONE EPISODE

  • We'll start with the first sparql query's dbpedia page, the dbpedia version of The Worst Episode.
  • Here are the dbpedia page's sections identifying the episode, the blackboard gag for this episode, and lastly, the season this episode is part of. We will use this information for our query.



Note: click any picture to enlarge it.

THE QUERY DIAGRAM

THE SPARQL QUERY - SEASON 12 EPISODES WITH BLACKBOARD GAGS

SELECT distinct ?episode,?chalkboard_gag
WHERE 
{
 ?episode
   <http://www.w3.org/2004/02/skos/core#subject>
     <http://dbpedia.org/resource/Category:The_Simpsons_episodes%2C_season_12>
 .
 ?episode
   <http://dbpedia.org/property/blackboard>
     ?chalkboard_gag
 .
}
Show results.

SPECIFY YOUR OUTPUT VARIABLES

1) SELECT distinct ?episode,?chalkboard_gag
  • The select clause specifies what fields you want in your output.
  • The distinct keyword removes duplicate values of ?episode - ?chalkboard_gag combinations.
  • I specified the same two variables, ?episode and ?chalkboard_gag.

START OF YOUR SELECTION CRITERIA

2) WHERE { . . . } Enough said.

IDENTIFY THE EPISODES IN SEASON 12







 
4) ?episode  the subject
5)  <http://www.w3.org/2004/02/skos/core#subject>  the predicate
6)   <http://dbpedia.org/resource/Category:The_Simpsons_episodes%2C_season_12>  the object
7) .
 
  • Line 4) The subject we are talking about.
  • Line 5) At first sight, skos:subject didn't mean much to me, but when I saw its value refered to the Simpson's season 12, I figured it had to describe the season that this episode belonged to. I copied the link's value into my sparql query.
  • Line 6) For the object, I picked up the value of the long link to the right of skos:subject.
  • Line 7) The period marks the end of the first selection clause.
  • Recapping, lines 4-7 ask the SPARQL engine to search all off dbpedia to find the page(s) that I will call ?episode that have a skos:subject value of http://dbpedia.org/resource/Category:The_Simpsons_episodes%2C_season_12.

GET THE BLACKBOARD GAG


8) ?episode  the subject 
9)  <http://dbpedia.org/property/blackboard>  the predicate 
10)   ?chalkboard_gag  the object 
11) .

  • Line 8) By using the same variable, ?episode as subject in lines 4 and 8, I am telling SPARQL that I want to see the blackboard gag for the episode defined above.
  • Line 9) I copied the link,dbprop:blackboard from the dbpedia page as mentioned before.
  • Line 10) I specified the object as a variable called ?chalkboard_gag, meaning pick it up from the page (or really from the RDF data underlying the page).

    This will now show different blackboard gags for different episodes.
  • Line 11) End of the 2nd search clause.
  • Line 12)The closing bracket ends your selection criteria.

LETS CHECK OUR RESULTS

So that's your second query. Let's compare our results. versus The object link to the Simpson episodes season 12.

We have a little problem. Our results show 7 gags and season 12 had 21 episodes. What gives?
Not all the episodes had blackboard gags, so lets ask for each episode in season 12 and then optionally show the blackboard gag if it exists.

SPARQL QUERY WITH THE BLACKBOARD GAG OPTIONAL

SELECT distinct ?episode,?chalkboard_gag
WHERE 
{
 ?episode
   <http://www.w3.org/2004/02/skos/core#subject>
<http://dbpedia.org/resource/Category:The_Simpsons_episodes%2C_season_12>
 .
 OPTIONAL
 { 
 ?episode
   <http://dbpedia.org/property/blackboard>
     ?chalkboard_gag
 .
 } # end of optional blackboard gag
} # end of where clause

Show results
Now there are 21 episodes and still the same 7 blackboard gags. That clears up the mystery.

No comments:

Post a Comment