Baywatch
Baywatch

Reputation: 423

Sparql property filter

How does one figure out what the ontological property relationships are in order to know how to craft a sparql query properly?

For example, if I want the Major League Baseball teams that have won a world series.

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbpedia: <http://dbpedia.org/resource/> 
PREFIX owl: <http://dbpedia.org/ontology/> 
PREFIX db: <http://dbpedia.org/>
PREFIX dbpprop: <http://dbpedia.org/property/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#broader/>
PREFIX category: <http://dbpedia.org/resource/Category:>
PREFIX purl: <http://purl.org/dc/terms/>
PREFIX ps: <http://purl.org/dc/terms/subject/>


select  distinct *  
where { 
  ?team rdf:type owl:BaseballTeam .
  { ?team rdf:type yago:MajorLeagueBaseballTeams . }
  #{ ?team dbprop:champion dbpedia:Major_League_Baseball }
}

If I uncomment the last line in the query, I get no results. Looking at : http://dbpedia.org/page/Boston_Red_Sox

I see:

is dbpprop:champion of  dbpedia:American_League

I am unsure of how I would structure the syntax to filter only teams that have won a world series (Champion) and I am really confused on how to discover what the actual query prefixes ought to be.

Upvotes: 3

Views: 1154

Answers (1)

magnudae
magnudae

Reputation: 1272

   is dbpprop:champion of  dbpedia:American_League 

This sentence means that American_leage has a property champion which declares teams that have won the league.

Is-Of just tells you which properties that have the resource, you are looking at, as range. If you click your way through to the domain you can see that it has a property pointing to the initial resource. Just take a look at the dbpedia resource for American_league.

So, you have to structure your query like this to get the result you want. (You almost had it, it is just the other way around)

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbpedia: <http://dbpedia.org/resource/>  
PREFIX owl: <http://dbpedia.org/ontology/> 
PREFIX db: <http://dbpedia.org/>
PREFIX dbpprop: <http://dbpedia.org/property/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#broader/>
PREFIX category: <http://dbpedia.org/resource/Category:>
PREFIX purl: <http://purl.org/dc/terms/>
PREFIX ps: <http://purl.org/dc/terms/subject/>


select distinct *  
where { 
  ?team rdf:type owl:BaseballTeam .
  ?team rdf:type yago:MajorLeagueBaseballTeams .
  // Like the one below
  dbpedia:Major_League_Baseball dbprop:champion ?team
}

Upvotes: 6

Related Questions