Debian Codegraph @

README

raw
1 NAME
2 XML::Atom::OWL - parse an Atom file into RDF
3
4 SYNOPSIS
5 use XML::Atom::OWL;
6
7 $parser = XML::Atom::OWL->new($xml, $baseuri);
8 $graph = $parser->graph;
9
10 DESCRIPTION
11 This has a pretty similar interface to RDF::RDFa::Parser.
12
13 Constructor
14 `new($xml, $baseuri, \%options, $storage)`
15 This method creates a new XML::Atom::OWL object and returns it.
16
17 The $xml variable may contain an XML (Atom) string, or an
18 XML::LibXML::Document object. If a string, the document is parsed
19 using XML::LibXML, which will throw an exception if it is not
20 well-formed. XML::Atom::OWL does not catch the exception.
21
22 The base URI is used to resolve relative URIs found in the document.
23
24 Currently only one option is defined, 'no_fetch_content_src', a
25 boolean indicating whether <content src> URLs should be automatically
26 fetched and added to the model as if inline content had been provided.
27 They are fetched by default, but it's pretty rare for feeds to include
28 this attribute.
29
30 $storage is an RDF::Trine::Storage object. If undef, then a new
31 temporary store is created.
32
33 Public Methods
34 `uri`
35 Returns the base URI of the document being parsed. This will usually
36 be the same as the base URI provided to the constructor.
37
38 Optionally it may be passed a parameter - an absolute or relative URI
39 - in which case it returns the same URI which it was passed as a
40 parameter, but as an absolute URI, resolved relative to the document's
41 base URI.
42
43 This seems like two unrelated functions, but if you consider the
44 consequence of passing a relative URI consisting of a zero-length
45 string, it in fact makes sense.
46
47 `dom`
48 Returns the parsed XML::LibXML::Document.
49
50 `graph`
51 This method will return an RDF::Trine::Model object with all
52 statements of the full graph.
53
54 This method automatically calls `consume`.
55
56 `root_identifier`
57 Returns the blank node or URI for the root element of the Atom
58 document as an RDF::Trine::Node
59
60 Calls `consume` automatically.
61
62 `set_callbacks(\%callbacks)`
63 Set callback functions for the parser to call on certain events. These
64 are only necessary if you want to do something especially unusual.
65
66 $p->set_callbacks({
67 'pretriple_resource' => sub { ... } ,
68 'pretriple_literal' => sub { ... } ,
69 'ontriple' => undef ,
70 });
71
72 For details of the callback functions, see the section CALLBACKS.
73 `set_callbacks` must be used *before* `consume`. `set_callbacks`
74 itself returns a reference to the parser object itself.
75
76 `consume`
77 The document is parsed. Triples extracted from the document are passed
78 to the callbacks as each one is found; triples are made available in
79 the model returned by the `graph` method.
80
81 This function returns the parser object itself, making it easy to
82 abbreviate several of XML::Atom::OWL's functions:
83
84 my $iterator = XML::Atom::OWL->new(undef, $uri)
85 ->consume->graph->as_stream;
86
87 You probably only need to call this explicitly if you're using
88 callbacks.
89
90 CALLBACKS
91 Several callback functions are provided. These may be set using the
92 `set_callbacks` function, which taskes a hashref of keys pointing to
93 coderefs. The keys are named for the event to fire the callback on.
94
95 pretriple_resource
96 This is called when a triple has been found, but before preparing the
97 triple for adding to the model. It is only called for triples with a
98 non-literal object value.
99
100 The parameters passed to the callback function are:
101
102 * A reference to the `XML::Atom::OWL` object
103
104 * A reference to the `XML::LibXML::Element` being parsed
105
106 * Subject URI or bnode (string)
107
108 * Predicate URI (string)
109
110 * Object URI or bnode (string)
111
112 * Graph URI or bnode (string or undef)
113
114 The callback should return 1 to tell the parser to skip this triple (not
115 add it to the graph); return 0 otherwise.
116
117 pretriple_literal
118 This is the equivalent of pretriple_resource, but is only called for
119 triples with a literal object value.
120
121 The parameters passed to the callback function are:
122
123 * A reference to the `XML::Atom::OWL` object
124
125 * A reference to the `XML::LibXML::Element` being parsed
126
127 * Subject URI or bnode (string)
128
129 * Predicate URI (string)
130
131 * Object literal (string)
132
133 * Datatype URI (string or undef)
134
135 * Language (string or undef)
136
137 * Graph URI or bnode (string or undef)
138
139 Beware: sometimes both a datatype *and* a language will be passed. This
140 goes beyond the normal RDF data model.)
141
142 The callback should return 1 to tell the parser to skip this triple (not
143 add it to the graph); return 0 otherwise.
144
145 ontriple
146 This is called once a triple is ready to be added to the graph. (After the
147 pretriple callbacks.) The parameters passed to the callback function are:
148
149 * A reference to the `XML::Atom::OWL` object
150
151 * A reference to the `XML::LibXML::Element` being parsed
152
153 * An RDF::Trine::Statement object.
154
155 The callback should return 1 to tell the parser to skip this triple (not
156 add it to the graph); return 0 otherwise. The callback may modify the
157 RDF::Trine::Statement object.
158
159 BUGS
160 Please report any bugs to <http://rt.cpan.org/>.
161
162 SEE ALSO
163 RDF::Trine, XML::Atom::FromOWL.
164
165 <http://www.perlrdf.org/>.
166
167 AUTHOR
168 Toby Inkster <[email protected]>.
169
170 COPYRIGHT AND LICENCE
171 Copyright 2010-2011 Toby Inkster
172
173 This library is free software; you can redistribute it and/or modify it
174 under the same terms as Perl itself.
175
176 DISCLAIMER OF WARRANTIES
177 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
178 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
179 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
180