Jena N3 Parser, RDF Reader and Writer

This package contains

- an N3 parser
- a Jena reader, for reading the RDF subset of N3 into a Model
- a Jena writer for outputting RDF in an N3 syntax.

The N3 writer is aimed at producing readable N3 and analysies the model before writing. It may unsuitable for some forms of very large model.

This package does not contains a rules engine to interprete or execute N3 formulae. It is not a replacement for cwm; this system aims to provide daat input fo RDF in N3 format.

The Parser

The N3 parser provided parses the whole of the N3 language. It is a streaming parser that emits parser events (see the class N3ParserEventHandler) when a new triple is encountered.

It is a permissive parser, it does not aim to validate an N3 and mioght even parse some constructs which are not valid (examples include named formulae and named DAML lists; the generated parser events do not expressive the named objects). It does not check the characters comprising URIs and is more permissive on qnames that strict defintion would require.

The parser is built using antlr. The grammar file is "n3.g". An application will need access to the antlr runtime classes which are provided in antlr.jar in the Jena lib/ directory.

There is a simple application in jena.n3 that accesses the N3 parser directly or via the RDF generator for file conversion or for simple file checking.

The RDF generator

The RDF generator takes a stream of parser events and turns them into additions to a Jena model. The Jena reader is then a class that wraps up this functionality to conform to the Jena reader interface. The RDF generator does not allow formulae and will cause an error if one is encountered.

Performance

The parser alone runs at about 18K triples/second on Pentium4 750Mhz PC (it is I/O bound in the lexer). When generating RDF, the rate is about 9K statements/second.

Notes

N3 files are UTF-8: not raw bytes or ISO-8859-1. Applications should pass UTF-8 character set readers and writers to the appropriate Jena operations model.read and model.write. Often, this does not make a difference but can cause silent loss or change of character information.

Other Information on N3

- http://www.w3.org/2000/10/swap/doc/cwm
- http://www.w3.org/DesignIssues/Notation3.html
- http://infomesh.net/2002/notation3/
- http://notabug.com/2002/n3/
- http://www.agfa.com/w3c/euler

Acknowledgements

The grammar was not written from scratch. The grammar is based on cwm, Dan Connerly's python grammar and Graham Klyne's N3Parser as well as "Notation3 : A Rough Guide" which lists other parsers.