modules/rdf/parser/nquads.zzm

rdf-0.0.3 source code

=encoding utf8

=head1 NAME

rdf/parser/nquads - N-Quads parser.

=head1 SYNOPSIS

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


=head1 DESCRIPTION

C<NQuadsParser> parses RDF 1.1 N-Quads into RDF quads. Lines without an
explicit graph are loaded into the default graph. It accepts C<base> and
C<into> parser options for consistency with the other RDF parsers, though
N-Quads requires absolute IRIs.

=head1 EXPORTS

=head2 Classes

=over

=item C<NQuadsParser>

=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/nquads >> 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 NQuadsParser with RdfParser {
	method parse_string ( String text, ... PairList options ) {
		return _parser_result(
			( new RDFReader(source: text) ).read_nt_all(true),
			options,
		);
	}
}