4.  RDF Resource Objects

4.1  Resource Objects and the Syntax in S-expression

In RDF graph model, a node is represented by either resource nodes or literals. A resource node is either a named node, which has a globally unique URI, or a blank node, which has no URI. A literal is a kind of string or number, or an instance of XMLLiteral. Figure 4.1, which is taken from RDF/XML Syntax Specification, shows an example of RDF graph. In the figure, a rectangle represents a literal and an ellipse represents an anonymous blank node or a resource node that contains a URI inside. In SWCLOS, Figure 4.1 is expressed as follows in S-expression.


RDF Graph Example

Figure 4.1 RDF Graph Example (from RDF/XML Syntax Specification)

(rdf:Description
  (rdf:about "http://www.w3.org/TR/rdf-syntax-grammar")
  (ex:editor
    (rdf:Description
      (ex:homePage
        (rdf:Description (rdf:about "http://purl.org/net/dajobe/")))
      (ex:fullName "Dave Beckett")))
  (dc:title "RDF/XML Syntax Specification (Revised)"))

Whereas rdf:about in SWCLOS looks like a property in RDF, it is not a property in RDF but an XML attribute that takes a place in RDF/XML format resource definition. The ex:editor, ex:homePage, ex:fullName, and dc:title are RDF properties in QName representation for the corresponding URIs on the edges in the figure. The terminology ‘rdf:Description’ that appears in S-expression for RDF graph representation just denotes a sequence for RDF description. With addForm function, this statement turns out a resource object. See the syntax in BNF described below. Precisely, the assertion above produces three CLOS objects, that is, two named resource objects and one anonymous resource object, in addition to two lisp strings.

4.2  Adding and Getting a Resource Form

SWCLOS allows users to add such a form as mentioned in the previous section, that is, nested object-centered representation of RDF graph into the lisp environment. However, if a resource name is not supplied, the created object is anonymous. See the following example. If you type the lines as the demonstration, a dialogue window will pop up twice at the line 5 for package name of uri “http://purl.org/net/” and “http://www.w3.org/TR/”. Please note to push ‘cancel’ button in this case. If you gave some package name for the query, SWCLOS would create the package and make a symbol, e.g., package-name-you-input:dajobe. Then, you would obtain a different look at line 6, where the symbol name package-name-you-input:dajobe would appear instead of ‘(rdf:Description (rdf:about "http://purl.org/net/dajobe/"))’ for the anonymous object.

gx-user(3): (defpackage ex)
#<The ex package>
gx-user(4): (defpackage dc)
#<The dc package>
gx-user(5): (addForm '(rdf:Description
  (rdf:about "http://www.w3.org/TR/rdf-syntax-grammar")
  (ex::editor
    (rdf:Description
      (ex::homePage
        (rdf:Description (rdf:about "http://purl.org/net/dajobe/")))
      (ex::fullName "Dave Beckett")))
  (dc::title "RDF/XML Syntax Specification (Revised)")))
