You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Mikael Pesonen <mi...@lingsoft.fi> on 2016/04/14 11:11:10 UTC

Problem with simple query

Hi,

im matching strings in different graphs and this should do the trick:

SELECT ?prefLabel ?s2
WHERE {
   GRAPH <http://www.lingsoft.fi/somegraph>
   {
     ?s skos:prefLabel ?prefLabel .
   }
   OPTIONAL {
     GRAPH ?graph
     {
       ?s2 skos:prefLabel ?label2

       FILTER ( lcase(str(?prefLabel)) = lcase(str(?label2)) )
     }
   }
}

but im not getting any results. There are plenty of matches in store and 
this returns them (case sensitive match)

SELECT ?prefLabel ?s2
WHERE {
   GRAPH <http://www.lingsoft.fi/somegraph>
   {
     ?s skos:prefLabel ?prefLabel .
   }
   OPTIONAL {
     GRAPH ?graph
     {
       ?s2 skos:prefLabel ?prefLabel
     }
   }
}


Im I using FILTER wrong way or could it be a bug in search engine?

Br,
Mikael

-- 
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.pesonen@lingsoft.fi
Tel. +358 2 279 3300

Time zone: GMT+2

Helsinki Office
Eteläranta 10
FI-00130 Helsinki
FINLAND

Turku Office
Linnankatu 10 A
FI-20100 Turku
FINLAND


Re: Problem with simple query

Posted by james anderson <ja...@dydra.com>.
good morning,

> On 2016-04-14, at 11:11, Mikael Pesonen <mi...@lingsoft.fi> wrote:
> 
> 
> Hi,
> 
> im matching strings in different graphs and this should do the trick:

a more complete statement of your intent would help, but going by the query text, it appears that your goal is to retrieve all skos:prefLabels values from the <http://www.lingsoft.fi/somegraph> graph and, for those which also have a similar label in any graph, to augment the solution(s) with the respective graph name and label value.

if that is the intent, the first query cannot succeed: as another response noted, ?prefLabel is unbound in the optional clause.

the second query demonstrates that the semantics of an optional operator accomplishes some of your intent, as it correlates the values where the correspondence is based on term identity.

if you intend to relax that constraint, you will need to either produce an appropriate binding for the corresponding variable within the optional clause, as in

   BIND (lcase(str(?label2)) as ?prefLabel)

and allow the optional to produce your intended result, or perform the filter in a scope which comprises the initial ?prefLabel binding, but with logic which emulates that of the optional operator, for example

  FILTER ( ( !bound(?label2) ) || lcase(str(?prefLabel)) = lcase(str(?label2)) )

whereby, as another response noted, the optional with just the single pattern, will act as a cross-join.
this argues for the former approach.

best regards, from berlin,

> 
> SELECT ?prefLabel ?s2
> WHERE {
> GRAPH <http://www.lingsoft.fi/somegraph>
> {
>   ?s skos:prefLabel ?prefLabel .
> }
> OPTIONAL {
>   GRAPH ?graph
>   {
>     ?s2 skos:prefLabel ?label2
> 
>     FILTER ( lcase(str(?prefLabel)) = lcase(str(?label2)) )
>   }
> }
> }
> 
> but im not getting any results. There are plenty of matches in store and this returns them (case sensitive match)
> 
> SELECT ?prefLabel ?s2
> WHERE {
> GRAPH <http://www.lingsoft.fi/somegraph>
> {
>   ?s skos:prefLabel ?prefLabel .
> }
> OPTIONAL {
>   GRAPH ?graph
>   {
>     ?s2 skos:prefLabel ?prefLabel
>   }
> }
> }
> 
> 
> Im I using FILTER wrong way or could it be a bug in search engine?
> 
> Br,
> Mikael
> 
> -- 
> 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.pesonen@lingsoft.fi
> Tel. +358 2 279 3300
> 
> Time zone: GMT+2
> 
> Helsinki Office
> Eteläranta 10
> FI-00130 Helsinki
> FINLAND
> 
> Turku Office
> Linnankatu 10 A
> FI-20100 Turku
> FINLAND
> 

---
james anderson | james@dydra.com | http://dydra.com






Re: Problem with simple query

Posted by Claude Warren <cl...@xenei.com>.
Given that the  two queries have no common variables, wouldn't removing the
optional be more performant?  It seems like the optional will create extra
null results for <ANY skos:prefLabel ANY> triple, then do the cross product
with the same query from the other graph.   I think that removing the
optional will reduce the number of results in one side of the cross product.


Claude

On Thu, Apr 14, 2016 at 10:57 AM, Mikael Pesonen <mikael.pesonen@lingsoft.fi
> wrote:

