1

I made a SPARQL query using the official DBpedia endpoint.

I'll take it for example for the main Question:

SELECT  ?museum ?EnglishAbstract   ?RussianAbstract 
WHERE { 

?museum dbpedia-owl:abstract ?EnglishAbstract. 
?museum a dbpedia-owl:Museum.
filter(lang(?EnglishAbstract)='en')

optional{
    ?museum dbpedia-owl:abstract ?RussianAbstract.
    ?museum a dbpedia-owl:Museum.
filter(lang(?RussianAbstract)='ru')
}}
GROUP BY ?museum

With this query (that works good), I find for every row (museum) a bunch of Abstract in 2 languages: English and Russian. The Russian abstracts are present only if available because I use "OPTIONAL". Obviously I get a lot of empty attributes.

I would replace the blank attribute with the English abstract (always present).

Reading the W3C SPARQL page, I found that there is a particular testing value that is true when a variable is set: Bound

I would like to write something like this:

If Bound (?RussianAbstract), "?RussianAbstract", "?EnglishAbstract"

--> if RussianAbstract is present, hold it; else, put the EnglishAbstract instead of it.

Does anyone know how can I make it work?

TallTed
  • 9,069
  • 2
  • 22
  • 37
  • You may find [Generating values for empty attributes](http://stackoverflow.com/q/19723721/1281433) useful, as well as [SPARQL : how to make a class label shown as the column name of the class?](http://stackoverflow.com/q/26114572/1281433), which actually addresses using one value if another isn't available. – Joshua Taylor Jul 10 '15 at 15:13

1 Answers1

4

One way to do this is to use COALESCE:

SELECT  ?museum (COALESCE(?RussianAbstract, ?EnglishAbstract) as ?Abstract)
svick
  • 236,525
  • 50
  • 385
  • 514