Hi Andy

I think this query will give me the videos that have both ?s0 and ?s99. but
I'm also interested at the records having either of the two category (or
both)
(union is used as an or operation)

{
 ?v <http://onescreen.com/video_freebase#/music/track>  ?s99 .
 ?v <http://onescreen.com/video_freebase#/music>  ?s0
}

is there a function to detect undefined value and return zero in sparql?


Thank you.

Yuhan



On Mon, Oct 1, 2012 at 1:38 PM, Andy Seaborne <[email protected]> wrote:

> On 01/10/12 20:46, Yuhan Zhang wrote:
>
>> Hi all,
>>
>> I'm trying to perform sparql query to find <video_id, category, score>
>> triples with an union
>> aggregating all the matching scores over a video_id.
>> However, the score is returned as blank. Here's how I construct the query
>>
>> select ?v (sum(?s99*2+?s0) AS ?ss) where {
>>   { ?v 
>> <http://onescreen.com/video_**freebase#/music/track<http://onescreen.com/video_freebase#/music/track>>
>>  ?s99 }
>> union
>>   { ?v 
>> <http://onescreen.com/video_**freebase#/music<http://onescreen.com/video_freebase#/music>>
>>  ?s0 }
>> } group by ?v order by desc (?ss) limit 100
>>
>
> Do you really mean that?
>
> To do sum(?s99*2+?s0) you want ?s99 and ?s0 in the same row for each ?v
> which is:
>
> {
>  ?v 
> <http://onescreen.com/video_**freebase#/music/track<http://onescreen.com/video_freebase#/music/track>>
>  ?s99
>  ?v 
> <http://onescreen.com/video_**freebase#/music<http://onescreen.com/video_freebase#/music>>
>  ?s0
> }
>
> The score is returned as blank because eval of the SUM is an error (the
> expression (?s99*2+?s0) always has one variable or the other unbound so the
> evaluation has an undef i.e error.
>
>
>
>> ------------------------------**---------------
>> | v                                    | ss |
>> ==============================**===============
>> | <http://onescreen.com/video#**1732760<http://onescreen.com/video#1732760>>
>> |    |
>> | <http://onescreen.com/video#**1732780<http://onescreen.com/video#1732780>>
>> |    |
>> | <http://onescreen.com/video#**1732800<http://onescreen.com/video#1732800>>
>> |    |
>>
>>
>> but selecting with the specific video_id, the record does have both, but
>> on
>> different columns:
>>
>> select ?s0 ?s99 where {
>>   { 
>> <http://onescreen.com/video#**1732760<http://onescreen.com/video#1732760>>
>> <
>> http://onescreen.com/video_**freebase#/music<http://onescreen.com/video_freebase#/music>>
>>  ?s0 }
>> union
>> { <http://onescreen.com/video#**1732760<http://onescreen.com/video#1732760>>
>> <
>> http://onescreen.com/video_**freebase#/music/track<http://onescreen.com/video_freebase#/music/track>>
>>  ?s99 }
>> }
>>
>> ------------------------------**------------------------------**
>> ------------------------------**-------------------
>> | s0                                                  | s99
>>                                       |
>> ==============================**==============================**
>> ==============================**===================
>> | 
>> "0.01532"^^<http://www.w3.org/**2001/XMLSchema#float<http://www.w3.org/2001/XMLSchema#float>>
>> |
>>                                       |
>> |                                                     |
>> "0.00739"^^<http://www.w3.org/**2001/XMLSchema#float<http://www.w3.org/2001/XMLSchema#float>>
>> |
>> ------------------------------**------------------------------**
>> ------------------------------**-------------------
>>
>> looks like it is caused by blank variable, either sum() or + with a blank
>> causes the result to be blank.
>> I noticed that I couldn't map the two columns into the same variable name,
>> as I'd like to apply different weights ?s99 and ?s0
>> to achieve sum(?s99*2+?s0)
>>
>> so, with which function could I make a variable to be 0 when it is blank?
>> what is the correct way to construct this query?
>>
>>
>> Thank you.
>>
>> Yuhan
>>
>>
>

Reply via email to