W3C home > Mailing lists > Public > public-rdf-dawg@w3.org > October to December 2010

rq25.xml String functions definitions - first shot (ACTION-350)

From: Axel Polleres <axel.polleres@deri.org>
Date: Mon, 20 Dec 2010 18:37:22 +0000
Message-Id: <82908090-4C83-4D85-ACB5-3B72E0F6EE29@deri.org>
To: SPARQL Working Group <public-rdf-dawg@w3.org>
This discharges ACTION-350: Draft some input for the function library section

I did a first shot drafting the string functions definitions (see below). 
Andy will integrate it with one of the next batches of edits into rq25.xml

It would be great if some other people would also get involved, e.g. 
drafting numeric, date/time, and hash functions.
****Please *ALL* take this as a call for volunteers!****


In this particular case, I tried to 

i) follow the setup Andy defined in
 http://lists.w3.org/Archives/Public/public-rdf-dawg/2010OctDec/0361.html (plus discussion)
and 
ii) taking into account my interpretation of the outcomes of the discussion in
 http://www.w3.org/2009/sparql/meeting/2010-12-07#function_library

Smaller things I wasn't sure about, and which we may collect opinions on: 

1) in the ENCODE function, I wasn't sure what I should do with this note, I left it marked as "todo": 

           <p>Same as javascript encodeURIComponent : fn:encode-for-uri</p>

  (Andy mentioned Steve had preferred it to be ENCODE_FOR_URI due the jaavscript community's
   experience with confusion over names...)

2) in relation to starts(), ends(), contains(), I hope I got the allowed mixes of argument types right.
  I took what I understood from Andy's original mail as a basis...

  (particularly some test cases will make this all concrete, the examples in the doc can be taken as a starting point for TCs)


