1RDF::Trine::Parser(3) User Contributed Perl DocumentationRDF::Trine::Parser(3)
2
3
4
6 RDF::Trine::Parser - RDF Parser class
7
9 This document describes RDF::Trine::Parser version 1.019
10
12 use RDF::Trine::Parser;
13
14 RDF::Trine::Parser->parse_url_into_model( $url, $model );
15
16 my $parser = RDF::Trine::Parser->new( 'turtle' );
17 $parser->parse_into_model( $base_uri, $rdf, $model );
18
19 $parser->parse_file_into_model( $base_uri, 'data.ttl', $model );
20
22 RDF::Trine::Parser is a base class for RDF parsers. It may be used as a
23 factory class for constructing parser objects by name or media type
24 with the "new" method, or used to abstract away the logic of choosing a
25 parser based on the media type of RDF content retrieved over the
26 network with the "parse_url_into_model" method.
27
29 "media_type"
30 Returns the canonical media type associated with this parser.
31
32 "media_types"
33 Returns the media types associated with this parser.
34
35 "parser_by_media_type ( $media_type )"
36 Returns the parser class appropriate for parsing content of the
37 specified media type. Returns undef if not appropriate parser is
38 found.
39
40 "guess_parser_by_filename ( $filename )"
41 Returns the best-guess parser class to parse a file with the given
42 filename. Defaults to RDF::Trine::Parser::RDFXML if not
43 appropriate parser is found.
44
45 "new ( $parser_name, @args )"
46 Returns a new RDF::Trine::Parser object for the parser with the
47 specified name (e.g. "rdfxml" or "turtle"). If no parser with the
48 specified name is found, throws a RDF::Trine::Error::ParserError
49 exception.
50
51 Any @args will be passed through to the format-specific parser
52 constructor.
53
54 If @args contains the key-value pair "(canonicalize => 1)", literal
55 value canonicalization will be attempted during parsing with
56 warnings being emitted for invalid lexical forms for recognized
57 datatypes.
58
59 "parse_url_into_model ( $url, $model [, %args] )"
60 Retrieves the content from $url and attempts to parse the resulting
61 RDF into $model using a parser chosen by the associated content
62 media type.
63
64 If %args contains a 'content_cb' key with a CODE reference value,
65 that callback function will be called after a successful response
66 as:
67
68 $content_cb->( $url, $content, $http_response_object )
69
70 If %args contains a 'useragent' key with a LWP::UserAgent object
71 value, that object is used to retrieve the requested URL without
72 any configuration (such as setting the Accept: header) which would
73 ordinarily take place. Otherwise, the default user agent
74 ("default_useragent" in RDF::Trine) is cloned and configured to
75 retrieve content that will be acceptable to any available parser.
76
77 "parse_url ( $url, \&handler [, %args] )"
78 Retrieves the content from $url and attempts to parse the resulting
79 RDF. For each parsed RDF triple that is parsed, &handler will be
80 called with the triple as an argument. Otherwise, this method acts
81 just like "parse_url_into_model".
82
83 "parse_into_model ( $base_uri, $data, $model [, context => $context] )"
84 Parses the bytes in $data, using the given $base_uri. For each RDF
85 statement parsed, will call "$model->add_statement( $statement )".
86
87 "parse_file_into_model ( $base_uri, $fh, $model [, context => $context]
88 )"
89 Parses all data read from the filehandle or file $fh, using the
90 given $base_uri. For each RDF statement parsed, will call
91 "$model->add_statement( $statement )".
92
93 "parse_file ( $base_uri, $fh, $handler )"
94 Parses all data read from the filehandle or file $fh, using the
95 given $base_uri. If $fh is a filename, this method can guess the
96 associated parse. For each RDF statement parsed, "$handler->( $st
97 )" is called.
98
99 "parse ( $base_uri, $rdf, \&handler )"
100 "new_bnode_prefix ()"
101 Returns a new prefix to be used in the construction of blank node
102 identifiers. If either Data::UUID or UUID::Tiny are available,
103 they are used to construct a globally unique bnode prefix.
104 Otherwise, an empty string is returned.
105
106 "default_accept_header"
107 Returns the default HTTP Accept header value used in requesting RDF
108 content (e.g. in "parse_url_into_model") that may be parsed by one
109 of the available RDF::Trine::Parser subclasses.
110
111 By default, RDF/XML and Turtle are preferred over other media
112 types.
113
115 Please report any bugs or feature requests to through the GitHub web
116 interface at <https://github.com/kasei/perlrdf/issues>.
117
119 Gregory Todd Williams "<gwilliams@cpan.org>"
120
122 Copyright (c) 2006-2012 Gregory Todd Williams. This program is free
123 software; you can redistribute it and/or modify it under the same terms
124 as Perl itself.
125
126
127
128perl v5.30.0 2019-07-26 RDF::Trine::Parser(3)