The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

RDF::Lazy - Lazy typing access to RDF data

VERSION

version 0.063

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->revs('foaf:knows');   # retrieve all people known by $x

  $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->turtle;  # dump in RDF/Turtle syntax
  $g->ttlpre;  # dump in RDF/Turtle, wrapped in a HTML <pre> tag
  $g->rdfxml;  # dump in RDF/XML
  $g->rdfjson; # dump in RDF/JSON

DESCRIPTION

This module wraps RDF::Trine::Node to provide simple node-centric access to RDF data. It was designed to access RDF within 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) 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. RDF data can be RDF:Trine::Model or RDF::Trine::Store, which are used by reference, or many other forms, as supported by add.

resource ( $uri )

Return 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 node.

blank ( [ $identifier ] )

Return 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. 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:

    $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 and 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.