Re: Help with simple SPARQL query getting strings of selected languages

Something like this might work (untested):

SELECT
(min(?s) as ?preferred_s) ?s_type 
FROM <http://some_graph/>
WHERE
{
     ?s a ?s_type .
     ?s <http://schema.org/name> ?s_label_g
     BIND (if (lang(?s_label_g) = "en"
           ,1
           ,if(lang(?s_label_g) = "",2,3)) AS ?priority)
}
group by ?s ?s_type
order by ?priority asc

Regards,
--Paul

On Thu, 2018-03-22 at 14:45 +0200, Mikael Pesonen wrote:
> Hi,
> 
> I'm having trouble contructing a basic query which selects a string so 
> that it prefers one language, over others but always tries to return 
> something.
> 
> So I have names
> 
> :item schema:name "name"@en
> :item schema:name "nimi"@fi
> :item schema:name "namn"
> 
> I need query that returns the English name ("name"@en) , but if not 
> found the name without language ("namn"), and as last resort name in 
> Finnish ("nimi"@fi)
> 
> This query returns one random name:
> 
> SELECT
> ?s
> (SAMPLE(?s_label_g) as ?s_label)
> ?s_type
> FROM <http://some_graph/>
> WHERE
> {
>      ?s a ?s_type .
>      ?s <http://schema.org/name> ?s_label_g
> }
> GROUP BY ?s ?s_type
> 
> 
> Anyone can help?
> 

Received on Thursday, 22 March 2018 14:54:31 UTC