Raptor RDF parser and serializer bindings for Node.js
=====================================================

Experimental, use at own risk!

[Raptor](http://librdf.org/raptor/) is a mature RDF parsing and serializing library written in C by Dave Beckett. It is part of Redland, the RDF handling and storage library.

These bindings support [raptor 2](http://librdf.org/raptor/api/) only (v1.9.0 or greater).

Building
========

A version of `libraptor2` is downloaded, compiled and statically linked against automatically. If you prefer to use a version of `libraptor2` already installed on your system (e. g. under `/usr/local`), just 

    export RAPTOR_PREFIX=/usr/local

General Usage
=============

Include raptor bindings with

    var raptor = require('raptor');

You can create parsers or serializers for certain syntax types like so:

    var parser = raptor.newParser('rdfxml');
    var serializer = raptor.newSerializer('turtle');

API
===

Parser
------

* `parser.parseFile(pathName [, base]);`

    Parses file at path `pathName` using optional base URI `base`.

* `parser.parseURI(uri [, base]);`

    Parses RDF date retrieved from `uri` using optional base URI `base`.

* `parser.parseStart([base]);`

    Starts parsing in buffer mode using optional base URI `base`.
    Buffers can be sent to the parser via `parser.parseBuffer(buffer)`.
    Calling `parseBuffer()` with no parameter ends buffer parsing mode.

* `parser.setOption(optionName, optionValue);`

    Sets several parsing options (not implemented yet).

* `parser.abort();`

    Aborts the parsing process; 'end' will be emitted.

* `parser.name` holds the syntax name that was used with `raptor.newParser` (e.&thinsp;g. 'rdfxml').

Serializer
----------


Emitted Events
--------------

On the following conditions, events are emitted:

A new statement was parsed
--------------------------

    parser.on('statement', function (statement) {
        // do something with statement
    });

Statements are exposed with the following structure:

    var statement = {
        subject: {
            type: 'uri',                                 /* 'uri' or 'bnode' */
            value: 'http://example.com/exampleResource'
        }, 
        predicate: {
            type: 'uri',                                     /* always 'uri' */
            value: 'http://example.com/exampleProperty'
        }, 
        object: {
            type: 'typed-literal',                         /* 'uri', 'literal', 
                                                 'typed-literal', or 'bnode' */
            value: 'An example literal value', 
            datatype: 'http://www.w3.org/2001/XMLSchema#string'
        }, 
        toString: function () {
                                     /* return statement as N-triples string */
        }
    }

A new resource was parsed
-------------------------

  parser.on('resource', function (r) {
    // do something with resource
  });

The resource

### Parsing has ended
Either by reaching `EOF`, or by interruption due to `parser.abort()` being called.

    parser.on('end', function () {
        // handle end event
    });

### A namespace has been declared

    parser.on('namespace', function (prefix, namespaceURI) {
        // handle namespace event
    });

### A message has been retrieved

    parser.on('message', function (type, message, code) {
        // log errors and warnings synchronously
        if (type == 'error' || type == 'warning') {
            util.log(type.toUpperCase() + ': ' + message + ' (' + code + ')');
        }
    });

