A small followup. Since I need to get both the excerpt and the score I
figure I need to do something like the following to make sure to only
get each ?r once:

select ?r
(bif:concat(bif:search_excerpt(bif:vector('nepomuk'),
  (select ?v2 where
    { { ?r ?v1 ?v2 .
           ?v2 bif:contains 'nepomuk' . }
         UNION { ?r ?v1 ?v3 . ?v3 ?v4 ?v2 .
           ?v4
<http://www.w3.org/2000/01/rdf-schema#subPropertyOf>
<http://www.w3.org/2000/01/rdf-schema#label> .
           ?v2 bif:contains 'nepomuk' . } }
  )
))) as
?_n_f_t_m_ex_

(select max(?v5) as ?score where
    { { ?r ?v1 ?v2 .
           ?v2 bif:contains 'nepomuk'  OPTION (score ?v5) . }
         UNION { ?r ?v1 ?v3 . ?v3 ?v4 ?v2 .
           ?v4
<http://www.w3.org/2000/01/rdf-schema#subPropertyOf>
<http://www.w3.org/2000/01/rdf-schema#label> .
           ?v2 bif:contains 'nepomuk' OPTION (score ?v5) . } }
) as ?score

where {
    { select distinct ?r
      where { {
            { ?r ?v1 ?v2 .
              ?v2 bif:contains 'nepomuk' . }
            UNION { ?r ?v1 ?v3 . ?v3 ?v4 ?v2 .
              ?v4
<http://www.w3.org/2000/01/rdf-schema#subPropertyOf>
<http://www.w3.org/2000/01/rdf-schema#label> .
              ?v2 bif:contains 'nepomuk' . } } .
          ?r a ?v6 .
          ?v6
<http://www.semanticdesktop.org/ontologies/2007/08/15/nao#userVisible>
'true'^^<sopranofakes:/booleanHackUntilVirtuosoProblemIsResolved> . }
LIMIT 10 }
}

Meaning I do a separate select for the excerpt, the score, and the
actual resource.

Is this correct?

Cheers,
Sebastian

On 09/13/2010 11:05 AM, Sebastian Trüg wrote:
> Hello Ivan,
> 
> thanks a lot for looking into my query.
> Now let me see if I understand correctly:
> 
> On 09/13/2010 09:42 AM, Ivan Mikhailov wrote:
>> There are two problems with this query.
>> First, ?v2 and ?v5 are barely connected. It looks like the query is
>> written to select the excerpt of the "best" resource about a keyword and
>> the score of it, but max(?v5) seems to be redundant: the score of ?v2 is
>> always the same, no matter how many branches of UNION will calculate it.
> 
> I used max() to filter out duplicate results in case we have two
> statements matching with different literals (in one part of the UNION).
> Then the query would return both since the score is different.
> 
>> Second issue, the visible due to an error message, is that
>> the ?_n_f_t_m_ex_ may get a value of arbitrary size, as far as I can
>> understand, so obtaining the "distinct" from a temporary table of all
>> data is a real problem. A possible workaround it to exclude
>> the ?_n_f_t_m_ex_ from distinct, something like
>>
>> select ?r
>> (bif:concat(bif:search_excerpt(bif:vector('trueg.'), ?v2))) as
>> ?_n_f_t_m_ex_
>> where {
>>     { select distinct ?r
>>       where { {
>>             { ?r ?v1 ?v2 .
>>               ?v2 bif:contains "'trueg.'" }
>>             UNION { ?r ?v1 ?v3 . ?v3 ?v4 ?v2 .
>>               ?v4
>> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf>
>> <http://www.w3.org/2000/01/rdf-schema#label> .
>>               ?v2 bif:contains "'trueg.'" } } .
>>           ?r a ?v6 .
>>           ?v6 
>> <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#userVisible>
>> 'true'^^<sopranofakes:/booleanHackUntilVirtuosoProblemIsResolved> . } LIMIT 
>> 10 }
>>     { { ?r ?v1 ?v2 .
>>            ?v2 bif:contains "'trueg.'" OPTION (score ?_n_f_t_m_s_) . }
>>          UNION { ?r ?v1 ?v3 . ?v3 ?v4 ?v2 .
>>            ?v4
>> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf>
>> <http://www.w3.org/2000/01/rdf-schema#label> .
>>            ?v2 bif:contains "'trueg.'" OPTION (score ?_n_f_t_m_s_) . } }
>> }
>>
>> for one or many excerpts per ?r or
> 
> So you use the second block to make sure ?v2 is not selected distinct?
> 
> (As a side-remark: this query is generated from a query API where
> ?_n_f_t_m_s_ can be a sum of several weighted scores.)
> 
>> select ?r
>> (bif:concat(bif:search_excerpt(bif:vector('trueg.'),
>>   (select ?v2 where
>>     { { ?r ?v1 ?v2 .
>>            ?v2 bif:contains "'trueg.'" OPTION (score ?_n_f_t_m_s_) . }
>>          UNION { ?r ?v1 ?v3 . ?v3 ?v4 ?v2 .
>>            ?v4
>> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf>
>> <http://www.w3.org/2000/01/rdf-schema#label> .
>>            ?v2 bif:contains "'trueg.'" OPTION (score ?_n_f_t_m_s_) . } }
>>   )
>> ))) as
>> ?_n_f_t_m_ex_
>> where {
>>     { select distinct ?r
>>       where { {
>>             { ?r ?v1 ?v2 .
>>               ?v2 bif:contains "'trueg.'" }
>>             UNION { ?r ?v1 ?v3 . ?v3 ?v4 ?v2 .
>>               ?v4
>> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf>
>> <http://www.w3.org/2000/01/rdf-schema#label> .
>>               ?v2 bif:contains "'trueg.'" } } .
>>           ?r a ?v6 .
>>           ?v6 
>> <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#userVisible>
>> 'true'^^<sopranofakes:/booleanHackUntilVirtuosoProblemIsResolved> . } LIMIT 
>> 10 }
>> }
>>
>> for some single excerpt per ?r
> 
> Here the select in the bif:search_excerpt block could return several
> values for ?v2, right? What would bif:search_excerpt do with them?
> Concat them?
> 
> This looks very interesting but I fear it will be very very hard to get
> that into my query generator which is already very complicated as it is. :P
> 
> Cheers,
> Sebastian
> 
> ------------------------------------------------------------------------------
> Start uncovering the many advantages of virtual appliances
> and start using them to simplify application deployment and
> accelerate your shift to cloud computing
> http://p.sf.net/sfu/novell-sfdev2dev
> _______________________________________________
> Virtuoso-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/virtuoso-users
> 

Reply via email to