modules/rdf/parser/ntriples.zzm

rdf-0.0.3 source code

=encoding utf8

=head1 NAME

rdf/parser/ntriples - N-Triples parser.

=head1 SYNOPSIS

  from rdf/parser/ntriples import NTriplesParser;
  
  let parser := new NTriplesParser();
  let quads := parser.parse_string("<s> <p> \"o\" .\n");


=head1 DESCRIPTION

C<NTriplesParser> parses RDF 1.1 N-Triples into RDF quads in the default
graph. It accepts C<base> and C<into> parser options for consistency with
the other RDF parsers, though N-Triples requires absolute IRIs.

=head1 EXPORTS

=head2 Classes

=over

=item C<NTriplesParser>

=over

=item C<< parse_string(String text, ... options) >>

Parses C<text>. Returns an array of quads, or the supplied C<into> store
after adding the quads. Throws C<RDFSyntaxError> on invalid input.

=item C<< parse_file(path, ... options) >>

Reads UTF-8 from C<path> and parses it.

=item C<< parse_lines(Array lines, ... options) >>

Parses concatenated line chunks.

=item C<< parse_chunks(Array chunks, ... options) >>

Parses concatenated string or nested-array chunks.

=back

=back

=head1 COPYRIGHT AND LICENCE

B<< rdf/parser/ntriples >> is copyright Toby Inkster.

It is free software; you may redistribute it and/or modify it under
the terms of either the Artistic License 1.0 or the GNU General Public
License version 2.

=cut

from rdf/parser import RdfParser;
from rdf/parser/common import RDFReader, _parser_result;

class NTriplesParser with RdfParser {
	method parse_string ( String text, ... PairList options ) {
		return _parser_result(
			( new RDFReader(source: text) ).read_nt_all(false),
			options,
		);
	}
}