# NAME

RDF::Lazy - Lazy typing access to RDF data

# VERSION

version 0.06

# SYNOPSIS

  ### How to create a graph

  $g = RDF::Lazy->new(
     rdf        => $data,    # RDF::Trine::Model or ::Store (by reference)
     namespaces => {         # namespace prefix or RDF::Trine::NamespaceMap
         foaf => 'http://xmlns.com/foaf/0.1/',
         rdf  => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
         xsd  => "http://www.w3.org/2001/XMLSchema#",
     }
  );

  $g = RDF::Lazy->new( $data, format => 'turtle' );  # parse RDF/Turtle
  $g = RDF::Lazy->new( $data, format => 'rdfxml' );  # parse RDF/XML

  ### How to get nodes

  $p = $f->resource('http://xmlns.com/foaf/0.1/Person'); # get node
  $p = $f->uri('<http://xmlns.com/foaf/0.1/Person>');    # alternatively
  $p = $f->uri('foaf:Person);                            # same but lazier
  $p = $f->foaf_Person;                                  # same but laziest

  $l = $g->literal('Alice');              # get literal node
  $l = $g->literal('Alice','en');         # get literal node with language
  $l = $g->literal('123','xsd:integer');  # get literal node with datatype

  $b = $g->blank('x123');   # get blank node
  $b = $g->blank;           # get blank node with random id

  ### How to retrieve RDF

  $x->rel('foaf:knows');    # retrieve a person that $x knows
  $x->rev('foaf:knows');    # retrieve a person known by $x

  $x->rels('foaf:knows');   # retrieve all people that $x knows
  $x->rel_('foaf:knows');   # same

  $x->revs('foaf:knows');   # retrieve all people known by $x
  $x->rev_('foaf:knows');   # same

  $x->foaf_knows;           # short form of $x->rel('foaf:knows')
  $x->foaf_knows_;          # short form of $x->rels('foaf:knows')

  $x->rels;                 # array reference with a list of properties
  $x->revs;                 # same as rels, but other direction

  $x->type;                 # same as $x->rel('rdf:type')
  $x->types;                # same as $x->rels('rdf:type')

  $g->subjects( 'rdf:type', 'foaf:Person' );  # retrieve subjects
  $g->predicates( $subject, $object );        # list predicates
  $g->objects( $subject, 'foaf:knows' );      # list objects

  ### How to add RDF

  $g->add( $rdfdata, format => 'rdfxml' );    # parse and add
  $g->add( $subject, $predicate, $object );   # add single triple

  ### How to show RDF

  $g->ttl;     # dump in RDF/Turtle syntax
  $g->ttlpre;  # dump in RDF/Turtle, wrapped in a HTML <pre> tag

# DESCRIPTION

This module wraps [RDF::Trine::Node](http://search.cpan.org/perldoc?RDF::Trine::Node) to provide simple node-centric access to
RDF data. It was designed to access RDF within [Template](http://search.cpan.org/perldoc?Template) Toolkit but the
module does not depend on or and can be used independently. Basically, an
instance of RDF::Lazy contains an unlabeled RDF graph and a set of namespace
prefixes. For lazy access and graph traversal, each RDF node
([RDF::Lazy::Node](http://search.cpan.org/perldoc?RDF::Lazy::Node)) is tied to the graph.

# METHODS

## new ( [ [ rdf => ] $rdf ] [, namespaces => $namespaces ] [ %options ])

Return new RDF graph. Namespaces can be provided as hash reference or as
[RDF::Trine::NamespaceMap](http://search.cpan.org/perldoc?RDF::Trine::NamespaceMap). RDF data can be L<RDF:Trine::Model> or
[RDF::Trine::Store](http://search.cpan.org/perldoc?RDF::Trine::Store), which are used by reference, or many other forms,
as supported by [add](#pod_add).

## resource ( $uri )

Return [RDF::Lazy::Resource](http://search.cpan.org/perldoc?RDF::Lazy::Resource) node. The following statements are equivalent:

    $graph->resource('http://example.org');
    $graph->uri('<http://example.org>');

## literal ( $string , $language_or_datatype, $datatype )

Return [RDF::Lazy::Literal](http://search.cpan.org/perldoc?RDF::Lazy::Literal) node.

## blank ( [ $identifier ] )

Return [RDF::Lazy::Blank](http://search.cpan.org/perldoc?RDF::Lazy::Blank) node. A random identifier is generated unless you
provide an identifier as parameter.

## uri ( $name | $node )

Returns a node that is connected to the graph. Note that every valid RDF node
is part of any RDF graph: this method does not check whether the graph actually
contains a triple with the given node. You can either pass a name or an
instance of [RDF::Trine::Node](http://search.cpan.org/perldoc?RDF::Trine::Node). This method is also called for any undefined
method, so the following statements are equivalent:

    $graph->true;
    $graph->uri('true');

## rel / rels / rev / revs

Can be used to traverse the graph. See [RDF::Lazy::Node](http://search.cpan.org/perldoc?RDF::Lazy::Node):

    $node->rel( ... )           # where $node is located in $graph
    $graph->rel( $node, ... )   # equivalent

## add

Add RDF data. _Sorry, not documented yet!_

## ttl ( [ $node ] )

Returns a RDF/Turtle representation of a node's bounded description.

## ttlpre ( [ $node ] )

Returns an HTML escaped RDF/Turtle representation of a node's bounded
description, wrapped in a HTML `<pre class="turtle">` element.

# SEE ALSO

[RDF::Helper](http://search.cpan.org/perldoc?RDF::Helper) and [RDF::TrineShortcuts](http://search.cpan.org/perldoc?RDF::TrineShortcuts) provide similar APIs.

# AUTHOR

Jakob Voß <voss@gbv.de>

# COPYRIGHT AND LICENSE

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.