Hello Alexander,

I need to get some cities with it's names. And here is my query:
> 
>                SELECT DISTINCT ?cityUri ?cityName
>                WHERE
>                { 
>                 ?cityUri ?predicate ?value.
>                 ?cityUri a <http://linkedgeodata.org/vocabulary#city>.
>                 ?value bif:contains "someCity".
>                 OPTIONAL 
>                 { 
>                  ?cityUri
> <http://linkedgeodata.org/vocabulary#name> ?cityName
>                 } 
>                }
> 
> But when there are several names for one city I get duplicated cities.
> Of course I can remove duplicates after retrieving the result, but
> it's ugly. Is there any way to limit optional parameters (for example,
> as adding Limit to query)?


My favorite cheating is
SELECT DISTINCT ?cityUri (MAX(?cityName)) as ?name
...

that eliminates redundant names. If names differs in language then
recent Virtuosos let you choose best suitable name based on browser
preferences, e.g.

SELECT DISTINCT
?cityUri 
(sql:BEST_LANGMATCH (?cityName, 'ru, en-gb;q=0.8, en;q=0.7, *;q=0.1',
'')) as ?bestCityName
...

Best Regards,

Ivan Mikhailov
OpenLink Software
http://virtuoso.openlinksw.com



Reply via email to