OWLlink:
HTTP/S-Expression Binding

Working Draft October 2008

This version:
http://www.owllink.org/owllink-httpsexpr-20081001/
Latest version:
http://www.owllink.org/owllink-httpsexpr/
Authors:
Michael Wessel, Racer Systems GmbH & Co. KG
Contributers:
Thorsten Liebig, Ulm University
Marko Luther, DOCOMO Euro-Labs Munich
Ralf Möller, TU Hamburg
Olaf Noppens, Ulm University

Abstract

This document defines a concrete binding of [OWLlink] into [HTTP/1.1] and [Common Lisp S-Expressions]. It is strongly coupled to the [HTTP/XML binding of OWLlink] and is intended for Common Lisp developers who are looking for an alternative binding which does not put the high burden on the implementor's shoulders of requiring an XML processing framework in order to parse, process and construct OWLlink messages. The basic idea of this binding is that the Common Lisp function read is, in combination with an Common Lisp HTTP framework, sufficient to construct Common Lisp representations of OWLlink messages from an HTTP stream. The binding is thought of as being automatically consistent and "in sync" with the primary [HTTP/XML binding of OWLlink.] Thus, whenever the HTTP/XML binding is updated, the HTTP/S-Expression binding is affected as well. Rather than specifying the concrete syntax of the concrete S-Expression messages in this document (which would be subject to change in future versions) we specify a simple translation function that maps OWLlink HTTP/XML messages to HTTP/S-Expression messages instead.

Status of this Document

May Be Superseded

