HTML::Embedded::Turtle(3pm) | User Contributed Perl Documentation | HTML::Embedded::Turtle(3pm) |
HTML::Embedded::Turtle - embedding RDF in HTML the crazy way
use HTML::Embedded::Turtle; my $het = HTML::Embedded::Turtle->new($html, $base_uri); foreach my $graph ($het->endorsements) { my $model = $het->graph($graph); # $model is an RDF::Trine::Model. Do something with it. }
RDF can be embedded in (X)HTML using simple <script> tags. This is described at <http://esw.w3.org/N3inHTML>. This gives you a file format that can contain multiple (optionally named) graphs. The document as a whole can "endorse" a graph by including:
<link rel="meta" href="#foo" />
Where "#foo" is a fragment identifier pointing to a graph.
<script type="text/turtle" id="foo"> ... </script>
The rel="meta" stuff is parsed using an RDFa parser, so equivalent RDFa works too.
This module parses HTML files containing graphs like these, and allows you to access them each individually; as a union of all graphs on the page; or as a union of just the endorsed graphs.
Despite the module name, this module supports a variety of <script type>s: text/turtle, application/turtle, application/x-turtle text/plain (N-Triples), text/n3 (Notation 3), application/x-rdf+json (RDF/JSON), application/json (RDF/JSON), and application/rdf+xml (RDF/XML).
The deprecated attribute "language" is also supported:
<script language="Turtle" id="foo"> ... </script>
Languages supported are (case insensitive): "Turtle", "NTriples", "RDFJSON", "RDFXML" and "Notation3".
Options include:
Choose which parser to use: 'html' or 'xml'. The former chooses HTML::HTML5::Parser, which can handle tag soup; the latter chooses XML::LibXML, which cannot. Defaults to 'html'.
A set of options to be parsed to RDF::RDFa::Parser when looking for endorsements. See RDF::RDFa::Parser::Config. The default is probably sensible.
"graphs" and "all_graphs" are aliases for each other.
Please report any bugs to <http://rt.cpan.org/>.
Please forgive me in advance for inflicting this module upon you.
RDF::RDFa::Parser, RDF::Trine, RDF::TriN3.
<http://www.perlrdf.org/>.
Toby Inkster <tobyink@cpan.org>.
Copyright (C) 2010-2011, 2013 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2021-09-11 | perl v5.32.1 |