RDF::Lazy::Tutorial - Tutorial to get started with RDF::Lazy
version 0.071
The basic object in RDF::Lazy is a node (RDF::Lazy::Node). A node represents an RDF node in an RDF graph. Every nody can be stringified to its value:
"$x" Perl syntax [% x %] Template Toolkit syntax {$x} Smarty syntax
There are three kinds of nodes:
implemented by RDF::Lazy::Resource and stringified to their URI, for instance http://example.org/foo.
http://example.org/foo
implemented by RDF::Lazy::Literal and stringified to their string value. instance hello world.
hello world
implemented by RDF::Lazy::Literal and stringified to _: followed by their internal blank node identifier, for instance _:n0815.
_:
_:n0815
Nodes have a couple of useful methods. For instance you can check the kind of a node x with the methods is_resource (or its alias is_uri), is_literal, and is_blank:
x
is_resource
is_uri
is_literal
is_blank
$x->is_literal Perl syntax [% x.is_literal %] Template Toolkit syntax {$x->is_literal} or {$x.is_literal} Smarty syntax
The method str is automatically called to stringify a node, so "$x" and <$x-str>> are equivalent. In HTML templates you can use the method esc to HTML/XML-escape the stringified node value:
str
"$x"
<$x-
esc
[% x.esc %] Template Toolkit syntax {$x->esc} or {$x.esc} Smarty syntax
Each node in RDF::Lazy belongs to a particular RDF graph (RDF::Lazy). You can access a node's graph by its graph method, if needed. Graphs have some factory methods to create new node objects:
graph
$g->uri("http://example.org/foo") A resource node, belonging to $g $g->literal("hello world") A literal node, belonging to $g $g->blank("n0815") A blank node, belonging to $g
The graph methods ttl and ttlpre are handy o dump the whole graph in Turtle syntax. The latter wraps and escapes Turtle for HTML output:
ttl
ttlpre
[% g.ttlpre %]
For instance you can show the number of triples in a node's graph like this:
<p>The node's graph contains [% x.graph.size %] triples.</p>
One can traverse the RDF graph from any node. For instance, given a foaf:Person node, one can get another resource linked via foaf:knows:
foaf:Person
foaf:knows
if ( $x->type('foaf:Person') ) { $another_person = $x->foaf_knows; }
Jakob Voß <voss@gbv.de>
This software is copyright (c) 2011 by Jakob Voß.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install RDF::Lazy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm RDF::Lazy
CPAN shell
perl -MCPAN -e shell install RDF::Lazy
For more information on module installation, please visit the detailed CPAN module installation guide.