Okay thanks. This stuff is complicated...

On 18/03/2022 16.20, Andy Seaborne wrote:
The OPTIONAL uses ?graph.

So it isn't simple a matter of "optional adds rows" After the optional happens, there is a new condition on ?graph.

The inside of GRAPH ?graph { inner } is executed then joined to ensure ?graph is the right value.

On 18/03/2022 12:52, Mikael Pesonen wrote:

Hi Martynas,

So query below returns some extra columns (but fewer rows) with OPTIONAL. With OPTIONAL only one item is returned from graph http://www.yso.fi/onto/mesh/ <http://www.yso.fi/onto/mesh/> . Without OPTIONAL two items are returned, one from each graph.

Data is available on bottom of these pages:
http://finto.fi/mesh/en/
http://finto.fi/tero/en/

2 files, 600K and 800K lines.

Not a minimal example. Not a data sample.

And its not the data being used here which is a dataset with named graphs (different names to their URLs), not Turtle files.



PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX text: <http://jena.apache.org/text#>
SELECT *
WHERE
{
     VALUES ?graph {<http://www.yso.fi/onto/tero/> <http://www.yso.fi/onto/mesh/>}
     GRAPH ?graph
     {
         {
             SELECT DISTINCT ?concept ?prefLabelm ?altLabelm WHERE
             {
                 {
                     (?concept ?score1 ?prefLabelm) text:query (skos:prefLabel "aamiainen*") .
                     FILTER ( (lang(?prefLabelm) = "fi" ))
                 }
             }
         }
         OPTIONAL { ?concept skos:broader* [ skos:topConceptOf ?graph; skos:prefLabel ?topConceptLabel ] }
     }
}

On 18/03/2022 12.58, Martynas Jusevičius wrote:
Can you provide a full query string and a data sample that illustrate
the problem? Then it's easy to see what's going on, for example on
http://sparql.org/sparql.html.

On Fri, Mar 18, 2022 at 11:52 AM Mikael Pesonen
<mikael.peso...@lingsoft.fi>  wrote:

Is this a problem with query, not with Jena?

On 15/03/2022 9.30, Lorenz Buehmann wrote:
Hi,

I'm probably misunderstanding the query, but what is the purpose of
the OPTIONAL here?

?graph is bound because of VALUES clause, ?concept is bound because of
the graph pattern before the OPTIONAL as well.

So ?graph and ?concept are bound on the left hand side of the
left-join aka OPTIONAL

Here is the algebra:

(join
       (table (vars ?graph)
         (row [?graph<http://www.yso.fi/onto/tero/>])
         (row [?graph<http://www.yso.fi/onto/mesh/>])
       )
       (assign ((?graph ?*g0))
         (leftjoin
           (distinct
             (project (?concept ?prefLabelm ?altLabelm)
               (filter (= (lang ?prefLabelm) "fi")
                 (quadpattern
                   (quad ?*g0 ??0 rdf:first ?concept)
                   (quad ?*g0 ??0 rdf:rest ??1)
                   (quad ?*g0 ??1 rdf:first ?score1)
                   (quad ?*g0 ??1 rdf:rest ??2)
                   (quad ?*g0 ??2 rdf:first ?prefLabelm)
                   (quad ?*g0 ??2 rdf:rest rdf:nil)
                   (quad ?*g0 ??0 text:query ??3)
                   (quad ?*g0 ??3 rdf:first skos:prefLabel)
                   (quad ?*g0 ??3 rdf:rest ??4)
                   (quad ?*g0 ??4 rdf:first "aamiainen*")
                   (quad ?*g0 ??4 rdf:rest rdf:nil)
                 ))))
           (sequence
             (graph ?*g0
               (path ?concept (path* skos:broader) ??5))
             (quadpattern (quad ?*g0 ??5 skos:topConceptOf ?graph)))))


Can you say what you want to achieve with the OPTIONAL maybe, it won't
return any additional data as far as I can see.

On 14.03.22 14:30, Mikael Pesonen wrote:
Hi, not directly related to Jena, but I have a query in which
optional clause limits the number of results. I thought it's never
possible. So below query returns less results with optional enabled.
Wonder why is that and what would be the correct way to get optional
data so than all rows are returned?

SELECT *
WHERE
{
     VALUES ?graph {<http://www.yso.fi/onto/tero/>
<http://www.yso.fi/onto/mesh/>}
     GRAPH ?graph
     {
         {
             SELECT DISTINCT ?concept ?prefLabelm ?altLabelm WHERE
             {
                 {
                     (?concept ?score1 ?prefLabelm) text:query
(skos:prefLabel "aamiainen*") .
                     FILTER ( (lang(?prefLabelm) = "fi" ))
                 }
             }
         }
    # OPTIONAL { ?concept skos:broader* [ skos:topConceptOf ?graph] }
     }
}
--
Lingsoft - 30 years of Leading Language Management

www.lingsoft.fi

Speech Applications - Language Management - Translation - Reader's and Writer's Tools - Text Tools - E-books and M-books

Mikael Pesonen
System Engineer

e-mail:mikael.peso...@lingsoft.fi
Tel. +358 2 279 3300

Time zone: GMT+2

Helsinki Office
Eteläranta 10
FI-00130 Helsinki
FINLAND

Turku Office
Kauppiaskatu 5 A
FI-20100 Turku
FINLAND



--
Lingsoft - 30 years of Leading Language Management

www.lingsoft.fi

Speech Applications - Language Management - Translation - Reader's and Writer's 
Tools - Text Tools - E-books and M-books

Mikael Pesonen
System Engineer

e-mail: mikael.peso...@lingsoft.fi
Tel. +358 2 279 3300

Time zone: GMT+2

Helsinki Office
Eteläranta 10
FI-00130 Helsinki
FINLAND

Turku Office
Kauppiaskatu 5 A
FI-20100 Turku
FINLAND

Reply via email to