Dear all,

I have to write a query where I
1) want to select some entities with a subquery S, let's call the result set R
2) take the crossproduct R x R,   and
3) apply some filter on R x R
Below you find a working query like that, acting on some gene data.
The crucial point for me is: In order to obtain R x R, I use the subquery S 
twice.
This is something I don't like: Not-so-smart SPARQL processors would run the
subquery twice, though theoretically, it would be sufficient to run S only once,
if there was an easy way to "construct" from the result set R the cross-product 
R X R.
So my question is: Is there a better way to write that query without running S 
twice?
Is there a convenient way to let SPARQL generate R x R, when there is a SPARQL 
query
which generates R?

Best
Frithjof



select  ?gene1  (concat(">= ",xsd:string(?cdetected2)," detected") as ?o1)
where
{
    {
        #
        # subquery S, first instance
        #
        select (?gene as ?gene1)  (count(?ta1) as ?cdetected1)
        where
            {
            ?gene a :Gene .
            ?ta1 a :Textual_Annotation .
            ?ta1 :has_involved_gene ?gene .
            ?ta1 :has_strength :level_detected .
            }
        GROUP BY ?gene
        ORDER BY DESC(?cdetected1)
        LIMIT 5
        }

        {
        #
        # subquery S, second instance
        #
        select (?gene as ?gene2)  (count(?ta1) as ?cdetected2)
        where
            {
            ?gene a :Gene .
            ?ta1 a :Textual_Annotation .
            ?ta1 :has_involved_gene ?gene .
            ?ta1 :has_strength :level_detected .
            }
        GROUP BY ?gene
        ORDER BY DESC(?cdetected2)
        LIMIT 5
        }
        #
        # filter condition on R X R
        #
        FILTER (?cdetected1>=?cdetected2)
}


Dr. Frithjof Dau
Senior Researcher, Business Intelligence Practice   I   SAP Research Dresden
SAP AG   I   Chemnitzer Str. 48   I   01187 Dresden   I   Germany

T +49 351 4811-6152   I   F +49 6227 78-51425   I   mailto: 
[email protected]<mailto:[email protected]>
www.sap.com<http://www.sap.com>


Pflichtangaben/Mandatory Disclosure Statements:
http://www.sap.com/company/legal/impressum.epx
Diese E-Mail kann Betriebs- oder Geschäftsgeheimnisse oder sonstige 
vertrauliche Informationen enthalten. Sollten Sie diese E-Mail irrtümlich 
erhalten haben, ist Ihnen eine Kenntnisnahme des Inhalts, eine Vervielfältigung 
oder Weitergabe der E-Mail ausdrücklich untersagt. Bitte benachrichtigen Sie 
uns und vernichten Sie die empfangene E-Mail. Vielen Dank.

This e-mail may contain trade secrets or privileged, undisclosed, or otherwise 
confidential information. If you have received this e-mail in error, you are 
hereby notified that any review, copying, or distribution of it is strictly 
prohibited. Please inform us immediately and destroy the original transmittal. 
Thank you for your cooperation.



Reply via email to