W3C home > Mailing lists > Public > semantic-web@w3.org > March 2018

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

From: Jürgen Jakobitsch <juergen.jakobitsch@semantic-web.com>
Date: Thu, 22 Mar 2018 16:58:22 +0100
Message-ID: <CAETaefyz8SNFOvp1bh53KY=a0q+3sn6R9Wr6wr=Xw9Zod0NTSw@mail.gmail.com>
To: Paul Tyson <phtyson@sbcglobal.net>
Cc: Mikael Pesonen <mikael.pesonen@lingsoft.fi>, semantic-web@w3.org
sorry.. couldn't resist.. :-)

SELECT
  ?concept

(STRLANG(REPLACE(STR(?template),'(\\d{1}-)(.*?)(@(en|de))$','$2'),STRAFTER(?template,"@"))
AS ?label)
WHERE {
  SELECT
    (MAX(CONCAT(?priority,"-",STR(?prefLabel),"@",STR(?lang))) AS ?template)
    ?concept
  WHERE {
    VALUES (?lang ?priority) { ("en" 1) ("de" 2) }
    ?concept skos:prefLabel ?prefLabel FILTER(LANG(?prefLabel)=?lang)
  }
}

krj

*Jürgen Jakobitsch*
Innovation Director
Semantic Web Company GmbH
EU: +43-14021235 <+43%201%204021235>
US: (415) 800-3776
Mobile: +43-676-6212710 <+43%20676%206212710>
https://www.poolparty.biz
https://www.semantic-web.com

*Download now
<https://www.poolparty.biz/wp-content/uploads/2017/08/IDC_Paper_How_Semantic_Technologies_Steer_Cognitive_Applications.pdf>
**IDC
White Paper*
*Get certified! <https://www.poolparty.biz/academy/> **PoolParty Academy*


*PoolParty selected as a KMWorld Trend-Setting Product for 2017*


PERSONAL INFORMATION
| web       : http://www.turnguard.com
| foaf      : http://www.turnguard.com/turnguard
| g+        : https://plus.google.com/111233759991616358206/posts
| skype     : jakobitsch-punkt
| xmlns:tg  = "http://www.turnguard.com/turnguard#"
| blockchain : https://onename.com/turnguard

2018-03-22 15:53 GMT+01:00 Paul Tyson <phtyson@sbcglobal.net>:

> 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 15:58:47 UTC

This archive was generated by hypermail 2.3.1 : Thursday, 22 March 2018 15:58:56 UTC