Re: IRI creation and encoding

Hi Peter,

Sorry for the delayed answer. Note that your proposed query doesn't work as such in SPARQL1.1: first, it overloads "+" as string concatenation and uses expressions in the CONSTRUCT template. You can use fn:concat from from XPath/Xquery Functions&Operators here. Also, as alternative for example:percentEncode, it seems you could likewise consider fn:encode-for-uri.


This said, your query would be expressible following the current draft of SPARQL 1.1 by subqueries as follows:

PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX myLibrary: <http://mylibrary.example/>

CONSTRUCT { ?s skos:prefLabel ?label . 
           ?s myLibrary:hasAlternateURI ?u }
WHERE { { SELECT ?s (IRI(fn:concat("http://otherlibrary.example/",
           fn:encode-for-uri(?label),
           "/lang/",fn:encode-for-uri(lang(?label)))) AS  ?u )
        WHERE { ?s skos:prefLabel ?label . } } }

Please note that not every SPARQL1.1 compliant implementation is supposed to support all of the XPath/Xquery functions, we are currently discussing which additional functions to add to the standard library. In fact, fn:concat and fn:encode-for-uri are on the list of proposed functions for such an extension of the standard function library [1] so they would become normative and thus should be supported by SPARQL1.1 compliant implementations.

Also, note that the actual syntax may still change, in fact, the group is discussing whether to take your proposal on board to allow '+' as a shortcut notation for string concatenation (fn:concat).

Hope this clarfies matters, and thanks for your comment again, with best regards, Axel

1. http://www.w3.org/2009/sparql/wiki/Feature:FunctionLibrary#XQuery_1.0_and_XPath_2.0_Functions_and_Operators

On 4 Jun 2010, at 01:01, Peter Ansell wrote:

> Hi,
> 
> I am not sure what the progress has been on the (very useful)
> extension to make it possible for SPARQL to create new URI/IRIs from
> literals/variables [1] but it would be nice if the discussion could
> also include something about a function for string transformation to
> encode strings so that the URIs are valid.
> 
> For example it would be nice to be able to do something similar to the
> following pattern using a IRI/URI creation facility,
> 
> CONSTRUCT
> { ?s <skos:prefLabel> ?label . ?s <myLibrary:hasAlternateURI>
> IRI("http://otherlibrary.example/"+example:percentEncode(?label)+"/lang/"+example:percentEncode(lang(?label))}
> WHERE
> { ?s <skos:prefLabel> ?label . }
> 
> Cheers,
> 
> Peter
> 
> [1] http://www.w3.org/2009/sparql/wiki/Feature:IriBuiltIn
> 
> 

Received on Tuesday, 12 October 2010 16:02:59 UTC