SWCLOS: A Semantic Web Reasoner on CLOS

RDF Subsystem

This subsystem provides the tools for RDF/XML parser. After loading this module, load the RDFS module to clasify things in RDFS semantics.



File RDF\Utils.cl

Utilities for SWCLOS and Rbase from AIMA and others

Utilities in this file are taken from AIMA and redefined in package gx.


mkatom x [function]

If x is an atom, return it; otherwise if one length list, return the element, else returns x

mklist x [function]

If x is a list, return it; otherwise return a singleton list, (x).

mappend fn &rest lists [function]

Apply fn to respective elements of list(s), and append results.

set-equalp x y [function]

returns true if x and y is equal as set, the test function is equalp.

set-eq x y [function]

returns true if x and y is equal as set, the test function is eq.

length>1 list [function]

Is this a list of 2 or more elements?

length=1 list [function]

Is this a list of exactly one element?

length=2 list [function]

Is this a list of exactly two elements?

starts-with list element [function]

Is this a list that starts with the given element?

last1 list [function]

Return the last element of a list.

last2 lst [function]

Return the last two element of a list.

reuse-cons x y x-y [function]

Return (cons x y), or reuse x-y if it is equal to (cons x y)

Delay Evaluation from OnLisp

Delay mechanism is copied from ``On Lisp'' by Paul Graham.

unforced [constant]

delay forced closure [type]

delay expr [macro]

force x [function]

delay-role-p role [function]

set-delay-role role [function]

And Others, from Winston's Lisp.

squash x [function]

flattens a nested list x and returns a list that includes only atoms.

String Pattern

match source target &optional start [function]

compares source string to target string starting start in target. and all characters in source are matched to target in order, returns true.

substitute-pattern new old sequence &key start [function]

duplicate-p list &key test key [function]

null-string-p str [function]

Seiji Koide Nov-15-2010


File RDF\RdfIO.cl

Rdf I/O module

IT Program Project in Japan: Building Operation-Support System for Large-scale System using IT.

This code was encoded by Seiji Koide at Galaxy Express Corporation, Japan, for the realization of the MEXT IT Program in Japan.

Copyright (c) 2002, 2004 Galaxy Express Corporation
Copyright (c) 2007, 2008, 2010 Seiji Koide


The line number of input stream is counted and used in error messages.

*line-number* [variable]

line number, starting from one, zero is just a flag that indicates no RDF/XML parser input.

*line-pos* [variable]

current line position, starting from zero

*pos* [variable]

current position, starting from zero

line-count stream [function]

RDF input functions are hidden from user's view.

To parsing XML documents, dedicated input functions are developed. The motivation of this development is as follows. The transition machine is usually modeled for parsing the syntax of languages. However, the expression of the syntax specification of a particular language and the transition machine for the language is very different and difficult to imagine one to another. On the other hand, Ratfor and C (maybe) language need only one character peeking to parse them. Generally, any number of peeking allows us to parse any context free language. For XML parsing, in the experience, nine peeking characters is enough to parse XML for "<![CDATA[", maybe.

These special functions allow programmers to peek any numbers of characters in the stream. These functions are very useful to parse XML documents without state transition mechanism. We can decide what kind of data comes up next by peeking a number of characters.

If you want to show what characters remain in the buffer, use the command expose-buf without parameters. The buffer has two pointers to the start and the end of sequence of characters.


assert-pattern pattern stream [function]

asserts that input from stream matches to pattern. pattern is a string. This function eats up all characters that equal to pattern. In case of mismatch, an error occurs.

read-quoted-string stream [function]

reads a quoted string from stream.

parse-pattern-delimited-string pattern stream [function]

reads input character from stream until the occurence of pattern and returns it as string. pattern is not eaten. one character at least should stand before pattern.

Seiji Koide Sep-13-2008


File RDF\IRI.cl

IRI module

IRI in SWCLOS and Rbase system

Every uri for RDF is globally unique in the WWW. Therefore, a uri in SWCLOS must be unique. The uniqueness of uri is assured by interning a uri.

A triple subject/predicate/object in RDF is embodied as CLOSobject/slotname/slotvalue in SWCLOS, and subjective CLOSobject is bound to the subjective uri. Precisely, a subjective uri is an instance of class iri in SWCLOS and Rbase that is subclass of net.uri:uri in ACL library.