3) also in relation to starts() and ends(), doesn't "starts" end "ends" sound a bit like 
  the arguments should be reversed as opposed to "starts-with", "ends-with" 
  (however, that'd make the definitions differ significantly from fn:starts-with/fn:ends-with which we probably don't want...)
  Could we use "startsWith" "endsWith" instead (aware that capitalisation doesn't matter)?
  Using "str" in a string function to be clear is also a possibility:
  I.e. the following alternatives
  
    strStarts, strEnds
    startsWith, endsWith
  
   Anyways, I am fine with leaving it as is and I think the WG decision was
   names as suggested as the editor input. Just wanted to have asked...Opinions/comments welcome.
  
=======================================

When someone drafts input, Andy mentioned he prefers only the particular sections to be sent to him, 
instead of the whole rq25.xml (easier to merge, I assume, in case he's editting
somewhere close), see example below...

THanks all,
Axel


--------

         <div4 id="func-strlen">
            <head class="SPARQLoperator">strlen</head>
          <pre class="prototype"><code class="return" title="return">xsd:integer</code>&nbsp;&nbsp;&nbsp;<code class="operator" title="operator">strlen</code>(<code class="parm type" title="parameter type">literal</code> ltrl)</pre>

          <p>The <code>strlen</code> function is SPARQL's correspondent to the XPath <a href="http://www.w3.org/TR/xpath-functions/#func-string-length">fn:string-length</a> function and accepts simple literals, plain literals with language tags as well as <code>xsd:string</code> typed literals as input. For those, it returns an <code>xsd:integer</code> equal to the length in characters of the lexical form of the literal. For typed literals with types other than <code>xsd:string</code> it returns a <a href="http://www.w3.org/TR/xquery/#dt-type-error" class="norm">type error</a>.</p>

          <div class="result">
            <table>
              <tbody>
                <tr>
                  <td><code>strlen("chat")</code></td>
                  <td>"4"^^xs:integer</td>
                </tr>
                <tr>
                  <td><code>strlen("chat"@en)</code></td>
                  <td>"4"^^xs:integer</td>
                </tr>
                <tr>
                  <td><code>strlen("chat"^^xsd:string)</code></td>
                  <td>"4"^^xs:integer</td>
                </tr>
              </tbody>
            </table>
           </div>
       
           </div4>

          <div4 id="func-substr">
            <head class="SPARQLoperator">substr</head>
          <pre class="prototype"><code class="return" title="return">literal</code>&nbsp;&nbsp;&nbsp;<code class="operator" title="operator">substr</code>(<code class="parm type" title="parameter type">literal</code> source, <code class="parm type" title="parameter type">xsd:integer</code> startingLoc)</pre>
          <pre class="prototype"><code class="return" title="return">literal</code>&nbsp;&nbsp;&nbsp;<code class="operator" title="operator">substr</code>(<code class="parm type" title="parameter type">literal</code> source, <code class="parm type" title="parameter type">xsd:integer</code> startingLoc, <code class="parm type" title="parameter type">xsd:integer</code> lengtgh)</pre>

          <p>The <code>substr</code> function is SPARQL's correspondent to the XPath <a href="http://www.w3.org/TR/xpath-functions/#func-string-length">fn:substring</a> function, which is applied to the lexical form of the <code>source</code> input parameter.
 It accepts simple literals, plain literals with language tags as well as <code>xsd:string</code> typed literals for the <code>source</code> input parameter, and returns a <a href="http://www.w3.org/TR/xquery/#dt-type-error" class="norm">type error</a> for all other typed literals. It returns a literal of the same kind (simple literal, literal with language tag, <code>xsd:string</code> typed literal) as the <code>source</code> input parameter.</p>

          <div class="result">
            <table>
              <tbody>
                <tr>
                  <td><code>substring("foobar", "4"^^xsd:integer)</code></td>
                  <td>"bar"</td>
                </tr>
                <tr>
                  <td><code>strlen("foobar"@en, "4"^^xsd:integer)</code></td>
                  <td>"bar"@en</td>
                </tr>
                <tr>
                  <td><code>strlen("foobar"^^xsd:string, "4"^^xsd:integer)</code></td>
                  <td>"bar"^^xsd:string</td>
                </tr>
                <tr>
                  <td><code>substring("foobar", "4"^^xsd:integer, "1"^^xsd:integer)</code></td>
                  <td>"b"</td>
                </tr>
                <tr>
                  <td><code>strlen("foobar"@en, "4"^^xsd:integer, "1"^^xsd:integer)</code></td>
                  <td>"b"@en</td>
                </tr>
                <tr>
                  <td><code>strlen("foobar"^^xsd:string, "4"^^xsd:integer, "1"^^xsd:integer)</code></td>
                  <td>"b"^^xsd:string</td>
                </tr>
              </tbody>
            </table>
           </div>
          </div4>

          <div4 id="func-ucase">
            <head class="SPARQLoperator">ucase</head>
 <pre class="prototype"><code class="return" title="return">literal</code>&nbsp;&nbsp;&nbsp;<code class="operator" title="operator">ucase</code>(<code class="parm type" title="parameter type">literal</code> ltrl)</pre>

          <p>The <code>ucase</code> function is SPARQL's correspondent to the XPath <a href="http://www.w3.org/TR/xpath-functions/#func-upper-case">fn:upper-case</a> function and accepts simple literals, plain literals with language tags as well as <code>xsd:string</code> typed literals as input. For those, it returns a literal of the same kind (simple literal, literal with language tag, <code>xsd:string</code> typed literal) as its input after translating every character of the lexical form of its input to its upper-case correspondent. For typed literals with types other than <code>xsd:string</code> it returns a <a href="http://www.w3.org/TR/xquery/#dt-type-error" class="norm">type error</a>.</p>

          <div class="result">
            <table>
              <tbody>
                <tr>
                  <td><code>ucase("foo")</code></td>
                  <td>"FOO"</td>
                </tr>
                <tr>
                  <td><code>ucase("foo"@en)</code></td>
                  <td>"FOO"@en</td>
                </tr>
                <tr>
                  <td><code>ucase("foo"^^xsd:string)</code></td>
                  <td>"FOO"^^xsd:string</td>
                </tr>
              </tbody>
            </table>
           </div>          </div4>

          <div4 id="func-lcase">
            <head class="SPARQLoperator">lcase</head>
 <pre class="prototype"><code class="return" title="return">literal</code>&nbsp;&nbsp;&nbsp;<code class="operator" title="operator">lcase</code>(<code class="parm type" title="parameter type">literal</code> ltrl)</pre>

          <p>The <code>lcase</code> function is SPARQL's correspondent to the XPath <a href="http://www.w3.org/TR/xpath-functions/#func-lower-case">fn:lower-case</a> function and accepts simple literals, plain literals with language tags as well as <code>xsd:string</code> typed literals as input. For those, it returns a literal of the same kind (simple literal, literal with language tag, <code>xsd:string</code> typed literal) as its input after translating every character of the lexical form of its input to its lower-case correspondent. For typed literals with types other than <code>xsd:string</code> it returns a <a href="http://www.w3.org/TR/xquery/#dt-type-error" class="norm">type error</a>.</p>

          <div class="result">
            <table>
              <tbody>
                <tr>
                  <td><code>lcase("BAR")</code></td>
                  <td>"bar"</td>
                </tr>
                <tr>
                  <td><code>lcase("BAR"@en)</code></td>
                  <td>"bar"@en</td>
                </tr>
                <tr>
                  <td><code>lcase("BAR"^^xsd:string)</code></td>
                  <td>"bar"^^xsd:string</td>
                </tr>
              </tbody>
            </table>
           </div>            </div4>

          <div4 id="func-ends">
            <head class="SPARQLoperator">ends</head>
<pre class="prototype"><code class="return" title="return">xsd:boolean</code>&nbsp;&nbsp;&nbsp;<code class="operator" title="operator">ends</code>(<code class="parm type" title="parameter type">literal</code> arg1, <code class="parm type" title="parameter type">literal</code> arg2)</pre>

          <p>The <code>ends</code> function is SPARQL's correspondent to the XPath <a href="http://www.w3.org/TR/xpath-functions/#func-ends-with">fn:ends-with</a> function and 
accepts</p>
<ul>
<li>pairs of simple literals,</li> 
<li>pairs of <code>xsd:string</code> typed literals</li>
<li>pairs of plain literals with identical language tags</li>
<li>pairs of an <code>xsd:string</code> typed literal (<code>arg1</code> or <code>arg2</code>) and a simple literal (<code>arg2</code> or <code>arg1</code>)</li>
<li>pairs of a plain literal with language tag (<code>arg1</code>) and a simple literal (<code>arg2</code>)</li>
<li>pairs of a plain literal with language tag (<code>arg1</code>) and an <code>xsd:string</code> typed literal (<code>arg2</code>)</li>
</ul>
<p>as input. For such input pairs, it returns true, whenever the lexical form of <code>arg1</code> ends with the lexical form of <code>arg2</code>, false otherwise; for other combinations of input literals it returns a <a href="http://www.w3.org/TR/xquery/#dt-type-error" class="norm">type error</a>. </p>

          <div class="result">
            <table>
              <tbody>
                <tr>
                  <td><code>ends("foobar", "bar")</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>ends("foobar"@en, "bar"@en)</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>ends("foobar"^^xsd:string, "bar"^^xsd:string)</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>ends("foobar"^^xsd:string, "bar")</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>ends("foobar", "bar"^^xsd:string)</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>ends("foobar"@en, "bar")</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>ends("foobar"@en, "bar"^^xsd:string)</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
              </tbody>
            </table>
           </div>            </div4>

          <div4 id="func-starts">
            <head class="SPARQLoperator">starts</head>
<pre class="prototype"><code class="return" title="return">xsd:boolean</code>&nbsp;&nbsp;&nbsp;<code class="operator" title="operator">starts</code>(<code class="parm type" title="parameter type">literal</code> arg1, <code class="parm type" title="parameter type">literal</code> arg2)</pre>

          <p>The <code>starts</code> function is SPARQL's correspondent to the XPath <a href="http://www.w3.org/TR/xpath-functions/#func-starts-with">fn:starts-with</a> function and 
accepts</p>
<ul>
<li>pairs of simple literals,</li> 
<li>pairs of <code>xsd:string</code> typed literals</li>
<li>pairs of plain literals with identical language tags</li>
<li>pairs of an <code>xsd:string</code> typed literal (<code>arg1</code> or <code>arg2</code>) and a simple literal (<code>arg2</code> or <code>arg1</code>)</li>
<li>pairs of a plain literal with language tag (<code>arg1</code>) and a simple literal (<code>arg2</code>)</li>
<li>pairs of a plain literal with language tag (<code>arg1</code>) and an <code>xsd:string</code> typed literal (<code>arg2</code>)</li>
</ul>
<p>as input. For such input pairs, it returns true, whenever the lexical form of <code>arg1</code> starts with the lexical form of <code>arg2</code>, false otherwise; for other combinations of input literals it returns a <a href="http://www.w3.org/TR/xquery/#dt-type-error" class="norm">type error</a>. </p>

          <div class="result">
            <table>
              <tbody>
                <tr>
                  <td><code>starts("foobar", "foo")</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>starts("foobar"@en, "foo"@en)</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>starts("foobar"^^xsd:string, "foo"^^xsd:string)</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>starts("foobar"^^xsd:string, "foo")</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>starts("foobar", "foo"^^xsd:string)</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>starts("foobar"@en, "foo")</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>starts("foobar"@en, "foo"^^xsd:string)</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
              </tbody>
            </table>
           </div>            </div4>

          <div4 id="func-contains">
            <head class="SPARQLoperator">contains</head>
<pre class="prototype"><code class="return" title="return">xsd:boolean</code>&nbsp;&nbsp;&nbsp;<code class="operator" title="operator">contains</code>(<code class="parm type" title="parameter type">literal</code> arg1, <code class="parm type" title="parameter type">literal</code> arg2)</pre>

          <p>The <code>contains</code> function is SPARQL's correspondent to the XPath <a href="http://www.w3.org/TR/xpath-functions/#func-contains">fn:contains</a> function and 
accepts</p>
<ul>
<li>pairs of simple literals,</li> 
<li>pairs of <code>xsd:string</code> typed literals</li>
<li>pairs of plain literals with identical language tags</li>
<li>pairs of an <code>xsd:string</code> typed literal (<code>arg1</code> or <code>arg2</code>) and a simple literal (<code>arg2</code> or <code>arg1</code>)</li>
<li>pairs of a plain literal with language tag (<code>arg1</code>) and a simple literal (<code>arg2</code>)</li>
<li>pairs of a plain literal with language tag (<code>arg1</code>) and an <code>xsd:string</code> typed literal (<code>arg2</code>)</li>
</ul>
<p>as input. For such input pairs, it returns true, whenever the lexical form of <code>arg1</code> contains the lexical form of <code>arg2</code>, false otherwise; for other combinations of input literals it returns a <a href="http://www.w3.org/TR/xquery/#dt-type-error" class="norm">type error</a>. </p>

          <div class="result">
            <table>
              <tbody>
                <tr>
                  <td><code>contains("foobar", "bar")</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>contains("foobar"@en, "foo"@en)</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>contains("foobar"^^xsd:string, "bar"^^xsd:string)</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>contains("foobar"^^xsd:string, "foo")</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>contains("foobar", "bar"^^xsd:string)</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>contains("foobar"@en, "foo")</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
                <tr>
                  <td><code>contains("foobar"@en, "bar"^^xsd:string)</code></td>
                  <td>"true"^^xsd:boolean</td>
                </tr>
              </tbody>
            </table>
           </div>            </div4>

          <div4 id="func-encode">
            <head class="SPARQLoperator">encode</head>
 <pre class="prototype"><code class="return" title="return">simple literal</code>&nbsp;&nbsp;&nbsp;<code class="operator" title="operator">encode</code>(<code class="parm type" title="parameter type">literal</code> ltrl)</pre>

          <p>The <code>encode</code> function is SPARQL's correspondent to the XPath <a href="http://www.w3.org/TR/xpath-functions/#func-encode-for-uri">fn:encode-for-uri</a> function and accepts simple literals  as well as <code>xsd:string</code> typed literals as input. It returns a simple literal with the lexical form obtained from the lexical form of its input after translating reserved characters according to the <a href="http://www.w3.org/TR/xpath-functions/#func-encode-for-uri">fn:encode-for-uri</a> function. For plain literals with language tag or typed literals with types other than <code>xsd:string</code> it returns a <a href="http://www.w3.org/TR/xquery/#dt-type-error" class="norm">type error</a>.</p>

          <div class="result">
            <table>
              <tbody>
                <tr>
                  <td><code>encode("Los Angeles")</code></td>
                  <td>"Los%20Angeles"</td>
                </tr>
                <tr>
                  <td><code>encode("Los Angeles"^^xsd:string)</code></td>
                  <td>"Los%20Angeles"^^xsd:string</td>
                </tr>
              </tbody>
            </table>
           </div>
            <div class="todo">@@Same as javascript encodeURIComponent : fn:encode-for-uri</div>
          </div4>

          <div4 id="func-concat">
            <head class="SPARQLoperator">concat</head>
<pre class="prototype"><code class="return" title="return">literal</code>&nbsp;&nbsp;&nbsp;<code class="operator" title="operator">concat</code>(<code class="parm type" title="parameter type">literal</code> ltrl<sub>1</sub> ... <code class="parm type" title="parameter type">literal</code> ltrl<sub>n</sub>)</pre>
 <p>The <code>concat</code> function is SPARQL's correspondent to the XPath <a href="http://www.w3.org/TR/xpath-functions/#func-concat">fn:concat</a> function. The function accepts  simple literals, plain literals with language tags as well as <code>xsd:string</code> typed literals as inputs; for typed literals with types other than <code>xsd:string</code> a <a href="http://www.w3.org/TR/xquery/#dt-type-error" class="norm">type error</a> is returned.
 The lexical form of the returned literal is obtained by concatenating the lexical forms of its inputs.
If all input literals are typed literals of type <code>xsd:string</code>, then the returned literal is also of type <code>xsd:string</code>, if all input literals are plain literals with identical language tag, then the returned literal is a plain literal with the same language tag, in all other cases, the returned literal is a simple literal.</p>
 
<div class="todo">@@ Note: this implies inheriting homogeneous language tags and dropping ambiguous language tags.</div>

          <div class="result">
            <table>
              <tbody>
                <tr>
                  <td><code>concat("foo", "bar")</code></td>
                  <td>"foobar"</td>
                </tr>
                <tr>
                  <td><code>concat("foo"@en, "foo"@en)</code></td>
                  <td>"foobar"@en</td>
                </tr>
                <tr>
                  <td><code>concat("foo"^^xsd:string, "bar"^^xsd:string)</code></td>
                  <td>"foobar"^^xsd:string</td>
                </tr>
                <tr>
                  <td><code>concat("foo"^^xsd:string, "foo")</code></td>
                  <td>"foobar"</td>
                </tr>
                <tr>
                  <td><code>concat("foo", "bar"^^xsd:string)</code></td>
                  <td>"foobar"</td>
                </tr>
                <tr>
                  <td><code>concat("foo"@en, "foo")</code></td>
                  <td>"foobar"</td>
                </tr>
                <tr>
                  <td><code>concat("foo"@en, "bar"^^xsd:string)</code></td>
                  <td>"foobar"</td>
                </tr>
              </tbody>
            </table>
           </div>  
          </div4>
Received on Monday, 20 December 2010 18:37:55 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 16:15:44 GMT