RDF::aREF::Encoder(3pm) | User Contributed Perl Documentation | RDF::aREF::Encoder(3pm) |
RDF::aREF::Encoder - encode RDF to another RDF Encoding Form
use RDF::aREF::Encoder; my $encoder = RDF::aREF::Encoder->new; # encode parts of aREF my $qname = $encoder->qname('http://schema.org/Review'); # 'schema_Review' my $predicate = $encoder->predicate({ type => 'uri', value => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' }); # 'a' my $object = $encoder->object({ type => 'literal', value => 'hello, world!', lang => 'en' }); # 'hello, world!@en' # method also accepts RDF::Trine::Node instances my $object = $encoder->object( RDF::Trine::Resource->new($iri) ); # encode RDF graphs (see also function 'encode_aref' in RDF::aREF) use RDF::Trine::Parser; my $aref = { }; RDF::Trine::Parser->parse_file ( $base_uri, $fh, sub { my $s = shift; $encoder->triple( $s->subject, $s->predicate, $s->object, $aref ); } );
This module provides methods to encode RDF data in another RDF Encoding Form (aREF). As aREF was designed to facilitate creation of RDF data, it may be easier to create aREF "by hand" instead of using this module!
A default namespace map, given as version string of module RDF::NS for stable qNames or as instance of RDF::NS. The most recent installed version of RDF::NS is used by default. The value 0 can be used to only use required namespace mappings (rdf, rdfs, owl and xsd).
By default RDF graphs with common subject are encoded as aREF predicate map:
{ _id => $subject, $predicate => $object }
Enable this option to always encode as aREF subject map:
{ $subject => { $predicate => $object } }
Note that no syntax checking is applied, e.g. whether a given URI is a valid URI or whether a given language is a valid language tag!
Abbreviate an URI as qName or return "undef". For instance "http://purl.org/dc/terms/title" is abbreviated to ""dct_title"".
Abbreviate an URI or as qName or enclose it in angular brackets.
Encode a literal RDF node by either appending ""@"" and an optional language tag, or ""^"" and an datatype URI.
Encode a blank node by prepending ""_:"" to its identifier.
Encode an RDF subject, predicate, or object respectively. The argument must either be given as hash reference, as defined in RDF/JSON <http://www.w3.org/TR/rdf-json/> format (see also method "as_hashref" of RDF::Trine::Model), or as array reference as internally used by RDF::Trine.
A hash reference is expected to have the following fields:
An array reference is expected to consists of
Encode an RDF triple, its elements given as explained for method "subject", "predicate", and "object". If an aREF data structure is given as fourth argument, the triple is added to this structure, possibly changing an aREF predicate map to an aRef subject map. Returns "undef" on failure.
Add RDF given in RDF/JSON <http://www.w3.org/TR/rdf-json/> format (as returned by method "as_hashref" in RDF::Trine::Model).
Add a RDF::Trine::Iterator to an aREF subject map.
experimental
RDF::aREF::Decoder, RDF::Trine::Node
2022-12-07 | perl v5.36.0 |