Read macro `<' reads a uri string and produces an iri. A uri reference is internalized to an instance of class iri. An instance of class iri is externalized (printed by `%W') as the same appearance of input uri data.


 <http://www.w3.org/2000/01/rdf-schema#Resource>    -> 
                                   <http://www.w3.org/2000/01/rdf-schema#Resource>
 rdfs:Resource (if defined as node)                 -> rdfs:Resource
 (eq <http://somewhere> <http://somewhere>)         -> true
 (eq <http://some%20where> <http://some%20where>)   -> true
 (eq <http://somewhere> <http://some%20where>)      -> false

An instance of iri has an extra slot for value just like QName. iri-boundp and iri-value is available for an iri just like boundp and symbol-value.

Two trailing characters '<<' returns a value bound to the iri. See, reader macro gx::double-angle-bracket-reader.

iri [class]

iri in SWCLOS and Rbase that is a subclass of net.uri:uri and able to bind a value to, just like lisp symbol.

print-object (iri iri) stream [method]

iri-boundp x [function]

Is x a uri and bound at its value slot?

iri-value (str string) [method]

returns bound value of iri value from str.

%iri-value uri [macro]

This macro should be used by programmers, when uri is definitely uri here.

iri-p x [function]

Is x an instance of iri?

IRI Escaping

See, rfc2396 for URI escaping

iri-reserved-char-p char [function]

Is this char reserved for iri?

iri-marked-char-p char [function]

Is this char marked for iri?

iri-delimiter-p char [function]

iri-unwise-p char [function]

iri-escape str [function]

This function performs Percent-Encoding. Namely, RESERVED CHARACTERS, DELIMITERS, and UNWISE CHARACTERS for URI that is contained in str are escaped with percent(%) character to a triplet of % HEXDIG HEXDIG>. Spaces and newlines are removed from .

%iri-escape-for-delimiter str [function]

escapes uri delimiter char in str before making uri.

%iri-escape str [function]

encodes the uri reserved characters to hexadecimals.

iri-de-escape str [function]

This function decodes Percent-Encoding to characters.

URI APIs fixes

null-iri-p uri [function]

returns true if uri is nil, null string, or uri is a uri and its rendered string is null.

IRI Methods

Three methods are defined for generic function iri: when thing is a iri (instance of class iri), its interned value is returned. When thing is a string, intern-uri is applied to create a interned uri from the string.

A uri is always interned for a given uri string, because the uniqueness is required for uri to be bound to a value. This notion is the same as lisp symbol.

iri (thing iri) [method]

returns interned thing for class gx:iri.

iri (thing uri) [method]

change class net.uri:uri of thing to iri and returns interned thing.

See also, <a href='http://www.franz.com/support/documentation/8.1/doc/operators/uri/parse-uri.htm>parse-uri'</a> in ACL document.

iri (thing string) [method]

when iri host exists but no iri path on the iri in thing, this method adds '/' to iri path. This is required for the namespace interning.

iri (thing t) [method]

signals an error.

To list all iris for resource, call list-all-entity-uris. See gxutils module.

Seiji Koide Nov-15-2010


File RDF\packages.cl

Packages in RDFS System

This module defines basic symbols in xml, xsd, rdf, rdfs, and owl package. Those symbols are exported so as to be QNames.


File RDF\Xml.cl

XML 1.1

IT Program Project in Japan: Building Operation-Support System for Large-scale System using IT

This code was encoded by Seiji Koide at Galaxy Express Corporation, Japan, for the realization of the MEXT IT Program in Japan.

Copyright (c) 2002, 2003, 2004 Galaxy Express Corporation
Copyright (c) 2007, 2008, 2010 Seiji Koide

This file provides xml and xsd name space, and xsd datatypes in lisp. The data types as resource objects that wrap lisp data are defined in RdfsKernel and RdfsCore file.


XML Built-in Datatypes


Followings shows xsd type subtype relation, cf. http://www.w3.org/TR/2001/REC-xmlschema-2-20010502.

 xsd:anySimpleType
       |
       +- xsd:boolean
       +-xsd:anyURI
       +-xsd:string
       +-xsd:float
       +-xsd:double
       +-xsd:decimal -+- xsd:integer +- xsd:long -- xsd:int -- xsd:short -- xsd:byte
                                     +-xsd:nonPositiveInteger -- xsd:negativeInteger
                                     +-xsd:nonNegativeInteger --+
                                                                |
       +--------------------------------------------------------+
       +-- xsd:positiveInteger
       +-- xsd:unsignedLong - xsd:unsignedInt - xsd:unsignedShort - xsd:unsignedByte

Note that type hierarchy of number in Lisp is as follows.


 cl:number -+- cl:real -+- cl:rational -+- cl:integer -+- cl:bignum
            |           |               |              +- cl:fixnum -- cl:bit
            |           |               +- cl:ratio
            |           |
            |           +- cl:float -+- cl:short-float
            |                        +- cl:single-float
            |                        +- cl:double-float
            |                        +- cl:long-float
            +- cl:complex

In Lisp, an input token is internalized to a lisp object in read process of REPL. For instance, a token that eveloped by double quotations is converted to a lisp string object typed to cl:string. A token '1' is converted to an object of lisp typed to cl:fixnum. A greater number expression than most-positive-fixnum in lisp is internalized to an object typed to cl:bignum. In RDF semantics, a string and integer denotes itself in the RDF universe like lisp. Note that RDF semantics does not have the notion of internalization and externalization. We mapped the denotation of plane literal of rdf:Literal to internalized data object in lisp, and the denotation of xsd typed data to an instance object of xsd datatype. Note also that Java provides automatic data conversion between raw data and wrapped object data (boxing and unboxing). In SWCLOS, the function value-of is used to get internalized lisp data from wrapping xsd object.

Mapping from Common Lisp Datatypes to RDF Datatypes

There is no complex number in xsd. Therefore, we ignore cl:complex.


The mapping of xsd:decimal is not straightforward. It may be lexically expressed by an integer, or any number of decimal digits with a point and succeeding any number of fractional digits. If the number of digits is finite (it is so in practice), the xsd:decimal value range is included in cl:rational? in Common Lisp. If the number of digits could be infinite, the xsd:decimal value range is equivalent to cl:rational. Therefore, xsd:decimal is mapped to cl:rational. However, lisp internalizes simple input number expressions of digits with a point to an appropriate cannonical value, e.g., bignum or float. Then, you need to explicitly designate a rational value like ``(rational nnn.mmm)'' if you want to set it as type xsd:decimal instead of xsd:float. Note also a float number has a limit for the precision. See the followings.

 cg-user(22): 1000000.1
 1000000.1
 cg-user(23): 100000000.1
 1.0e+8
 cg-user(24): (rational 1000000.1)
 8000001/8
 cg-user(25): (rational 100000000.1)
 100000000

The followings are examples of xsd data types. All of following forms return true.


 (cl:typep 1 'xsd:positiveInteger)
 (cl:typep -1 'xsd:negativeInteger)
 (cl:typep 0 'xsd:nonNegativeInteger)
 (cl:typep 0 'xsd:nonPositiveInteger)
 (cl:typep 32767 'xsd:short)
 (cl:typep 32768 'xsd:int)
 (cl:typep 2147483647 'xsd:int)
 (cl:typep 2147483648 'xsd:long)
 (cl:typep 9223372036854775807 'xsd:long)
 (cl:typep 9223372036854775808 'xsd:integer)
 (cl:typep 1 'xsd:decimal)
 (cl:typep 1.0e0 'xsd:float)
 (cl:typep 1.0d0 'xsd:double)
 (cl:typep (rational 1) 'xsd:decimal)
 (cl:typep (rational 0.000001) 'xsd:decimal)
 (cl:typep 0.000001 'xsd:float)
 (cl:typep "string?" 'xsd:string)
 (cl:typep (iri "http://somewhere") 'xsd:anyURI)
 (cl:typep 'xsd:false 'xsd:boolean)

See also function type-of in GxType module. See also GxType module with respect to the lexical space representation. See also disjoint-p on the discussion on disjointness of xsd datatypes.

unsignedByte [type]

0 <= x <= 255

unsignedShort [type]

0 <= x <= 65535

unsignedInt [type]

0 <= x <= 4294967295

unsignedLong [type]

0 <= x <= 18446744073709551615

byte [type]

-128 <= x <= 127

short [type]

-32768 <= x <= 32767

int [type]

-2147483648 <= x <= 2147483647

long [type]

-9223372036854775808 <= x <= 9223372036854775807

integer [type]

any number of digits without point but with or without + or -

positiveInteger [type]

integer greater than 0

nonPositiveInteger [type]

integer smaller than 1

negativeInteger [type]

integer smaller than 0

nonNegativeInteger [type]

integer greater than -1

float [type]

floating point number in lisp

double [type]

double floating point number in lisp

decimal [type]

rational number in lisp, which should be revised in future.

string [type]

string in lisp

boolean [type]

xsd:true or xsd:false

anyURI [type]

net.uri:rui in ACL

anySimpleType [type]

xsd:boolean, xsd:anyURI, xsd:string, xsd:float, xsd:double, or xsd:decimal

Seiji Koide Sep-11-2008


File RDF\rdferror.cl

Condition and Error Handling module

This code is written by Seiji Koide.
Copyright (c) 2007 Seiji Koide


*all-quiet* [variable]

*saved-warnings* [variable]

quiet-warning-handler c [function]

with-quiet-warnings &body forms [macro]

*undo* [variable]

*undo-stack* [variable]

*undoed-operations* [variable]

undoable-by-domain-condition-handler condition [function]

with-undoable &body forms [macro]

Undoable Objects and Classes

undoable-metaclass [class]

undoable-class [class]

shared-initialize (instance undoable-class) slot-names &rest initargs [method]


File RDF\NameSpace.cl

NameSpace module

IT Program Project in Japan: Building Operation-Support System for Large-scale System using IT

This module is separated from RDFShare module for more efficient modularity.

Copyright (c) 2002, 2004 by Galaxy Express Corporation

Copyright (c) 2007, 2008, 2010 Seiji Koide


URI in SWCLOS and Turtle System

URI APIs fixes

Note that method gx:iri always interns thing, but gx:parse-iri does not intern it.

parse-iri thing &rest args [function]

when uri host exists but no uri path on thing, this method adds '/' to uri path. This is required for the namespace interning. See also, a href='http://www.franz.com/support/documentation/8.1/doc/operators/uri/parse-uri.htm'parse-uri/a in ACL document.

OntologySpace and NameSpaces

XML namespaces provide a simple method for qualifying element and attribute names in XML documents by associating them with URI references that provides namespaces for the names. QNames are used for element names instead of URIs, and NSAttNames are used for namespace declaration. See the details in <http://www.w3.org/TR/xml-names/>.

A QName consists of Prefix and LocalPart. The Prefix is associated to a namespace URI, QNames that share the same Prefix belong to the namespace, and the uniqueness of a LocalPart in the namespace supports the global uniqueness of QName in the WWW. This machinery is very similar to interning mechanism of lisp symbol in package, which consists of a symbol name and package, where a symbol name is unique in the package. Thus, the QName is implemented as exported lisp symbol, and the namespace is implemented as lisp package. The packages for QNames are associated to the mamesapce URIs.

In most cases, the mapping from a uri to a QName is algorithmically decidable. However, there may be cases that system cannot decide how a uri should be mapped to a QName. In such a case, a user must provide the mapping rule or the function giving each mapping by replying the query from system one by one. Therefore, we need a maintenance device to keep irregular mapping for such cases. All name spaces that related to XML namespace URIs are installed into global variable *NameSpaces*.

*NameSpaces* [variable]

hasharray where a uri part associated to Prefix is interned. This space ensures the uniqueness of a Prefix associated uri by interning it. See make-uri-space in Allegro Common Lisp documentation.

All namespaces in system are listed by list-all-uri-namedspaces. See gxutil module.

A vocabulary URI in a namespace may be converted to a corresponding QName, in which a Prefix part is associated to the namespace URI, and a LocalPart is assocated to the vocabulary in the namespace. The namespace on Prefix can be shared among URIs that have the same Prefix so that LocalPart has a unique entry in the namedspace on Prefix. This machinery is very similar to interning mechanism of lisp symbol in package, which consists of a symbol name and package, where a symbol name is unique in the package. Thus, the QName is implemented as exported lisp symbol, and the namespace is implemented as lisp package.

uri-namedspace is a subclass of net.uri:uri which has two extra slots, package and env. package value keeps a package associated to a URI namespace. In case of regular mapping from URIs to QNames, no device for mapping from a local part of URI to a symbol name is needed, because SWCLOS provides such regular mapping. However, in case of irregular mapping, the mapping from a full URI to a LocalPart in the namespace or a full URI to a symbol name in the package is needed. This book-keeping is done for irregular mapping in the environment slot of uri-namedspace. Followings provide such a mapping device and the uri namespace functionality.

uri-namedspace [class]

A subclass of net.uri:uri. This instance has extra two slots, i.e., an associated symbol package slot and uri to symbol name mapping environment slot.

set-uri-namedspace prefix-uri [function]

after interning prefix-uri to *NameSpaces*, change the class of prefix-uri from net.uri:uri to uri-namedspace. After that, symbol to uri mapping can be placed in this namespace.

get-uri-namedspace prefix-uri [function]

retrieves a uri-namedspace on prefix-uri from *NameSpaces* by interning it.

set-uri-namedspace-from-pkg pkg [function]

supposing pkg has a documentation that is the same string as rendered prefix-uri, sets the prefix-uri as uri-namedspace, and puts this pkg into uri-namedspace-package slot.

uri2package prefix-uri [function]

returns a package associated to prefix-uri.

uri2env prefix-uri [function]

returns a LocalPart-symbol-name association list from prefix-uri. Note that the return value is null if there is no irregular mapping from uri to QName and no mapping given by replying a query.

The first thing to be done is, in spite that whether the mapping is regular or irregular, to divide a uri into a Prefix part and a LocalPart part. In regular mapping, a full URI with fragment is parted into a fragmentless URI and a fragment. The fragmentless URI is associated to Prefix of QName or package in lisp, and the fragment turns out a LocalPart of QName or symbol name in lisp.

For a URI without fragment, a function bound to global variable *uri2symbol-name-mapping-fun* and *uri2symbol-package-mapping-fun* are invoked if the system requires a corresponding QName or a package for a URI. Users can bind their own functions to these variables in order to apply to application oriented irregular mappings. However, two functions default-uri2symbol-name-mapping-fun and default-uri2symbol-package-mapping-fun are bound as default. See default-uri2symbol-name-mapping-fun and %%uri2symbol for the details.

*uri2symbol-name-mapping-fun* [variable]

a function to be invoked when uri to symbol name mapping is irregular.

*uri2symbol-package-mapping-fun* [variable]

a function to be invoked when uri to symbol package mapping is irregular.

uri2symbol uri [function]

transforms uri to a QName symbol. If irregular mapping has been established, the mapping is reused. When uri is a string, recursively calls with uri of uri. If uri is regular, namely a uri with fragment, %uri2symbol is used, else irregular-name&pkg is used. When uri is nil, nil is returned.

%uri2symbol uri [function]

in case of uri with fragment, mapping is regular. Then, uri without fragment is Prefix part and fragment of uri is LocalPart part of uri. This function returns the QName of uri without consulting the LocalPart environment in . its namespace. If there is no package information on uri without fragment part, a function bound to *uri2symbol-package-mapping-fun* is invoked. Note that uri-namedspace-env is unused in this regular case. Note that QName symbol is automatically exported in this function.

irregular-name&pkg uri [function]

when the mapping is irregular, this function is called. Firstly, a function bound to *uri2symbol-name-mapping-fun* is invoked with uri argument. If it gives a symbol then the symbol is returned. If it gives a string, the string is used as symbol name in a package that is obtained from uri through uri2package or from a function bound to *uri2symbol-package-mapping-fun*. When the package is newly obtained from *uri2symbol-package-mapping-fun*, the package is associated this uri itself. Then, in the worst case, each irregular uri has its own namespace, as system cannot know general rules from one by one Q&A. You had better provide a smarter application-oriented function on *uri2symbol-name-mapping-fun* that provides always an appropriate QName.

Mapping URI to package and symbol, ID to symbol, anonymousID to symbol

Query for Users

ask-user-for-string prompt string1 option1 option2 prompt2 [function]

This function is used in ask-user-package-name and ask-user-symbol-name.

default-uri2symbol-package-mapping-fun uri [function]

This function is bound to *uri2symbol-name-mapping-fun* as default. This function just makes a query for users.

default-uri2symbol-name-mapping-fun uri [function]

This function is bound to *uri2symbol-package-mapping-fun* as default. If uri has a uri path, then the returned value of %%uri2symbol is returned. Othewise a query is made for users.

%%uri2symbol uri [function]

Even if uri has no fragment, plausible separation is done by this function. In short, the file name or the most subfolder of uri path is taken as symbol name, and the remaining part of uri path is taken for namespace (package) association. If you can find some application specific rules for making QName, you had better program it as well as this function does.

Note that PrefixedAttName declaration in XML documents set the namespace with NCname (Prefix) and property value (associated prefix-uri). Note that DefaultAttName declaration in XML documents set the default namespace. See Rdf module.

*default-namespace* [variable]

Default name space URI for XML parsing in current time. This value is set by read-rdf-from-http and read-rdf-file.

*base-uri* [variable]

Base URI that is indicated in XML file. This value is set by read-rdf-from-http, read-rdf-file, and read-rdf-from-string.

QName2PrefixedName QName [function]

transforms QName to PrefixedName string. QName should be a lisp symbol.

QName2UnPrefixedName QName [function]

transforms QName to UnPrefixedName string. QName should be a lisp symbol.

export-as-QName symbol [function]

export this symbol as QName. The symbol-package of symbol is stored into the related uri namespace.

QNameString2symbol QName [function]

transforms QName string to a lisp symbol.

symbol2QNameString symbol [function]

transforms symbol to QName string in the current namespace.

Symbol to URI

symbol2uri symbol [function]

transforms symbol to its associated uri. The symbol package affects. The namespace uri should has been registered and documented in package.

NodeID

A nodeID is an exorted symbol in package "_". See the following example.


 (nodeID2symbol "abc")      -> _:abc
 (make-unique-nodeID "abc") -> _:abc0

nodeID? name [function]

Is this name a nodeID?

nodeID2symbol str [function]

simply transforms str to a exported symbol in anonymous node package :_ and returns it.

make-unique-nodeID str [function]

makes a unique node ID from str. Namely, adds numbers at the end of str and makes unique symbol.

name-ontology ontouri [function]

transforms ontouri to special symbol of which string is equal to ontouri.

Seiji Koide Nov-15-2010


File RDF\Literal.cl

Literal in Rbase System

Plane Literal

A plane literal without language tag is internalized to string in lisp. A plane literal with language tag is internalized to an instance of class rdf:inLang.

lang? x [function]

x is 2-letter language code as keyword symbol, e.g., :ja for Japanese, :en for English. See http://www.loc.gov/standards/iso639-2/php/code_list.php, but :en-US also accepted.

Plane Literal with Lang

A Lang object has lang and content. It is print out such as "Vine@fr".

inLang [class]

print-object (object inLang) stream [method]

equals (obj1 inLang) (obj2 inLang) [method]

Two plane literal with lang are equal if langs are equal and contents are equal.

@ content lang [function]

returns an instance of rdf:inLang structure. content must be a string. the string of lang may be any string or symbol and it must designate language tag.

File RDF\RDFShare.cl

Rdf Share module

IT Program Project in Japan: Building Operation-Support System for Large-scale System using IT

This module is separated from original Rdf module in order to separate sharable parts from Rdf module.

Copyright (c) 2002, 2004 by Galaxy Express Corporation

Copyright (c) 2007, 2008 Seiji Koide


Sharable Functions for XML 1.1 or 1.0 and NameSpace

In the followings, each specification from XML 1.1 (http://www.w3.org/TR/xml11/) or 1.0 (http://www.w3.org/TR/xml/) or Namespaces in XML 1.1 (http://www.w3.org/TR/xml-names11/) is listed before the definition in Lisp.


 [4]    NameStartChar    ::=
         ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | 
         [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | 
         [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | 
         [#x10000-#xEFFFF] 

NameStartChar-p char [function]

returns true if char is a NameStartChar.


 Namespaces[6]    NCNameStartChar    ::=    NameStartChar - ':'  

NCNameStartChar-p char [function]

returns true if char is an NCNameStartChar.


 [4a]    NameChar    ::=
          NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] |
          [#x203F-#x2040] 

NameChar-p char [function]

returns true if char is a NameChar.


 Namespaces[5]    NCNameChar    ::=    NameChar - ':' 

NCNameChar-p char [function]

returns true if char is an NCNameChar.


 [81]    EncName    ::=    [A-Za-z] ([A-Za-z0-9._] | '-')* 

EncName-p char [function]

returns true if char is an EncName.


 [5]    Name    ::=    NameStartChar (NameChar)* 

read-Name stream [function]

reads a name from stream and returns it as string.

%read-Name stream [function]

reads a name from stream and returns characters in list.


 [4]    NCName    ::=    NCNameStartChar NCNameChar* /* An XML Name, minus the ":" */ 

read-NCName stream [function]

reads a NCname from stream and returns it as string. The token must be NCName.

%read-NCName stream [function]

reads a NCName from stream and returns chars in list.

read-quoted-NCName stream [function]

reads a quoted NCName from stream and returns the NCName as string.


 [7]    Nmtoken    ::=    (NameChar)+ 

read-Nmtoken stream [function]

reads a Nmtoken from stream and returns it as string.

%read-Nmtoken stream [function]

reads a Nmtoken from stream and returns chars in list.


 [81]    EncName    ::=    [A-Za-z] ([A-Za-z0-9._] | '-')* 

read-EncName stream [function]

reads a EncName from stream and returns it as string.

%read-EncName stream [function]

reads a EncName from stream and returns chars in list.

 [14]    CharData    ::=    [<&]* - ([<&]* ']]>' [<&]*) 
 [18]    CDSect    ::=    CDStart CData CDEnd  
 [19]    CDStart    ::=    '<![CDATA[' 
 [20]    CData    ::=    (Char* - (Char* ']]>' Char*))  
 [21]    CDEnd    ::=    ']]>' 

CDStart-p stream [function]

Does CDStart characters come from stream next?

read-CData-to-CDEnd stream [function]

reads string from stream up to CDEnd, and returns CData.

Read-entity-decls

read-entity-decls tranforms a sequence of characters from stream that are declared as character entity to the designated character. For example,


*entity-decls* [variable]

storage for entity-decls

read-entity-decls stream [function]

reads entity delcs and returns mapped char. This function should be called just after '&'.


 [25]    Eq    ::=    S? '=' S? 

read-Eq stream &key format-control format-arguments [function]

reads Eq and returns character '='


 [23]    XMLDecl    ::=    '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' 

read-XMLDecl stream [function]

reads XMLDecl just after '<?xml'.


 [24]    VersionInfo    ::=
                      S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"') 

parse-VersionInfo stream [function]


 [80]    EncodingDecl    ::=
                         S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" ) 

EncodingDecl? stream [function]

returns true if character sequence 'enconding' is detected from stream.

read-EncodingDecl stream [function]

reads EncodingDecl and returns EncName that follows '='.


 [32]    SDDecl    ::=    S 'standalone' Eq (("'" ('yes' | 'no') "'") |
                          ('"' ('yes' | 'no') '"'))  

SDDecl? stream [function]

returns true if character sequence 'standalone' is detected from stream.

read-SDDecl stream [function]

Not Yet implemented.

Comment


  [15]    Comment    ::=    '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' 

Comment? stream [function]

returns true if character sequence '!--' is detected from .

read-Comment stream [function]

reads commented string from stream using parse-pattern-delimited-string.

In SWCLOS, comment is a structure that has slot body.

comment body [type]

print-comment r s k [function]

prints out Comment string. This function is not intended to be used by user.

parse-Comment stream [function]

reads Comment from stream and returns a comment structure.


 [11]    SystemLiteral    ::=    ('"' [^"]* '"') | ("'" [^']* "'") 

read-SystemLiteral stream [function]

reads SystemLiteral and returns the string.


 [13]    PubidChar    ::=    #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%] 

PubidChar-p char [function]

returns true if char is a PubidChar.


 [12]    PubidLiteral    ::=    '"' PubidChar* '"' | "'" (PubidChar - "'")* "'" 

read-PubidLiteral stream [function]

reads PubidLiteral from stream and returns the string.


 [75]    ExternalID    ::=    'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral 

ExternalID? stream [function]

Is the next pattern in stream SYSTEM or PUBLIC?

parse-ExternalID stream [function]

If the next pattern is SYSTEM or PUBLIC, then reads and parse the ExternalID from stream.


 [29]    markupdecl    ::=    elementdecl | AttlistDecl | EntityDecl | 
                              NotationDecl | PI | Comment 

markupdecl? stream [function]

this function only detects EntityDecl.

parse-markupdecl stream [function]

this function only parses EntityDecl.


 [28b]    intSubset    ::=    (markupdecl | DeclSep)* 

intSubset? stream [function]

returns true if intSubset is detected from stream.

parse-intSubset stream [function]

reads markupdecl or Comment and parse it.


 [28a]    DeclSep    ::=    PEReference | S 

DeclSep? stream [function]

returns true if PEReference is detected.


 [28]    doctypedecl    ::=
             '<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']' S?)? '>' 

read-doctypedecl stream [function]

reads doctypedecl.


 [6]     QName            ::=    PrefixedName 
                                 | UnprefixedName 
 [6a]    PrefixedName     ::=    Prefix ':' LocalPart  
 [6b]    UnprefixedName   ::=    LocalPart  
 [7]     Prefix           ::=    NCName 
 [8]     LocalPart        ::=    NCName 

read-QNameString stream [function]

reads a Qname from stream and returns it as string. The first token in stream must be NCName.

peep-QNameString stream [function]

peeps QName in stream and returns the string. The first token in stream must be NCName.

read-QName stream [function]

reads a Qname from stream and returns it as symbol if possible. The first token in stream must be NCName. If there is no package named Prefix, the package is created. If QName has no Prefix, LocalPart is interned in *default-namespace* package, or *base-uri* package. If no Prefix and no *default-namespace* and no *base-uri*, the string is returned.


 [70]    EntityDecl   ::=    GEDecl | PEDecl 
 [71]    GEDecl       ::=    '<!ENTITY' S Name S EntityDef S? '>' 
 [72]    PEDecl       ::=    '<!ENTITY' S '%' S Name S PEDef S? '>' 
 [73]    EntityDef    ::=    EntityValue | (ExternalID NDataDecl?) 

EntityDecl? stream [function]

returns true if EntityDecl is detected from stream.

parse-EntityDecl stream [function]

reads EntityDecl from stream and registers the declaration.

Peeping File Coding

Even though a file includes the character encoding information in XMLDecl part, we cannot know it without opening and peeping it. The following functions allow us to peep a file, looking for character encoding.

peep-XMLDecl-code-from-file file [function]

peeps file and returns a character code declared in XMLDecl.

peep-XMLDecl-code-from-string rdf-string [function]

peeps rdf-string and returns a character code declared in XMLDecl.

%peep-XMLDecl-code stream [function]

peeps stream and returns a character code declared in XMLDecl.

Data Type duration

PnYnMnDTnHnMnS, ex. P1Y2M3DT10H30M

parse-as-duration str stream [function]

parse-duration stream [function]

double-angle-bracket-reader stream char [function]

Seiji Koide Sep-13-2008


File RDF\Rdf.cl

Rdf module

IT Program Project in Japan: Building Operation-Support System for Large-scale System using IT

This code was encoded by Seiji Koide at Galaxy Express Corporation, Japan. for the realization of the MEXT IT Program in Japan.

Copyright (c) 2002, 2004 Galaxy Express Corporation
Copyright (c) 2007, 2008 Seiji Koide


rdf-parse-error [condition]

no-Eq-error [condition]

XML Structures in RDF and Parser

RDF/XML file contents can be read and transformed into Lisp structures of XMLDecl, doctypedecl, Comment, RDF, rdf:Description, and prop. For example, in the followings, parse-rdf returns a list that includes a structure of XMLDecl and RDF. Those structure printing functions print structures like XML serialized.


 :cd C:\allegro-projects\SWCLOS\RDFS\           -> C:\allegro-projects\SWCLOS\RDFS\
 (with-open-file (p "Intro.rdf") (parse-rdf p)) ->
 (<?xml version="1.0" ?> 
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
          xmlns:gxpr="http://galaxy-express.co.jp/MEXT/RDF/0.1/Prolog#"
          xmlns="http://galaxy-express.co.jp/MEXT/RDF/0.1/Prolog#">
   <rdf:Property rdf:ID="likes"/>
   <rdf:Description rdf:ID="Kim">
     <gxpr:likes rdf:resource="#Robin" />
   </rdf:Description>
   <rdf:Description rdf:ID="Sandy">
      <gxpr:likes rdf:resource="#Lee" />
      <gxpr:likes rdf:resource="#Kim" />
   </rdf:Description>
   <rdf:Description rdf:ID="Robin">
     <gxpr:likes rdf:resource="#cats" />
   </rdf:Description>
 </rdf:RDF>)

XMLDecl

XMLDecl is composed of version, encoding, and stadalone slots.

XMLDecl version encoding standalone [type]

print-XMLDecl r s k [function]

prints out XMLDecl string that contains version of r, encoding of r, and standalone of r to stream s. This function is not intended to be used by user.

Doctypedecl

doctypedecl is a structure that has slot name, external, and values.

doctypedecl name external values [type]

print-doctypedecl r s k [function]

a doctypedecl is printed in abreviated form '#doctypedecl ... '. This function is not intended to be used by user.

RDF Structures

An RDF structure has slots att&vals and body.

RDF att&vals body [type]

print-RDF r s k [function]

prints out an RDF structure r. This function is not intended to be used by user.

Description

An RDF structure includes one description that contains nested elements.

Description tag att&vals elements [type]

print-Description r s k [function]

prints out a Description r. This function is not intended to be used by user.

Property

A structure property has name, att&val, and value.

prop name att&vals value [type]

print-prop p s k [function]

prints out a property p. This function is not intended to be used by user.

Parser

parse-XMLDecl stream [function]

reads XMLDecl and returns XMLDecl structure. This function should be called just after '<?xml '

parse-doctypedecl stream [function]

reads doctypedecl from stream and returns it as structure.

parse-RDFdecl stream [function]

reads RDF/XML from stream and returns RDF structure.

parse-Description stream &optional depth [function]

reads and parses a description from stream and returns a text or a structure Description.

parse-property stream depth [function]

reads from stream and parse a property element, and returns a property structure.

Reader

read-Description stream &optional depth [function]

reads a description from stream and returns tag, attributes, and contents. Note that contents are a list of instances of property structure.

read-property stream depth [function]

reads a property from stream and returns tag, attributes, and its contents.

read-Attribute-in-RDF stream [function]

returns a list of Name symbol and attribute value.

 [66]    CharRef    ::=    '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';' 

read-CharRef stream [function]

reads CharRef from stream and returns a translated character

 [68]    EntityRef    ::=    '&' Name ';' 

read-EntityRef stream [function]

reads EntityRef and returns a translated string.

 [69]    PEReference    ::=    '%' Name ';' 

read-PEReference stream [function]

Not implemented yet. reads PEReference and returns a translated string.

 [67]    Reference    ::=    EntityRef | CharRef 

read-Reference stream [function]

reads EntityRef or CharRef from stream.

 [10]    AttValue    ::=    '"' ([^<&"] | Reference)* '"'  
                         |  "'" ([^<&'] | Reference)* "'" 

read-AttValue stream [function]

reads AttValue from stream and returns the string.

read-URI stream [function]

reads URI string from stream.

%read-URI stream q [function]

white-space-p decl [function]

Is this decl is all white space?.

skip-pattern-delimited-string pattern stream [function]

just skips and discards pattern in stream.

Parsing Attribute


 namespace[1]    NSAttName         ::=    PrefixedAttName | DefaultAttName 
 namespace[2]    PrefixedAttName   ::=    'xmlns:' NCName 
 namespace[3]    DefaultAttName    ::=    'xmlns' 
 namespace[15]   Attribute         ::=    NSAttName Eq AttValue | QName Eq AttValue 

read-Attribute-in-Description stream [function]

returns a list of Name symbol and attribute value.

read-Attribute-in-property stream [function]

returns a list of Name symbol and attribute value.

Element in XML


 [39]    element       ::=    EmptyElemTag | STag content ETag 
 namespace[14]    EmptyElemTag  ::=    '<' QName (S Attribute)* S? '/>' 
 namespace[12]    STag          ::=    '<' QName (S Attribute)* S? '>'
 [43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)* 

Read-element in XML general is defined as above. However, a Description element (node element) and a property element in RDF must be alternately appear in XML nest structure. See, http://www.w3.org/TR/rdf-syntax-grammar/#example1.

Therefore, two element reader are coded, dedicated to node elements and property elements repectively. Then, read-STag-or-EmptyElemTag-in-Description calls read-STag-or-EmptyElemTag-in-property, and read-STag-or-EmptyElemTag-in-property calls read-STag-or-EmptyElemTag-in-Description, if the substructure exists.

read-STag-or-EmptyElemTag-in-Description stream [function]

returns a start tag and attributes. attributes are a property list.

read-STag-or-EmptyElemTag-in-property stream [function]

returns a start tag and attributes. attributes are a property list. Note that returned value for tag is a string.

 namespace[13]    ETag    ::=    '</' QName S? '>'  

read-string-until-Etag-with-eat-up QName stream [function]

reads stream up to Etag of QName and returns the string read. QName must be a string.

ETag-p-with-eat-up STag stream [function]

tests a end tag for STag. STag should be a string. This function eats up the end tag with '/' & '', if true. Otherwise it does not eat, and returns false.

read-plane-text stream [function]

read-as-datatype value datatype [function]

value is a string. datatype is a symbol that indicates any of xsd:Datatypes. This function creates an instance of datatype from value. Note that white spaces of head and tail of value are trimed and read to a lisp object from value. For example, if datatype is xsd:integer '010' as value is translated to 10, an instance of cl:integer, then 10^^xsd:integer is made, in which the value is 10.

^^ value type [function]

makes an XML typed data with value of type. If value is a string, read-as-datatype is called, otherwise makes typed data of value and type. This function returns an instance of ill-structured-XMLLiteral when value does not comform to type.

RDFdecl? stream [function]

Is RDFdecl opening up?

RDFdeclEndp? stream [function]

Is RDFdecl closing?

parse-element stream [function]

parses XMLDecl, or doctypedecl, or comment, or RDFdecl.

Producer & Consumer model for RDF parsing

make-rdf/xml-parser stream [function]

makes a parser for RDF/XML.

parse-rdf stream [function]

parses RDF/XML from stream and makes the internal representation. This function returns a list of XML structures. Note that *base-uri* and *default-namespace* are updated through content from stream.

rdf-db-register name pos depth [function]

hook for external database.

rdf-db-open-p [function]

hook for external database.

Seiji Koide Sep-13-2008


File RDF\RdfReader.cl

RDF/XML parser module

IT Program Project in Japan: Building Operation-Support System for Large-scale System using IT

This code is written by Seiji Koide at Galaxy Express Corporation, Japan, for the realization of the MEXT IT Program in Japan,

Copyright © 2002,2004 by Galaxy Express Corporation, Japan. Copyright 2008-2009 Seiji Koide.

make-form x [function]

x may be a null list, string, number, literal, an instance of description, comment, or cons. This function returns a S-expression of x. If x is a comment, nil is returned.

prop-form prop [function]

Description-form description [function]

generates S-exression of description.

%Description-form class attrs props [function]

generates S-expression from class, attrs, and props. class is a QName symbol that indicates type tag in RDF/XML. attrs are a attribute/value list for attributes in RDF/XML. props are a property/value list for properties in RDF/XML.

Producer-Consumer Model

It is much better to incrementaly process data in each small fragment from input stream, without waiting until whole contents of file are read. In this case, a fragment from input stream is parsed by a parser and the result is handed to an interpreter that processes parsed data. If two processes are concurrently cooperate through pipe-like data connection, we call such computation model producer-consumer model. In Unix, it will be implemented with two processes and pipe. In Scheme, it will be implemented as coroutine with continuation. Unfortunately, Common Lisp is not equiped such a native model.Then, following make-rdfxml-reader and make-accepter-for-rdf create a producer and a consumer dedicated to parsing and interpreting RDF file.


make-rdfxml-reader stream [function]

This function creates a creater of a producer in producer-consumer model. The returned function must take a consumer.

Auto-epistemic Local Closed World Assumption

Offically, Semantic Webs are regarded as an open world. Namely, it is regarded that you cannot know all knowledge about the world. The limited capability of agent cannot exhaust almost infinite WWW world. It is called Open World Assumption (OWA) in Sematic Webs. However, this assumption produces less results in reasoning, especially with respect to the existential value restriction of property or owl:someValuesFrom. Rigorous OWA does not infer anything on existential restrictions, even if you add a slot value that does not satisfy an existenitially restriction into the slot in OWL, because a satisfiable value may be defined at another place in WWW, where you do not know.

Such rigorous OWA is not enjoyable for ontologies that you and your colleague are building. So, we have introduced the notion of auto-epistemic Local Closed World Assumption. In this idea, an agent and you can introspectively check their knowledge within their boundaries and be able to intrinsically world the agent knows, the agent stands at locally closed world around it. This is called auto-epistemic Local Closed World Assumption. The global variable *autoepistemic-local-closed-world* is set true as default in SWCLOS, and the satisfiability for existential restriction for slot value is aggressively checked. Namely, if an existential restriction is not satisfied, the interpretation is not satisfied. If you want to completely regard Open World Assumption, set *autoepistemic-local-closed-world* false.

In the Tableau Method of Description Logics, an instance that satisfies the existential restriction is virtually created and the satisfiability as a whole ontology is checked. We would like to claim it is basically the same as setting auto-epistemic Local Closed World Assumption.

*autoepistemic-local-closed-world* [variable]

default value is true, namely the world is locally closed within knowledge of agent.

make-accepter-for-rdf accepter-fun [function]

This function creates a creater of a consumer function in producer-consumer model. The returned function must take a producer.

*defined-resources* [variable]

accumulating list for defined resource with the line where the entity appeared.

*referenced-resources* [variable]

accumulating list for referenced resource with the line where the entity appeared.

read-rdf-file accepter-fun &optional file code [function]

reads an rdf file and hands parsed data to accepter-fun. If XMLDecl in file includes any code statement, it is set as character-code of this file. If no statement for character-code in file and code supplied, then this file is parsed in code. In parsing, QNames of referenced resources and defined resources are stored into *referenced-resources* and *defined-resources*. At the end this procedure, the set difference of *referenced-resources* and *defined-resources* is printed.

read-rdf-from-string accepter-fun rdf-string &optional code [function]

ask-user-rdf-file [function]

asks an rdf file to user.

Reader Macro '

This mechanism is similar to lisp symbol evaluation, but note that the form is not any symbol. So, the evaluation for such a form cannot be suppressed, even if you quoted it.

*standard-readtable* [variable]

*standard-readtable* [variable]

read-string stream closech [function]

read-lang-tag stream firstchar [function]

lang-tag-char-p char [function]

sub-tag-char-p char [function]

read-type-tag stream firstchar [function]

single-underscore-reader stream char [function]


File RDF\node.cl

gnode & rdf-node

rdf-node will be a superclass of rdfs:Class. gnode will be a superclass of rdfs:Resource. gnode class is needed for registration of class-instance relation.

rdf-node [class]

This metaclass is node class. This metaclass provides method class-direct-instances

gnode [class]

This class is needed to maintain mclasses.
An element of direct-instances slot are initially stored by make-instance(rdf-node) method and maintained by update-instance-for-different-class:after(gnode) which is invoked by change-class.

make-instance (class rdf-node) &rest initargs [method]

shadowed-class-p x [function]

returns true if x is an instance of shadowed class. shadowed-class is defined at RdfsObjects file.

update-instance-for-different-class (previous gnode) current &rest initargs [method]

node-p x [function]

bnode-p node [function]

ground? (node gnode) [method]

name (node symbol) [method]

name (node gnode) [method]

returns a QName or a nodeID of node, if it exists. Otherwise nil.

setf symbol (node gnode) [method]

exports symbol for QName.

SWCLOS Home Authors Lisp Code Overview