This version of the OWLlink structural specification refers to the public OWL 2 working draft as of April 11th 2008 (http://www.w3.org/TR/2008/WD-owl2-syntax-20080411/) and will soon be superseded by an updated specification in order to align with the latest OWL 2 working draft or recommendation.

Please Comment

The OWLlink Working Group seeks public feedback on these Working Drafts. Please send your comments to public-comments@owllink.org or post to the public discussion forum at http://www.owllink.org/forum/.


Contents


1 Introduction

OWLlink is defined in terms of a structural specification [OWLlink Structural Specification]. This document describes a binding of the specification to a concrete communication protocol, namely [Common Lisp S-Expressions] over [HTTP]. Note that this is only one conceivable binding. The primary OWLlink binding utilizes [XML over HTTP]. The HTTP/S-Expression binding provided here is thought of a being automatically kept up-to-date and "in sync" with the HTTP/XML binding. This is achieved by giving a translation function which generates Common Lisp S-Expressions from arbitrary OWLlink HTTP/XML messages.

As the HTTP/XML binding, the HTTP/S-Expression binding of OWLlink uses HTTP as its underlying communication protocol for exchanging S-Expressions between a reasoner and a client. More technically, the reasoner has to accept HTTP POST requests and responds as appropriate according to the OWLlink specification. The details of the HTTP transport are specified in the [OWLlink HTTP/XML binding] and apply to this document as well.

The requests as well as the responses have to consist of S-Expressions according to this specification. The basic idea is that the standard Common Lisp function read can be used to construct internal Common Lisp representations of OWLlink messages in terms of Common Lisp data structures (i.e., lists) which can then easily be processed further by a Common Lisp program. Thus, no XML parser is required. However, a Common Lisp HTTP framework is required. In order to construct a Common Lisp representation (as a Common Lisp data structure) of an OWLlink message (according to this binding) the standard Common Lisp function read is called on the HTTP stream. The read function accepts so-called S-Expressions. Details of the transport, such as character encoding etc., are left to the HTTP protocol, as in the HTTP/XML binding of OWLlink.

To get the basic idea of the translation, consider the following OWLlink message in the HTTP/XML binding:

    <Tell ol:kb="KB_1">
        <ox:SubClassOf>
            <ox:OWLClass ox:URI="B"/>
            <ox:OWLClass ox:URI="A"/>
        </ox:SubClassOf>
    </Tell>

The same message takes the following form in the HTTP/S-Expression binding:

(Tell (#@ol:kb "KB_1")
        (#!ox:SubClassOf () 
	 (#!ox:OWLClass (#@ox:URI "B"))
	 (#!ox:OWLClass (#@ox:URI "A"))
      )
)

The details of this mechanical translation are given in the next section. Thus, the set of well-formed HTTP/S-Expression OWLlink messages is specified as the set of well-formed HTTP/XML OWLlink messages on which the translation function has been applied.

The S-Expressions produced in that way are still somewhat verbose and thus not very friendly for human-machine communication. The OWL 2 functional syntax as specified in the [OWL 2 Specification] is much more compact and has a better human readability. It should thus be possible to exploit the benefits of this syntax for the S-Expression binding as well. The OWL 2 functional syntax for the SubClass axiom given above is SubClassOf(B A), as specified in the [OWL 2 Specification]. This directly corresponds to the S-Expression (SubClassOf B A). In the following, this syntax is called the OWL 2 functional S-Expression syntax. An expression in OWL 2 functional syntax ("term syntax") can easily be brought into OWL 2 functional S-Expression syntax simply by exchanging f(...) (where f is some "functor") with (f ...). W.r.t. the example, the tell message thus takes the following less verbose form in the alternative rendering:

(Tell (#@ol:kb "KB_1")
        (#!owl2:SubClassOf B A))

This rendering also has the benefit that implementors can easily reuse their OWL 2 parser for functional syntax in order to parse the content of tell messages (axioms).

Thus, within tell, there are two options regarding axiom syntax, since an axiom is either acceptable in OWL 2 functional S-Expression syntax, or in the S-Expression syntax derived by applying the translation function (to be specified in the next section) to the HTTP/XML rendering of that axiom.

Please note that the message formats of ask messages is fixed and thus independent of the axiom syntax which was used for telling the axiom. E.g., the response to the

(GetAllClasses :kb "KB_1")
message is
(SetOfClasses 
   (#!ox:OWLClass (#@ox:URI "A"))
   (#!ox:OWLClass (#@ox:URI "B"))
)

in both cases.

2 Binding - Specification of the Translation

Reconsidering the tell example message given above, the general translation schema for OWLlink messages rendered in the HTTP/XML binding to OWLlink messages rendered in the HTTP/S-Expression binding can be defined as follows. Such a message is referred to as an OWLlink S-Expression message in the following:

This translation applies to all XML/HTTP OWLlink messages, no matter whether they are messages of type RequestMessage or ResponseMessage.

Please also notice that XML CDATA sections, XML Comments, XML Processing Instructions, and the XML Declaration are not translated by the translation function just specified. These XML peculiarities are thus simply ignored (and thus skipped).

3 Simplified Syntax for Response Messages

Often, a less verbose message and more "Lisp-like" format of the ResponseMessage is desired. For this purpose, the :simple-answer "true"t attribute-value pair can be specified as an additional argument to the RequestMessage. The content in the corresponding answer ResponseMessage will benefit from a simplified rendering then. This simplification can be specified as follows: Reconsidering the request from the Introduction
(RequestMessage ()
  (GetAllClasses :kb "KB_1")
)
which returns
(ResponseMessage ()
 (SetOfClasses 
   (#!ox:OWLClass (#@ox:URI "A"))
   (#!ox:OWLClass (#@ox:URI "B"))
 )
)
thus produces the simplified response message
(ResponseMessage (:namespaces ((nil "http://www.w3.org/2006/12/owl2")))
 (OWLClass A)
 (OWLClass B)
)
if (GetAllClasses :kb "KB_1" :simple-answer "true") is submitted.

4 Examples

To be written.

5 Implementation Hints

Finally, let us briefly comment on the implementation of a simple mini parser in Common Lisp that can parse the given example message

(Tell (#@ol:kb "KB_1")
        (#!ox:SubClassOf () 
	 (#!ox:OWLClass (#@ox:URI "B"))
	 (#!ox:OWLClass (#@ox:URI "A"))
      )
)

We are using Common Lisp macro characters to map the #@ and #! to symbols with appropriate namespace prefixes (alternative approaches are possible, e.g., Common Lisp packages could be used for XML namespaces):

(defvar *current-namespace-prefixes* 
  '(("ox" "http://www.w3.org/ns/owl2-xml")
    ("ol" "http://www.owllink.org/owllink-ext-xml")))

(defun the-reader (stream subchar arg)
  (declare (ignorable subchar arg))
  (let* ((prefix 
          (coerce 
           (loop as 
                 x = (read-char stream nil)
                 while (and x (not (char-equal x #\:)))
                 collect x)
           'string))
         (resource 
          (let ((old-case 
                 (readtable-case *readtable*)))
            (unwind-protect
                (progn (setf (readtable-case *readtable*) :preserve)
                  (let ((char (peek-char nil stream nil)))
                    (when (and char 
                               (not (lw:whitespace-char-p char))
                               (not (char= char #\))))
                      (read stream))))
              (setf (readtable-case *readtable*) old-case))))
         (namespace (if (string= prefix "")
                        "http://www.owllink.org/owllink-ext-xml"
                      (second (assoc prefix *current-namespace-prefixes*
                                     :test #'string-equal)))))

    (if resource
        (if namespace
            (intern (format nil "~A#~A" namespace resource))
          (intern (format nil "~A" resource)))
      (if namespace
          (intern (format nil "~A" namespace))
        nil))))

(defun element-name-reader (&rest args)
  (apply #'the-reader args))

(defun attribute-name-reader (&rest args)
  (let ((*package* (find-package :keyword)))
    (apply #'the-reader args))) 
 
(set-dispatch-macro-character #\# #\! 'element-name-reader)

(set-dispatch-macro-character #\# #\@ 'attribute-name-reader)

Now we can implement the parsers for ol:tell and ox:class messages as simple macros. Their only purpose is to print out some messages on standard output during parsing. In a real implementation these macros will create Common Lisp data structures or directly call constructor functions in order to represent the axioms:

(defmacro #!:Tell ((&rest args &key #!:kb) &body body)
  (declare (ignorable args))
  `(progn
     (format t "~%Tell for KB ~A" ,#!:kb)
     ,@body))

(defmacro #!ox:SubClassOf ((&rest args) &body body)
  (declare (ignorable args))
  `(progn 
     (format t "~%SubClassOf")
     ,@body))

(defmacro #!ox:OWLClass ((&rest args &key #!ox:URI) &body body)
  (declare (ignorable args))
  `(progn 
     (format t "~%OWLClass ~A" ,#!ox:URI)
     ,@body))

In general, OWLlink S-Expressions will be loaded from an HTTP stream maintained by a Common Lisp HTTP framework. We use a simple string stream in this example for demonstration purposes. It is assumed that the HTTP framework has dealt with issues such as content compression, character encoding, etc. With the given definitions above, evaluation of

(with-input-from-string (stream
   "(#!:Tell (#@ol:kb \"KB_1\")
       (#!ox:SubClassOf ()
           (#!ox:OWLClass (#@ox:URI \"B\"))
           (#!ox:OWLClass (#@ox:URI \"A\"))))")
  (load stream))

produces the output:

Tell for KB KB_1
SubClassOf
OWLClass B
OWLClass A

6 References

[CLtL2]
Common Lisp the Language, 2nd Edition by Guy L. Steele et al., Thinking Machines, Inc., Digital Press, 1990, http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/clm.html.
[OWLlink HTTP/XML Binding]
OWLlink: HTTP/XML Binding. Sean Bechhofer, Thorsten Liebig, Marko Luther, Olaf Noppens. Working Draft, October 2008, http://www.owllink.org/owllink-httpxml-20081001/. Latest version available at http://www.owllink.org/owllink-httpxml/.
[OWLlink Structural Specification]
OWLlink: Structural Specification. Thorsten Liebig, Marko Luther, Olaf Noppens. Working Draft, October 2008, http://www.owllink.org/owllink-20081001/. Latest version available at http://www.owllink.org/owllink/.
[OWL 2 Specification]
OWL 2 Web Ontology Language:Structural Specification and Functional-Style Syntax Boris Motik, Peter F. Patel-Schneider, Bijan Parsia, eds. W3C Working Draft, 08 October 2008, http://www.w3.org/TR/2008/WD-owl2-syntax-20081008/. Latest version available at http://www.w3.org/TR/owl2-syntax/.
[HTTP/1.1]
Hypertext Transfer Protocol — HTTP/1.1, Request for Comments 2616. R. Fielding, J. Gettys, J. Mogul, H. Frystyk, L. Masinter, P. Leach, and T. Berners-Lee.