Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 754
Ryanf Avatar asked Dec 24 '22 18:12

Ryanf


1 Answers

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.

like image 130
Artemis Avatar answered Jan 05 '23 22:01

Artemis