W3C home > Mailing lists > Public > public-rdf-dawg@w3.org > April to June 2005

Re: using standard functions by URI

From: Seaborne, Andy <andy.seaborne@hp.com>
Date: Fri, 15 Apr 2005 20:44:51 +0100
Message-ID: <426019B3.1070809@hp.com>
To: Dan Connolly <connolly@w3.org>
Cc: RDF Data Access Working Group <public-rdf-dawg@w3.org>

Dan Connolly wrote:
> XQuery/XPath functions have URIs.
> e.g
>   http://www.w3.org/2005/04/xpath-functions/#max
> Suppose I write...
> PREFIX ex: <http://example/vocab#>
> PREFIX xfo: <http://www.w3.org/2005/04/xpath-functions/#>
> WHERE { ?who ex:name ?n
>         FILTER xfo:matches(?n, "Dan") . 
>       }
> That's a core SPARQL query, right? It works just as well as...
> PREFIX ex: <http://example/vocab#>
> WHERE { ?who ex:name ?n
>         FILTER regex(?n, "Dan") . 
>       }

Thanks for the example - I thought "yes" and went to make sure I could add 
such a function to ARQ's function registry.  But the devil is in the detail.

On investigation I found that, while your two queries are the same, regex is 
not exactly a shorter way to say xfo:matches as things stand.

xfo:matches is a general function application (SPARQL grammar) which can take 
two or three arguments. The arguments can be any expression, including 
variables.  So "xfo:matches(?str, ?regex)" is legal and is a dynamic pattern.

PREFIX ex: <http://example/vocab#>
PREFIX xfo: <http://www.w3.org/2005/04/xpath-functions/#>

WHERE { ?who ex:name ?n . ?y ex:pattern ?regex .
         xfo:matches(?n, ?regex)

I hadn't considered that to be an important feature or requirement for REGEX.

Regex, by the current grammar, takes 2 or 3 arguments but the second and third 
  must be constant strings.  The string regular expression is fixed in the query.

I can change this and make them dynamic arguements are rely on implementations 
spotting constants and precompiling regexs just once.  That is not hard at all.

However, some implementations will find the fully general regex being exacly 
fn:matches rather hard because base technology (SQL) does not provide much help.


     string LIKE pattern [ESCAPE escape-character]
     string SIMILAR TO pattern [ESCAPE escape-character]

The pattern is a fixed regular expression.

Eric - it would seem that there has to be a change to 11.1 or to the grammar. 
  What's your (or anyone else's) opinion.

> I don't see any text to that effect in
> http://www.w3.org/2001/sw/DataAccess/rq23/#extensionFunctions
> $Revision: 1.300 $ of $Date: 2005/04/14 11:43:04 $

Section 11:
The SPARQL operations are listed in table 11.1 and are associated with 
productions in the grammar. In addition, SPARQL imports a subset of the XPath 
functions, listed in table 11.2, which are invokable by name within a SPARQL 
query. These functions and operators are taken from the XQuery 1.0 and XPath 
2.0 Functions and Operators [17].

The only two appear to be fn:not and fn:matches.

> I think it's worth testing too.



Received on Friday, 15 April 2005 19:45:08 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:00:47 UTC