Debian Codegraph @

README

raw
1 NAME
2 HTML::Embedded::Turtle - embedding RDF in HTML the crazy way
3
4 SYNOPSIS
5 use HTML::Embedded::Turtle;
6
7 my $het = HTML::Embedded::Turtle->new($html, $base_uri);
8 foreach my $graph ($het->endorsements)
9 {
10 my $model = $het->graph($graph);
11
12 # $model is an RDF::Trine::Model. Do something with it.
13 }
14
15 DESCRIPTION
16 RDF can be embedded in (X)HTML using simple <script> tags. This is
17 described at <http://esw.w3.org/N3inHTML>. This gives you a file format
18 that can contain multiple (optionally named) graphs. The document as a
19 whole can "endorse" a graph by including:
20
21 <link rel="meta" href="#foo" />
22
23 Where "#foo" is a fragment identifier pointing to a graph.
24
25 <script type="text/turtle" id="foo"> ... </script>
26
27 The rel="meta" stuff is parsed using an RDFa parser, so equivalent RDFa
28 works too.
29
30 This module parses HTML files containing graphs like these, and allows
31 you to access them each individually; as a union of all graphs on the
32 page; or as a union of just the endorsed graphs.
33
34 Despite the module name, this module supports a variety of <script
35 type>s: text/turtle, application/turtle, application/x-turtle text/plain
36 (N-Triples), text/n3 (Notation 3), application/x-rdf+json (RDF/JSON),
37 application/json (RDF/JSON), and application/rdf+xml (RDF/XML).
38
39 The deprecated attribute "language" is also supported:
40
41 <script language="Turtle" id="foo"> ... </script>
42
43 Languages supported are (case insensitive): "Turtle", "NTriples",
44 "RDFJSON", "RDFXML" and "Notation3".
45
46 Constructor
47 "HTML::Embedded::Turtle->new($markup, $base_uri, \%opts)"
48 Create a new object. $markup is the HTML or XHTML markup to parse;
49 $base_uri is the base URI to use for relative references.
50
51 Options include:
52
53 * markup
54
55 Choose which parser to use: 'html' or 'xml'. The former chooses
56 HTML::HTML5::Parser, which can handle tag soup; the latter
57 chooses XML::LibXML, which cannot. Defaults to 'html'.
58
59 * rdfa_options
60
61 A set of options to be parsed to RDF::RDFa::Parser when looking
62 for endorsements. See RDF::RDFa::Parser::Config. The default is
63 probably sensible.
64
65 Public Methods
66 "union_graph"
67 A union graph of all graphs found in the document, as an
68 RDF::Trine::Model. Note that the returned model contains quads.
69
70 "endorsed_union_graph"
71 A union graph of only the endorsed graphs, as an RDF::Trine::Model.
72 Note that the returned model contains quads.
73
74 "graph($name)"
75 A single graph from the page.
76
77 "graphs"
78 "all_graphs"
79 A hashref where the keys are graph names and the values are
80 RDF::Trine::Models. Some graph names will be URIs, and others may be
81 blank nodes (e.g. "_:foobar").
82
83 "graphs" and "all_graphs" are aliases for each other.
84
85 "endorsed_graphs"
86 Like "all_graphs", but only returns endorsed graphs. Note that all
87 endorsed graphs will have graph names that are URIs.
88
89 "endorsements"
90 Returns a list of URIs which are the names of endorsed graphs. Note
91 that the presence of a URI $x in this list does not imply that
92 "$het->graph($x)" will be defined.
93
94 "dom"
95 Returns the page DOM.
96
97 "uri"
98 Returns the page URI.
99
100 BUGS
101 Please report any bugs to <http://rt.cpan.org/>.
102
103 Please forgive me in advance for inflicting this module upon you.
104
105 SEE ALSO
106 RDF::RDFa::Parser, RDF::Trine, RDF::TriN3.
107
108 <http://www.perlrdf.org/>.
109
110 AUTHOR
111 Toby Inkster <[email protected]>.
112
113 COPYRIGHT AND LICENSE
114 Copyright (C) 2010-2011, 2013 by Toby Inkster.
115
116 This is free software; you can redistribute it and/or modify it under
117 the same terms as the Perl 5 programming language system itself.
118
119 DISCLAIMER OF WARRANTIES
120 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
121 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
122 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
123