Search code examples
sparqldbpedia

Can SPARQL handle blank results for specific cells?


I am writing a SPARQL query and cant figure out how to allow blank results for specific columns.

My current request is:

select * where {
?game a dbpedia-owl:Game ;
dbpprop:name ?name ; 
dbpedia-owl:publisher ?publisher . }

Some Games have an owl for publisher while others do not. The above request filters out the Games that do not have a publisher. I want to be able to get the games with a publisher and the games without a publisher in the same CSV.

I tried to write if isset statements for the publisher owl but cannot seem to get the correct blanks.

Instead of filtering out the games without a publisher, I want the result with a blank for the publisher cell.

Any suggestions?


Solution

  • Whenever you are looking for something that might and might not be present, you can put that part of the statement in an optional part of SPARQL query. Thus:

    select * where {
        ?game a dbpedia-owl:Game ;
        dbpprop:name ?name . 
    optional{
         ?game dbpedia-owl:publisher ?publisher . 
    }
    }   
    

    The count before the optional is 112 and after is 143.