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.
Utilities for SWCLOS and Rbase from AIMA and others
Utilities in this file are taken from AIMA and redefined in package gx.
If x is an atom, return it; otherwise if one length list, return the element, else returns x |
If x is a list, return it; otherwise return a singleton list, (x). |
Apply fn to respective elements of list(s), and append results. |
returns true if x and y is equal as set, the test function is equalp. |
returns true if x and y is equal as set, the test function is eq. |
Is this a list of 2 or more elements? |
Is this a list of exactly one element? |
Is this a list of exactly two elements? |
Is this a list that starts with the given element? |
Return the last element of a list. |
Return the last two element of a list. |
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.
delay forced closure |
[type] |
And Others, from Winston's Lisp.
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. |
Seiji Koide Nov-15-2010
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, starting from one, zero is just a flag that indicates no RDF/XML parser input. |
current line position, starting from zero |
current position, starting from zero |
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.
- ((#\null) #\null) indicates null list.
- ((a b c #\null) #\null) indicates three characters 'a', 'b', and 'c' in buffer.
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. |
reads a quoted string from stream. |
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
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 in SWCLOS and Rbase that is a subclass of net.uri:uri and able to bind a value to,
just like lisp symbol. |
Is x a uri and bound at its value slot? |
returns bound value of iri value from str. |
This macro should be used by programmers, when uri is definitely uri here. |
IRI Escaping
See, rfc2396 for URI escaping
Is this char reserved for iri? |
Is this char marked for iri? |
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 . |
escapes uri delimiter char in str before making uri. |
encodes the uri reserved characters to hexadecimals. |
This function decodes Percent-Encoding to characters. |
URI APIs fixes
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.
returns interned thing for class gx:iri. |
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. |
To list all iris for resource, call list-all-entity-uris. See gxutils module.
Seiji Koide Nov-15-2010
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.
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.
- cl:single-float is mapped to xsd:float.
- cl:double-float is mapped to xsd:double.
- cl:integer is mapped to xsd:integer.
- The range of cl:bignum and cl:fixnum is mapped to the range of xsd:long, xsd:int,
xsd:short, and xsd:byte according to the definition of range of each datatype.
- cl:rational is mapped to xsd:decimal.
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.
0 <= x <= 18446744073709551615 |
-2147483648 <= x <= 2147483647 |
-9223372036854775808 <= x <= 9223372036854775807 |
any number of digits without point but with or without + or - |
floating point number in lisp |
double floating point number in lisp |
rational number in lisp, which should be revised in future. |
xsd:boolean, xsd:anyURI, xsd:string, xsd:float, xsd:double, or xsd:decimal |
Seiji Koide Sep-11-2008
Condition and Error Handling module
This code is written by Seiji Koide.
Copyright (c) 2007 Seiji Koide
Undoable Objects and Classes
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.
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*.
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.
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. |
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. |
retrieves a uri-namedspace on prefix-uri from *NameSpaces* by interning it. |
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. |
returns a package associated to prefix-uri. |
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.
a function to be invoked when uri to symbol name mapping is irregular. |
a function to be invoked when uri to symbol package mapping is irregular. |
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. |
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. |
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
This function is used in ask-user-package-name and ask-user-symbol-name. |
This function is bound to *uri2symbol-name-mapping-fun* as default. This function just makes a query for users. |
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. |
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 name space URI for XML parsing in current time. This value is set by read-rdf-from-http and read-rdf-file. |
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. |
transforms QName to PrefixedName string. QName should be a lisp symbol. |
transforms QName to UnPrefixedName string. QName should be a lisp symbol. |
export this symbol as QName. The symbol-package of symbol is stored
into the related uri namespace. |
transforms QName string to a lisp symbol. |
transforms symbol to QName string in the current namespace. |
Symbol to URI
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
simply transforms str to a exported symbol in anonymous node package :_
and returns it. |
makes a unique node ID from str. Namely, adds numbers at the end of str and makes unique symbol. |
transforms ontouri to special symbol of which string is equal to ontouri. |
Seiji Koide Nov-15-2010
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.
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".
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. |
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]
returns true if char is a NameStartChar. |
Namespaces[6] NCNameStartChar ::= NameStartChar - ':'
returns true if char is an NCNameStartChar. |
[4a] NameChar ::=
NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] |
[#x203F-#x2040]
returns true if char is a NameChar. |
Namespaces[5] NCNameChar ::= NameChar - ':'
returns true if char is an NCNameChar. |
[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
returns true if char is an EncName. |
[5] Name ::= NameStartChar (NameChar)*
reads a name from stream and returns it as string. |
reads a name from stream and returns characters in list. |
[4] NCName ::= NCNameStartChar NCNameChar* /* An XML Name, minus the ":" */
reads a NCname from stream and returns it as string. The token must be NCName. |
reads a NCName from stream and returns chars in list. |
reads a quoted NCName from stream and returns the NCName as string. |
[7] Nmtoken ::= (NameChar)+
reads a Nmtoken from stream and returns it as string. |
reads a Nmtoken from stream and returns chars in list. |
[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
reads a EncName from stream and returns it as string. |
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 ::= ']]>'
Does CDStart characters come from stream next? |
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,
- & -> '&'
- < -> '<'
- > -> '>'
- ' -> "'"
- " -> '"'
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? '?>'
reads XMLDecl just after '<?xml'. |
[24] VersionInfo ::=
S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"')
[80] EncodingDecl ::=
S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" )
returns true if character sequence 'enconding' is detected from stream. |
reads EncodingDecl and returns EncName that follows '='. |
[32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") |
('"' ('yes' | 'no') '"'))
returns true if character sequence 'standalone' is detected from stream. |
Comment
[15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
returns true if character sequence '!--' is detected from . |
reads commented string from stream using parse-pattern-delimited-string. |
In SWCLOS, comment is a structure that has slot body.
prints out Comment string. This function is not intended to be used by user. |
reads Comment from stream and returns a comment structure. |
[11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
reads SystemLiteral and returns the string. |
[13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
returns true if char is a PubidChar. |
[12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
reads PubidLiteral from stream and returns the string. |
[75] ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral
Is the next pattern in stream SYSTEM or PUBLIC? |
If the next pattern is SYSTEM or PUBLIC, then reads and parse the ExternalID from stream. |
[29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl |
NotationDecl | PI | Comment
this function only detects EntityDecl. |
this function only parses EntityDecl. |
[28b] intSubset ::= (markupdecl | DeclSep)*
returns true if intSubset is detected from stream. |
reads markupdecl or Comment and parse it. |
[28a] DeclSep ::= PEReference | S
returns true if PEReference is detected. |
[28] doctypedecl ::=
'<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']' S?)? '>'
[6] QName ::= PrefixedName
| UnprefixedName
[6a] PrefixedName ::= Prefix ':' LocalPart
[6b] UnprefixedName ::= LocalPart
[7] Prefix ::= NCName
[8] LocalPart ::= NCName
reads a Qname from stream and returns it as string. The first token in stream must be NCName. |
peeps QName in stream and returns the string. The first token in stream must be NCName. |
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?)
returns true if EntityDecl is detected from stream. |
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.
peeps file and returns a character code declared in XMLDecl. |
peeps rdf-string and returns a character code declared in XMLDecl. |
peeps stream and returns a character code declared in XMLDecl. |
Data Type duration
PnYnMnDTnHnMnS, ex. P1Y2M3DT10H30M
Seiji Koide Sep-13-2008
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
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] |
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.
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.
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.
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] |
prints out a property p. This function is not intended to be used by user. |
Parser
reads XMLDecl and returns XMLDecl structure. This function should be called
just after '<?xml ' |
reads doctypedecl from stream and returns it as structure. |
reads RDF/XML from stream and returns RDF structure. |
reads and parses a description from stream and returns a text or a structure Description. |
reads from stream and parse a property element, and returns a property structure. |
Reader
reads a description from stream and returns tag, attributes, and contents.
Note that contents are a list of instances of property structure. |
reads a property from stream and returns tag, attributes, and its contents. |
returns a list of Name symbol and attribute value. |
[66] CharRef ::= '' [0-9]+ ';' | '' [0-9a-fA-F]+ ';'
reads CharRef from stream and returns a translated character |
[68] EntityRef ::= '&' Name ';'
reads EntityRef and returns a translated string. |
[69] PEReference ::= '%' Name ';'
Not implemented yet. reads PEReference and returns a translated string. |
[67] Reference ::= EntityRef | CharRef
reads EntityRef or CharRef from stream. |
[10] AttValue ::= '"' ([^<&"] | Reference)* '"'
| "'" ([^<&'] | Reference)* "'"
reads AttValue from stream and returns the string. |
reads URI string from stream. |
Is this decl is all white space?. |
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
returns a list of Name symbol and attribute value. |
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.
returns a start tag and attributes. attributes are a property list. |
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? '>'
reads stream up to Etag of QName and returns the string read.
QName must be a string. |
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. |
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. |
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. |
parses XMLDecl, or doctypedecl, or comment, or RDFdecl. |
Producer & Consumer model for RDF parsing
makes a parser for RDF/XML. |
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. |
hook for external database. |
hook for external database. |
Seiji Koide Sep-13-2008
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.
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. |
generates S-exression of description. |
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.
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.
default value is true, namely the world is locally closed within knowledge of agent. |
This function creates a creater of a consumer function in producer-consumer model.
The returned function must take a producer. |
accumulating list for defined resource with the line where the entity appeared. |
accumulating list for referenced resource with the line where the entity appeared. |
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. |
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.
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.
This metaclass is node class. This metaclass provides method class-direct-instances |
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.
returns true if x is an instance of shadowed class.
shadowed-class is defined at RdfsObjects file. |
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. |