<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>call: A Nucleus for a Web of Open Functions</article-title>
      </title-group>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>Math/CS Department University of Cagliari Via Ospedale</institution>
          <addr-line>72 09124 Cagliari (CA)</addr-line>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>In our recent work we envisioned a Web where functions, like Linked Data, can be openly published and available to all the users of any remote sparql endpoint. The resulting Web of Functions can be realized by introducing a call sparql extension that can invoke any remote function (custom third-party extensions) by only knowing its corresponding URI, while the implementation and the computational resources are made available by the function publisher. In this paper we demo our framework with a set of functions showing (1) advanced use of its higher-order expressivity power featuring, e.g., function composition of third-party functions, and (2) a possible bridge between hundreds of standard Web APIs and the Web of Functions. In our view these functions found an initial nucleus to which anyone can contribute within the decentralized Web of Functions, made available through call.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>
        While extending the language with user-de ned custom functions (sometimes
called extension functions) represented by URIs is a native feature of the sparql
language, the mechanism only works on the single endpoint featuring that
speci c function. In our recent work [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], we investigated interoperability,
computational power and expressivity of functions that can be used within a sparql
query, envisioning a Web where also functions can be openly published, making
them available to all the users of any other endpoint. In [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] we de ne a wfn:call
function with three possible architectures to deploy it in a backward compatible
manner. It is the basis needed in order to realize a Web of Open Functions,
meaning that users can call a function by only knowing its corresponding URI,
as it is the case for entities and properties in the Web of Open Data1, while
the implementation and the computational resources are made available by the
function publisher, as it happens with usual Web APIs.
      </p>
      <p>
        Practically, supposing that Alice wants to use a Bob's sparql extension (only
de ned in Bob's endpoint) from her own endpoint, she will write the following:
PREFIX wfn: &lt;http://webofcode.org/wfn/&gt;
1 We titled this paper after DBpedia milestone work in [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ].
      </p>
      <p>PREFIX bob: &lt;http://bob-server.org/fn/&gt;
SELECT *
WHERE {
# within Alice data, find useful values for ?arg1, ?arg2
...
# now use Bob's function</p>
      <p>
        FILTER(wfn:call(bob:complexFunction, ?arg1, ?arg2) )
}
Therefore, the function wfn:call takes care of nding the right endpoint (see [
        <xref ref-type="bibr" rid="ref1 ref3 ref4">1,
3, 4</xref>
        ]), i.e., Bob's, and then remotely call Bob's complexFunction. We believe this
may be the rst step toward a novel view of the Web as a place holding code
and functions, not only data as the Linked Data is greatly doing. The Semantic
Web already shifted URIs from pages to conceptual entities, primarily
structured data. We believe that among these concepts there should be computable
functions.
      </p>
      <p>In this paper we demo our open source implementation for the wfn:call
function, realized as an Apache Jena's custom function extension, and
available with other resources (including a link to our endpoint that publishes it)
at http://atzori.webofcode.org/projects/wfn/. In particular, we devise an
initial nucleus of practical functions that may empower sparql queries with
computations that exploit higher-order expressivity and hundreds of existing
Web APIs.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Fully Higher-Order Functions in SPARQL</title>
      <p>Higher-order functions (HOF) are functions that take functions as either input
and/or output. Languages that allow functions to be used as any other kind
of data, are said to feature rst-class functions. Here we show that these
advanced expressivity, typical of functional languages, can be used within sparql
by means of wfn:call. In the following we exemplify it by describing the use of
three important HOF: reduce, compose and memoize.</p>
      <p>Reduce. In functional languages \reduce" (also called \fold", \inject" or
\aggregate") is a function that takes a binary function (e.g., the + operator) and a list
(e.g., a list of integers), producing a result by recursively applying the function
to the remaining list (providing, e.g., the sum of all the elements). Thus, it
represents a general-purpose aggregation mechanism potentially useful in sparql
queries. In the following we show how it can be used to apply the binary max
function provided by Jena to a list of 4 numbers:
PREFIX call: &lt;http://webofcode.org/wfn/call&gt;
PREFIX afn: &lt;http://jena.hpl.hp.com/ARQ/function#&gt;.</p>
      <p>SELECT ?max {</p>
      <p>BIND( call:(wfn:reduce, afn:max, 5, 7, -1, 3) AS ?max)
}
resulting in ?max = 7.</p>
      <p>Compose. Another important HOF is the composition function. Given two
