One Document to Bind Them

Harry Halpin, <H.Halpin@ed.ac.uk>

Henry S. Thompson, <ht@inf.ed.ac.uk>

Lambda

WWW2006, Edinburgh, May 2006

Introduction

A paradigm for uniting the diverse strands of XML-based Web technologies by allowing them to be incorporated within a single document.

XML without a description of its processing is not fully describing

By embedding the minimal number of constructs in XML we can extend XML into functional processing language, that uses the Semantic Web as a type system and can access Web Services.

Standard Confusion

Given the current plethora of XML-based standards and technologies, XML is being pulled in multiple directions: the Semantic Web, Web Services, and maintaining the good-old fashioned Web based on REST and HTML. - and then there's the Web 2.0...
the Web standard map

TimBL's Semantic Web Stack

The Semantic Web is getting more, not less complex. How does it connect to the rest of Web architecture? Processing models? TimBL's Semantic Web stack

The Web Services Stack

So many stacks to choose from!

WS Stack 1

The Web Services Stack.

WS Stack 2

The Web Services Stack..

WS Stack 3

The Web Services Stack...

WS Stack 4

Would the company with the game-plan in their closet please stand-up?

Gameplans

XML notes

The Web 2.0

Part of the Web 2.0 is about new Web-centric processing models, in particular taking advantage of standardized client-side browser programming languages (Javascript) and standardized data exchange via XML to build neat applications.

What's the processing model for XML?

[See Answer Here from XML Processing Working Group]

Back to Basics: XML

Is XML self-describing?

Tim Berners-Lee noted that XML documents are not self-describing since they do not provide a description of their preferred method of processing or their meaning.

Element and attribute names provide a hint as to their usage...

Every schema is a public agreement, and the details of this agreement are usually not described by the document itself or known to outside parties.

Is there hope?

Only formats like Atom, RSS, OPML (and non-XML ones like vCard) are well-understood by everybody on the Web since as the meaning and usage of microformats are well-known due to the clear and easily-accessible description of these formats and their widespread adoption.

Are all but the most popular of microformats doomed to be misunderstood?

Not without explicit semantics and self-describing processing

XML Pipeline Processing

Think back to UNIX pipeline
cat input.xml | xsv someschema.xsd 
   | saxon xhtmlout.xsl > output.xml  

The One Damn Thing After Another model

XPDL

Just give UNIX pipelines (minus complexities!) a simple XML-syntax: XPDL, XML Pipeline Definition Language.
 <param name="target" select="result"/>

  <process id="p2" type="transform">
    <input name="stylesheet" label="xhtmlout.xsl"/>
    <input name="document" label="valid"/>
    <output name="result" label="result"/>
  </process>

  <process id="p1" type="validate">
    <input name="document" label="input.xml"/>
    <input name="schema" label="someschema.xsd"/>
    <output name="psvi" label="valid"/>
  </process>
The processing instructions are outside the document itself, and so cannot take advantage of the natural compositionality of XML (trees).

Inside the XML Document

Thompson showed how you can put the processing instructions inside the XML document.
<page xmlns:fx="http://www.ltg.ed.ac.uk/~ht/functionalXML">
  <fx:transform xmlns:xi="http://www.w3.org/2001/XInclude"
              stylesheet="xmlhtmlout.xsl">
    <fx:validate schemaDocument="someschema.xsd">
      <document version="2.0">
        <head profile="http://www.w3.org/2003/g/data-view">
          <link rel="transformation"
            href="http://www.example.org/xml2rdf.xsl" />
        </head>
        <body>
          <title>Some Document</title>
            <author = "Brian Suda" />
          <title>
            My input data is below!
          </title>
          <data>
            The <b>data itself</b>!
          </data>
        </body>
      </document>
    </fx:validate>
  </fx:transform>

The Logic Behind FunctionalXML

Both XML pipelines and the simple functional expression thereof map onto finite state automata (FSA) that are guaranteed to terminate.

XML pipeline languages such Orbeon's XPL and NetKernel have already gone to the Turing-Complete stage.

No complex programming should be done in XML.

Pipelines are simple languages that encapsulate more complex processors.

A powerful but lightweight option that allows us to add processing components (not instructions) to the nodes of an XML document, and so make XML self-describing.

Variables and Control

Scoping via the use of a fx:let construct, and variables can be bound within a scope by a fx:bind construct. A name attribute of fx:bind can then be used to name the variable. Control structures can use a cond keyword to wrap case...else conditionals.
<fx:let xmlns:fx="http://www.ltg.ed.ac.uk/~ht/functionalXML">
  <fx:bind name="myvariable">
    <fx:include href="document.xml"/>
  </fx:bind>
  <fx:cond>
    <fx:case test="$myvariable/document/@version &gt; 1.0">
      <fx:transform stylesheet="xhtmlout.xsl">
         <fx:validate schemaDocument="someschema.xsd">
           <fx:include href="$myvariable"/>
         </fx:validate>
      </fx:transform>
    </fx:case>
  </fx:cond>
</fx:let>

XML Processors as Functions

Every processing component is a function from XML to XML.

We should be able to create functions and assign functions to variables.

  1. A fx:defun define functions.
  2. Binding functions to code and data via the use of a fx:lambda
  3. Grounding on the local machine via fx:processdef element.
  4. Arguments can then be given using the children of an fx:args element.
  5. Use fx:apply to run.

An Example:GRDDL