Warning: Entail by rdf1: ex::editor rdf:type rdf:Property.
Warning: Entail by rdf1: dc::title rdf:type rdf:Property.
Warning: Entail by rdf1: ex::homePage rdf:type rdf:Property.
Warning: Entail by rdf1: ex::fullName rdf:type rdf:Property.
#<|rdfs:Resource| common-lisp:nil>
gx-user(6): (pprint (get-form <<http://www.w3.org/TR/rdf-syntax-grammar>>))

(rdf:Description (rdf:about "http://www.w3.org/TR/rdf-syntax-grammar")
  (ex:editor
    (rdf:Description
      (ex:homePage (rdf:Description (rdf:about "http://purl.org/net/dajobe/")))
      (ex:fullName "Dave Beckett")))
  (dc:title "RDF/XML Syntax Specification (Revised)"))

Do not care about those warnings at line 5 at this time. It will be explained at Section 5.5. In this example, an RDF graph shown in Figure 4.1 is inputted through a form in S-expression in SWCLOS, and three objects are created in the environment. You can backwardly generate the form in RDF graph from the subjective resource object using get-form in the lisp top level.

The value of property ‘ex:editor’ is anonymous. The value of ‘ex:homePage’ is also anonymous, because SWCLOS did not obtain the name by your cancellation for its package name. Note that SWCLOS cannot identify anonymous objects by name, even if they have the URI in rdf:about attribute. (However, you can get anonymous objects through corresponding URIs with function iri-value.)

Function addForm interprets a form according to the following BNF syntax, where {A--Z} means any character from A to Z, and {SomeNode - element} means the possibility of SomeNode minus element. Also note ‘xyz’ means a sequence of character x, y, and z. #\x means a character x.

form ::= number | string | uri | qname | langedString | datatypeString |
           ‘(’ ws* lang-tag ws+ string ws* ‘)’ | ‘(’ ws* datatype ws+ datum ws* ‘)’ |
           ‘(’ ws* ‘@’ ws+ lang-tag ws+ string ws* ‘)’ |
           ‘(’ ws* ‘^^’ ws+ datatype ws+ datum ws* ‘)’ |
           ‘(’ ws* ‘rdf:Description’ [ws+ nform] {ws+ lang-form | ws+ slot-form}* ws* ‘)’ |
           ‘(’ ws* type-tag [ws+ nform] {ws+ lang-form | ws+ slot-form}* ws* ‘)’
lang-form ::= ‘(’ ws* ‘xml:lang’ ws+ lang-tag ws* ‘)’
slot-form ::= ‘(’ ws* ‘rdf:about’ ws+ uri ws* ‘)’ | ‘(’ ws* ‘rdf:ID’ ws+ name ws* ‘)’ |
                   ‘(’ ws* ‘rdf:nodeID’ ws+ bname ws* ‘)’ | ‘(’ ws* ‘:name’ ws+ name ws* ‘)’ |
                   ‘(’ ws* role {ws+ lang-tag}? {ws+ form}+ ws* ‘)’
langedString ::= string ‘@’ language
language ::= {a--z}+ {‘-’ {a--z0--9}+}*, comforming to IETF BCP 47
lang-tag ::= ‘:’ {a--z}+ {‘-’ {a--zA--Z0--9}+}*, comforming to IETF BCP 47
datatypeString ::= string ‘^^’ datatype
datatype ::= symbol - ‘cl:nil’ - ‘t’, comforming to xsd datatype (see Section 6)
nform ::= name | ‘(’ ws* ‘:name’ ws+ name ws* ‘)’
role ::= symbol - ‘cl:nil’ - ‘t’
type-tag ::= symbol - ‘cl:nil’ - ‘t’
symbol ::= qname | unexported-qname
qname ::= [prefixName ‘:’] name
unexported-qname ::= prefixName ‘::’ name
prefixName ::= {nameStartChar - ‘:’ - ‘_’} nameChar*
name ::= nameStartChar nameChar*
bname ::= ‘_:’ name
nameStartChar ::= See XML 1.1 NameStartChar.
nameChar ::= See XML 1.1 NameChar.
string ::= ‘"’ scharacter* ‘"’
scharacter ::= {echaracter -- ‘"’} | ‘\"’
echaracter ::= character | ‘#\Tab’ | ‘#\Newline’ | ‘#\Return’
character ::= ‘#\\’ | {#\Space -- #\[} | {#\] -- #x10FFFF}, up to the limit of UNICODE
ws ::= ‘#\Space’ | ‘#\Tab’ | ‘#\Newline’
uri ::= string conformable to URI in W3C
datum ::= string or lisp object that conforms to designated datatype
number ::= number character sequence in Lisp, cf. Parsing of Numbers and Symbols

addForm form [role]
[Function]
typically returns a resource object for form. In the top level, role is not supplied. Otherwise, role must be supplied in recursive call with form as role's filler.
A user usually do not use this function directly, instead a user should use defIndividual or defConcept (defResource) or defProperty macro for resource definition.
See also addForm in documentation in doc folder.

get-form resource
[Function]
generates and returns the form of resource in S-expression.


Author: Seiji Koide. Copyright (c) 2005, 2006 GALAXY EXPRESS CORPORATION. Feb. 2006
Copyright (c) 2007-2010 Seiji Koide. Oct.2010