djpowell.net

The Web, RDF, and other stuff

New RDF syntax: The Schema

More details about my proposed RDF syntax


I’ve put some links to related content at the Namespace URI: http://djpowell.net/schemas/treetriples/1/

# RELAX NG Compact Syntax Grammar for proposed RDF/TreeTriples syntax
# EXPERIMENTAL!
#
# David Powell - 2006-11-24

default namespace = "http://djpowell.net/schemas/treetriples/1/"

# Common attributes

start = rdf
## Root rdf element contains a list of triples and declarations.
rdf =
   element rdf {
      s* & d* & dstmt?
   }


## A triple is declared by creating an 's' element for the triple's
## subject, and nesting 'p' and 'o' elements inside for the predicate
## and object of the triple.  Multiple 'p' and 'o' elements can be
## nested, effectively abbreviating the common case of many statements
## with duplicate subjects, or subject/predicate pairs.
## Triples sharing the same subject MUST be represented with a single
## 's' element.
s =
   element s {
      attribute id { id },
      p+
   }

## A predicate for the parent node's subject.  Triples sharing the same
## subject and predicate MUST be represented by a single nested 's' and
## 'p' element.
p =
   element p {
       attribute id { uri },
       o+
   }

## An object which forms a triple with the grandparent node's subject, and
## the parent node's predicate.
o =
    element o {
      ## A statement id can be used to create an rdf:Statement structure
      ## corresponding to an asserted statement.
      attribute stmtId { id }?,
      (
          (attribute id { id }, nocontent) |
          literal |
          parseXml
       )
    }


## Literals can be typed, or have a language.  For XML literals, the special 
## special 'parseXml' form MUST be used.
literal = 
    (
        attribute xml:lang { lang }? |
        attribute datatype { uri }?
    ),
    text

lang =
    xsd:language

## ids may represent nodeIds for bnodes, or URIs for resources.
id =
    nodeId | uri

## A nodeId is a document-scoped label for a bNode.  nodeIds must
## start with the characters "_:", followed by an NCName, restricted to 
## ASCII characters
nodeId =
    xsd:Name { pattern = "_:[a-zA-Z_][a-zA-Z0-9.\-_]*" }

## An absolute RDF URI.  URIs will never start with the string "_:", which
## is reserved for bNodes.
## MUST be an absolute IRI..
## Leading and trailing spaces MUST NOT be present.
uri =
    xsd:anyURI
	
## Represents an XML literal.  The 'o' element and its attributes are not
## part of the content.  The contained elements are expected to follow the
## same rules as RDF/XML XML literals.
parseXml = 
   attribute parse { string "xml" },
   (text|anyElement)*

anyElement =
   element * {
      (attribute * { text }
       | text
       | anyElement)*
   }

nocontent = string ""

## Declarations provide a sane way of declaring lists, containers,
## and un-asserted, reified statements.
d = 
    element d {
       parseList |
       parseContainer
    }

## Only one un-asserted reified statement block is allowed, but it can
## contain many statements.
dstmt =
    element d {
       parseStatement
    }

## Represents an RDF collection.  The 'id' of the collection may be represented
## by a 'listId' attribute on the first member 'o' element.
## empty collections are supported.
parseList = 
   attribute parse { string "list" },
   collectedo*

## Represents an RDF container.  The URI represents the container type, which
## is assumed to be a subtype of rdfs:Container.  The attribute value:
## container indicates that none of the explicit types are stated.
## empty containers must use SPO syntax.
parseContainer = 
   attribute parse { string "seq" | string "alt" | string "bag" | string "container" },
   attribute id { id },
   containedo+

## Represents un-asserted, reified statements.
parseStatement = 
   attribute parse { string "statement" },
   s+

## NOTE there is no special support for reified containers, collections, or statements.

## Objects in containers can't contain a stmtId.
containedo =
    element o {
      (
          (attribute id { id }, nocontent) |
          literal |
          parseXml
       )
    }

## Objects in collections can't contain a stmtId, but can contain a listId to
## allow the list nodes themselves to be referenced.
collectedo =
    element o {
      attribute listId { id }?,
      (
          (attribute id { id }, nocontent) |
          literal |
          parseXml
       )
    }

        
[Download RelaxNG Schema]

[Email a comment]

[Latest] [Archive by Date] [Archive by Category] [Atom Feed]

Last updated: 5th March 7:07 PM (+0000)