<fx:let xmlns:fx="http://www.ltg.ed.ac.uk/~ht/functionalXML">
  <fx:defun name="myGrddl">
    <fx:lambda>
      <fx:args>
        <fx:arg name="inputXML" />
      </fx:args>
      <fx:processdef grounding= "glean.py --output $stdout $inputXML"  />
    </fx:lambda>
  </fx:defun>   
  <fx:bind name="myvariable">
    <fx:validate schemaDocument="someschema.xsd">
      <fx:include href="document.xml"/>
    </fx:validate>
  </fx:bind> 
  <fx:cond>
    <fx:case test="$myvariable/head/link/@rel 
                  &eq; "transformation"">
       <fx:apply name="myGrddl"> 
         <fx:include href="$myvariable" /> 
       </fx:apply>
    </fx:case> 
 </fx:cond>
</fx:let>

Lisp for the Web

Evolution of language
(let ((myvariable "input.xml"))
  (cond ([$myvariable/document/@version > 1]
           (transform (validate myvariable "someschema.xsd") 
           "xhtmlout.xsl"))))

Web Services as Functions

It is too difficult to include the results of a Web Service directly into an XML document. Aren't Web Services just remote functions?
<fx:let>
  <fx:defun name="wsValidate">
    <fx:lambda> 
      <fx:args>
        <fx:arg name="inputXML" />
        <fx:arg name="schemaDocument" />
      </fx:args>
      <fx:restWebService
        location="http://www.example.org/SchemaValidator" />
     </fx:lambda>
  </fx:defun>
  <fx:transform stylesheet="xhtml.out">
    <fx:apply name="wsValidate"  schemaDocument="someschema.xsd">
      <fx:include href="input.xml"/>
    </fx:apply>
  </fx:transform>
</fx:let>
And why not have a soapWebService that helps abstract away from the WS stack?

RDF in the Document

The Semantic Web is a solution in need of a problem.

The problem of the hour for the Semantic Web is data integration.

So we can have a Semantic FunctionalXML where some functions map from infosets to triples.
  <document xmlns:sfx="http://www.ibiblio.org/hhalpin/sfXML"
             xmlns:fx="http://www.ltg.ed.ac.uk/~ht/functionalXML">
    <sfx:grddl>
      <fx:include href="neworder.xml" />
    </sfx:grddl>
    <fx:include href="bookdata.rdf" />
  </document>

RDF as a Typing System

If XML is data, then However, on the Web it may be important that a string is a firstName as in the first name of a person, and not just any string.

Explicitly model the world semantics of your data, not just give them data types.

World vs. Model
<fx:let xmlns:sfx="http://www.ibiblio.org/hhalpin/sfXML"
        xmlns:storeOnt="http://www.example.org/StoreOntology/"  >
  <sfx:bind name="myPerson" type="storeOnt:StoreCustomer">
         <fx:include href="customerOrder121.xml" />
  </sfx:bind>
</fx:let>

Semantic Web Services Made Simple

If the Semantic Web is open-world typing, and Web Services are functions available on the Web, then Semantic Web Services are typed functions for the Web.

Invoke Web Services not just by their URI, but by the type of information they output and input.

All we require is that WSDL inputs and outputs can be annotated with RDF - just like WSDL-SA.

Example

<body>
  <fx:let xmlns:fx="http://www.ibiblio.org/hhalpin/sfXML"
        xmlns:dirOnt="http://www.example.org/DirectionsOntology/">
    <sfx:bind name="myAddress" type="dirOnt:Address">
      <sfx:include href="myaddr.rdf"/>
    </sfx:bind> 
    <sfx:bind name="yourAddress" type="dirOnt:Address">
      <sfx:include href="your_addr.rdf"/>
    </sfx:bind>
    <h1>Welcome to My Web Page</h1>
    <p>The <b>directions</b> to my House are here:</p>
    <sfx:defun name="doDir">
      <sfx:lambda type="dirOnt:Directions">
        <sfx:args>
          <sfx:arg name="origin" type="dirOnt:Origin"/>
          <sfx:arg name="destination" type="dirOnt:Destination"/>
        </sfx:args>
      </sfx:lambda>
    </sfx:defun>
    <sfx:defun name="doMap">
      <sfx:lambda outputType="dirOnt:Map">
        <sfx:args>
          <sfx:arg name="address" type="dirOnt:Location"/>
        </sfx:args>
      </sfx:lambda>  
    </sfx:defun>
    <sfx:apply name="doDir" origin="$yourAddress" destination="$myAddress" />
    <p>You may find this <b>map</b> useful as well!</p>
    <sfx:apply name="doMap" address="$myAddress"/>
  </fx:let>
</body>

Proofs for Free

Curry-Howard Isomorphism = Proofs are Programs

Typed Functional Programming Languages = Intuitionistic Predicate Logic

Example Proof
<fx:let xmlns:fx="http://www.ltg.ed.ac.uk/~ht/functionalXML">
  <fx:bind name="myvariable">
    <fx:include href="document.xml"/>
  </fx:bind>
  <fx:cond>
    <fx:case test="$myvariable/document/@version &gt; 1.0">
      <fx:transform stylesheet="http://www.example.com/xhtmlout.xsd">
         <fx:authenticate stylesheet="http://www.me.com/key.gpg.asc">
           <fx:include href="$myvariable"/>
         </fx:authenticate>
      </fx:transform>
    </fx:case>
  </fx:cond>
</fx:let>

Related Work

Does not currently require OWL-S, WSMO, non-functional properties and so on . Does not do trust and automatic service composition - but can build on existing(?) solutions.

Sort of like a formally well-founded and low budget Semantic Web Service processing - but not for business processes.

Obviously related to functional programming and Lisp.

Lots of formal work to be done and implementation.

Turing's Promise

Typed Lambda Calculus = A model of computation

sfXML documents = Typed Lambda Calculus

A universal computer = the Web