functions g and f , it returns a third function that behaves as the application of f
followed by the application of g, i.e., g(f (:)). The following query excerpt:
BIND(call:(wfn:compose, fn:upper-case, afn:namespace)
AS ?uppercase_ns).</p>
      <p>BIND(call:(?uppercase_ns, &lt;http://something.org/myentity&gt;) AS ?result)
returns the uppercased namespace, that is, HTTP://SOMETHING.ORG/. In
particular, variable ?uppercase_ns is binded to a dynamically generated sparql
function that, whenever invoked, applies afn:namespace followed by fn:upper-case.
Memoize. Many sparql queries may iterate over intermediate results,
requiring the execution of the same function multiple times, possibly with the same
paramenters. In order to speed up the execution of potentially time-consuming
functions, we implemented a memoization function that keeps the results of
function calls and then returns the cached result when the same inputs occur again.
This part of the query:</p>
      <p>
        BIND(call:(wfn:memoize, ?slow_function) AS ?fast_function).
BIND(call:(?fast_function, 1) AS ?result1). #1st time at normal speed
BIND(call:(?fast_function, 1) AS ?result2). #2nd time is faster
dynamically generates a ?fast_function that is the memoization of function
in ?slow_function. Please notice that this kind of useful features are possible
only in higher-order environments, such as the one resulting by the use of our
call function [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
3
      </p>
      <p>
        Bridging Web APIs and the Web of Functions
In order to develop a useful Web of Functions, the small set of auxiliary
functions presented in the previous section are clearly not enough. While some other
powerful user-de ned functions are already online (e.g., runSPARQL [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] computes
recursive sparql functions), we need a larger nucleus of functions allowing any
sort of computation from within sparql queries. In this section we propose the
exploitation of a well-known Web API hub, namely Mashape2, by using a simple
bridge function that allows to call any mashape-featured API. This function,
that we called wfn:api-bridge, pushes hundreds of Web APIs within the Web
of Functions, ranging from weather forecast to face detection, from language
translation to ight information lookup. For instance, we can iterate over
DBpedia cities in Tuscany nding those with a close airport, cheap ight and good
weather during the week after a given arrival day. In the following we nd large
Tuscany cities sorted by current weather temperature:
SELECT * {
?city dbpedia-owl:region dbpedia:Tuscany;
      </p>
      <p>dbpedia-owl:populationTotal ?population;
2 Freely available at http://www.mashape.com/</p>
      <p>FILTER(?population &gt; 80000).</p>
      <p>
        BIND(CONCAT("lat=",?lat,"&amp;lon=",?long) AS ?parameters)
BIND( call:(wfn:api-bridge, "community-open-weather-map", ?parameters,
"main.temp") as ?temperature).
} ORDER BY ?temperature
The wfn:api-bridge function calls the Mashape Web API corresponding to the
rst argument, with parameters speci ed in the second argument, then returning
the JSON eld selected in the third argument. Di erent APIs necessary to answer
the query can be combined together with compose, and the resulting function
may be memoized for better performance if needed. Advanced uses may exploit
Linked Data information to search through existing Web API repositories [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ].
4
      </p>
    </sec>
    <sec id="sec-3">
      <title>Conclusions and Demo Showcase</title>
      <p>We presented a set of sparql extensions containing higher-order manipulation
functions, allowing for instance function composition, together with a bridge
function that allows the use of hundreds of existing Web APIs from any sparql
endpoint featuring the wfn:call function, that we developed and opensourced
for Apache Jena. This set, forming an initial nucleus for the Web of Functions,
enables a wide spectrum of much powerful sparql queries w.r.t. the ones we are
currently used to, with a number of practical examples that will be showcased
during the demo and made available at our website.</p>
      <p>Acknowledgments. This work was supported in part by the RAS Project
CRP-17615 DENIS: Dataspaces Enhancing Next Internet in Sardinia and by
MIUR PRIN 2010-11 project Security Horizons.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Atzori</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          :
          <article-title>Toward the Web of Functions: Interoperable Higher-Order Functions in SPARQL</article-title>
          . In: 13th International Semantic Web Conference (Research Track). (
          <year>2014</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Auer</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Bizer</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kobilarov</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lehmann</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Cyganiak</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ives</surname>
            ,
            <given-names>Z.G.</given-names>
          </string-name>
          :
          <article-title>DBpedia: A Nucleus for a Web of Open Data</article-title>
          .
          <source>In: The Semantic Web, 6th International Semantic Web Conference, 2nd Asian Semantic Web Conference (ISWC/ASWC)</source>
          .
          <article-title>(</article-title>
          <year>2007</year>
          )
          <volume>722</volume>
          {
          <fpage>735</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Paulheim</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Hertling</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          :
          <article-title>Discoverability of SPARQL Endpoints in Linked Open Data</article-title>
          .
          <source>In: International Semantic Web Conference (Posters &amp; Demos)</source>
          . (
          <year>2013</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Alexander</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Cyganiak</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Hausenblas</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Zhao</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          :
          <article-title>Describing Linked Datasets with the VoID Vocabulary</article-title>
          (
          <year>December 2010</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Atzori</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          :
          <article-title>Computing Recursive SPARQL Queries</article-title>
          .
          <source>In: 8th IEEE International Conference on Semantic Computing</source>
          . (
          <year>2014</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Bianchini</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Antonellis</surname>
            ,
            <given-names>V.D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Melchiori</surname>
            ,
            <given-names>M.:</given-names>
          </string-name>
          <article-title>A Linked Data Perspective for Effective Exploration of Web APIs Repositories</article-title>
          .
          <source>In: ICWE</source>
          <year>2013</year>
          .
          <article-title>(</article-title>
          <year>2013</year>
          )
          <volume>506</volume>
          {
          <fpage>509</fpage>
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>