RDF::Trine::Parser(3) RDF Parser class

VERSION

This document describes RDF::Trine::Parser version 1.014

SYNOPSIS


use RDF::Trine::Parser;

RDF::Trine::Parser->parse_url_into_model( $url, $model );

my $parser = RDF::Trine::Parser->new( 'turtle' );
$parser->parse_into_model( $base_uri, $rdf, $model );

$parser->parse_file_into_model( $base_uri, 'data.ttl', $model );

DESCRIPTION

RDF::Trine::Parser is a base class for RDF parsers. It may be used as a factory class for constructing parser objects by name or media type with the "new" method, or used to abstract away the logic of choosing a parser based on the media type of RDF content retrieved over the network with the "parse_url_into_model" method.

METHODS

"media_type"
Returns the canonical media type associated with this parser.
"media_types"
Returns the media types associated with this parser.
"parser_by_media_type ( $media_type )"
Returns the parser class appropriate for parsing content of the specified media type. Returns undef if not appropriate parser is found.
"guess_parser_by_filename ( $filename )"
Returns the best-guess parser class to parse a file with the given filename. Defaults to RDF::Trine::Parser::RDFXML if not appropriate parser is found.
"new ( $parser_name, @args )"
Returns a new RDF::Trine::Parser object for the parser with the specified name (e.g. ``rdfxml'' or ``turtle''). If no parser with the specified name is found, throws a RDF::Trine::Error::ParserError exception.

Any @args will be passed through to the format-specific parser constructor.

If @args contains the key-value pair "(canonicalize => 1)", literal value canonicalization will be attempted during parsing with warnings being emitted for invalid lexical forms for recognized datatypes.

"parse_url_into_model ( $url, $model [, %args] )"
Retrieves the content from $url and attempts to parse the resulting RDF into $model using a parser chosen by the associated content media type.

If %args contains a 'content_cb' key with a CODE reference value, that callback function will be called after a successful response as:

 $content_cb->( $url, $content, $http_response_object )

If %args contains a 'useragent' key with a LWP::UserAgent object value, that object is used to retrieve the requested URL without any configuration (such as setting the Accept: header) which would ordinarily take place. Otherwise, the default user agent (``default_useragent'' in RDF::Trine) is cloned and configured to retrieve content that will be acceptable to any available parser.

"parse_url ( $url, \&handler [, %args] )"
Retrieves the content from $url and attempts to parse the resulting RDF. For each parsed RDF triple that is parsed, &handler will be called with the triple as an argument. Otherwise, this method acts just like "parse_url_into_model".
"parse_into_model ( $base_uri, $data, $model [, context => $context] )"
Parses the bytes in $data, using the given $base_uri. For each RDF statement parsed, will call "$model->add_statement( $statement )".
"parse_file_into_model ( $base_uri, $fh, $model [, context => $context] )"
Parses all data read from the filehandle or file $fh, using the given $base_uri. For each RDF statement parsed, will call "$model->add_statement( $statement )".
"parse_file ( $base_uri, $fh, $handler )"
Parses all data read from the filehandle or file $fh, using the given $base_uri. If $fh is a filename, this method can guess the associated parse. For each RDF statement parsed, "$handler->( $st )" is called.
"parse ( $base_uri, $rdf, \&handler )"
"new_bnode_prefix ()"
Returns a new prefix to be used in the construction of blank node identifiers. If either Data::UUID or UUID::Tiny are available, they are used to construct a globally unique bnode prefix. Otherwise, an empty string is returned.
"default_accept_header"
Returns the default HTTP Accept header value used in requesting RDF content (e.g. in ``parse_url_into_model'') that may be parsed by one of the available RDF::Trine::Parser subclasses.

By default, RDF/XML and Turtle are preferred over other media types.

BUGS

Please report any bugs or feature requests to through the GitHub web interface at <https://github.com/kasei/perlrdf/issues>.

AUTHOR

Gregory Todd Williams "<[email protected]>"

COPYRIGHT

Copyright (c) 2006-2012 Gregory Todd Williams. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.