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).
0
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".
undef
http://purl.org/dc/terms/title
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 format (see also method as_hashref of RDF::Trine::Model), or as array reference as internally used by RDF::Trine.
as_hashref
A hash reference is expected to have the following fields:
one of uri, literal or bnode (required)
uri
literal
bnode
the URI of the object, its lexical value or a blank node label depending on whether the object is a uri, literal or bnode
the language of a literal value (optional but if supplied it must not be empty)
the datatype URI of the literal value (optional)
An array reference is expected to consists of
three elements (value, language tag, and datatype uri) for literal nodes,
two elements "URI" and the URI for URI nodes,
URI
two elements "BLANK" and the blank node identifier for blank nodes.
BLANK
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.
subject
predicate
object
Add RDF given in 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
To install RDF::aREF, copy and paste the appropriate command in to your terminal.
cpanm
cpanm RDF::aREF
CPAN shell
perl -MCPAN -e shell install RDF::aREF
For more information on module installation, please visit the detailed CPAN module installation guide.