NAME¶
RDF::aREF::Encoder - encode RDF to another RDF Encoding Form
SYNOPSIS¶
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(
'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 {
$encoder->add_triple( $aref, $_[0] );
} );
DESCRIPTION¶
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!
OPTIONS¶
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).
METHODS¶
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!
qname( $uri )¶
Abbreviate an URI as qName or return "undef". For instance
"
http://purl.org/dc/terms/title" is abbreviated to
""dct_title"".
uri( $uri )¶
Abbreviate an URI or as qName or enclose it in angular brackets.
predicate( $uri )¶
Return an predicate URI as qNamem, as ""a"", or as given
URI.
literal( $value, $language_tag, $datatype_uri )¶
Encode a literal RDF node by either appending ""@"" and an
optional language tag, or ""^"" and an datatype URI.
bnode( $identifier )¶
Encode a blank node by prepending ""_:"" to its identifier.
object( $object )¶
Encode an RDF object given either 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 in array reference as
internally used by RDF::Trine.
A hash reference is expected to have the following fields:
- type
- one of "uri", "literal" or "bnode"
(required)
- value
- the URI of the object, its lexical value or a blank node label depending
on whether the object is a uri, literal or bnode
- lang
- the language of a literal value (optional but if supplied it must not be
empty)
- datatype
- 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,
- •
- two elements ""BLANK"" and the blank node identifier
for blank nodes.
add_triple( $aref, $statement )¶
Add a RDF::Trine::Stament to an aREF subject map.
experimental
add_iterator( $aref, $iterator )¶
Add a RDF::Trine::Iterator to an aREF subject map.
experimental
add_objects( $predicate_map, $predicate, $objects )¶
experimental
add_hashref( $aref, $rdf )¶
Add RDF given in RDF/JSON <
http://www.w3.org/TR/rdf-json/> format (as
returned by method "as_hashref" in RDF::Trine::Model).
experimental
SEE ALSO¶
RDF::aREF::Decoder, RDF::Trine::Node