>
> Thanks, that worked!
>
> Br,
> Mikael
>
>
>
> On 14.4.2016 12:36, Martynas Jusevičius wrote:
>
>> My guess would be that because of SPARQL bottom-up semantics,
>> ?prefLabel is undefined at the point where you are applying it. Try
>> moving it out of OPTIONAL.
>>
>> On Thu, Apr 14, 2016 at 11:11 AM, Mikael Pesonen
>> <mi...@lingsoft.fi> wrote:
>>
>>> Hi,
>>>
>>> im matching strings in different graphs and this should do the trick:
>>>
>>> SELECT ?prefLabel ?s2
>>> WHERE {
>>>    GRAPH <http://www.lingsoft.fi/somegraph>
>>>    {
>>>      ?s skos:prefLabel ?prefLabel .
>>>    }
>>>    OPTIONAL {
>>>      GRAPH ?graph
>>>      {
>>>        ?s2 skos:prefLabel ?label2
>>>
>>>        FILTER ( lcase(str(?prefLabel)) = lcase(str(?label2)) )
>>>      }
>>>    }
>>> }
>>>
>>> but im not getting any results. There are plenty of matches in store and
>>> this returns them (case sensitive match)
>>>
>>> SELECT ?prefLabel ?s2
>>> WHERE {
>>>    GRAPH <http://www.lingsoft.fi/somegraph>
>>>    {
>>>      ?s skos:prefLabel ?prefLabel .
>>>    }
>>>    OPTIONAL {
>>>      GRAPH ?graph
>>>      {
>>>        ?s2 skos:prefLabel ?prefLabel
>>>      }
>>>    }
>>> }
>>>
>>>
>>> Im I using FILTER wrong way or could it be a bug in search engine?
>>>
>>> Br,
>>> Mikael
>>>
>>> --
>>> 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.pesonen@lingsoft.fi
>>> Tel. +358 2 279 3300
>>>
>>> Time zone: GMT+2
>>>
>>> Helsinki Office
>>> Eteläranta 10
>>> FI-00130 Helsinki
>>> FINLAND
>>>
>>> Turku Office
>>> Linnankatu 10 A
>>> FI-20100 Turku
>>> FINLAND
>>>
>>>
> --
> 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.pesonen@lingsoft.fi
> Tel. +358 2 279 3300
>
> Time zone: GMT+2
>
> Helsinki Office
> Eteläranta 10
> FI-00130 Helsinki
> FINLAND
>
> Turku Office
> Linnankatu 10 A
> FI-20100 Turku
> FINLAND
>
>


-- 
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren

Re: Problem with simple query

Posted by Mikael Pesonen <mi...@lingsoft.fi>.
Thanks, that worked!

Br,
Mikael


On 14.4.2016 12:36, Martynas Jusevičius wrote:
> My guess would be that because of SPARQL bottom-up semantics,
> ?prefLabel is undefined at the point where you are applying it. Try
> moving it out of OPTIONAL.
>
> On Thu, Apr 14, 2016 at 11:11 AM, Mikael Pesonen
> <mi...@lingsoft.fi> wrote:
>> Hi,
>>
>> im matching strings in different graphs and this should do the trick:
>>
>> SELECT ?prefLabel ?s2
>> WHERE {
>>    GRAPH <http://www.lingsoft.fi/somegraph>
>>    {
>>      ?s skos:prefLabel ?prefLabel .
>>    }
>>    OPTIONAL {
>>      GRAPH ?graph
>>      {
>>        ?s2 skos:prefLabel ?label2
>>
>>        FILTER ( lcase(str(?prefLabel)) = lcase(str(?label2)) )
>>      }
>>    }
>> }
>>
>> but im not getting any results. There are plenty of matches in store and
>> this returns them (case sensitive match)
>>
>> SELECT ?prefLabel ?s2
>> WHERE {
>>    GRAPH <http://www.lingsoft.fi/somegraph>
>>    {
>>      ?s skos:prefLabel ?prefLabel .
>>    }
>>    OPTIONAL {
>>      GRAPH ?graph
>>      {
>>        ?s2 skos:prefLabel ?prefLabel
>>      }
>>    }
>> }
>>
>>
>> Im I using FILTER wrong way or could it be a bug in search engine?
>>
>> Br,
>> Mikael
>>
>> --
>> 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.pesonen@lingsoft.fi
>> Tel. +358 2 279 3300
>>
>> Time zone: GMT+2
>>
>> Helsinki Office
>> Eteläranta 10
>> FI-00130 Helsinki
>> FINLAND
>>
>> Turku Office
>> Linnankatu 10 A
>> FI-20100 Turku
>> FINLAND
>>

-- 
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.pesonen@lingsoft.fi
Tel. +358 2 279 3300

Time zone: GMT+2

Helsinki Office
Eteläranta 10
FI-00130 Helsinki
FINLAND

Turku Office
Linnankatu 10 A
FI-20100 Turku
FINLAND


Re: Problem with simple query

Posted by Martynas Jusevičius <ma...@graphity.org>.
My guess would be that because of SPARQL bottom-up semantics,
?prefLabel is undefined at the point where you are applying it. Try
moving it out of OPTIONAL.

On Thu, Apr 14, 2016 at 11:11 AM, Mikael Pesonen
<mi...@lingsoft.fi> wrote:
>
> Hi,
>
> im matching strings in different graphs and this should do the trick:
>
> SELECT ?prefLabel ?s2
> WHERE {
>   GRAPH <http://www.lingsoft.fi/somegraph>
>   {
>     ?s skos:prefLabel ?prefLabel .
>   }
>   OPTIONAL {
>     GRAPH ?graph
>     {
>       ?s2 skos:prefLabel ?label2
>
>       FILTER ( lcase(str(?prefLabel)) = lcase(str(?label2)) )
>     }
>   }
> }
>
> but im not getting any results. There are plenty of matches in store and
> this returns them (case sensitive match)
>
> SELECT ?prefLabel ?s2
> WHERE {
>   GRAPH <http://www.lingsoft.fi/somegraph>
>   {
>     ?s skos:prefLabel ?prefLabel .
>   }
>   OPTIONAL {
>     GRAPH ?graph
>     {
>       ?s2 skos:prefLabel ?prefLabel
>     }
>   }
> }
>
>
> Im I using FILTER wrong way or could it be a bug in search engine?
>
> Br,
> Mikael
>
> --
> 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.pesonen@lingsoft.fi
> Tel. +358 2 279 3300
>
> Time zone: GMT+2
>
> Helsinki Office
> Eteläranta 10
> FI-00130 Helsinki
> FINLAND
>
> Turku Office
> Linnankatu 10 A
> FI-20100 Turku
> FINLAND
>