RDF::Laces - A module to string together RDF statements from Perl syntax

SYNOPSIS

  $doc = new RDF::Laces('http://example.com/document/');
  $doc->foo("bar");        # make statement
  $doc->foo($doc->{bar});  # reference nodes within $doc
  $doc->()->foo("bar");    # use blank node in $doc
  $doc->{example} = $doc;  # create prefix
  $doc->example;           # set default prefix

DESCRIPTION

This module provides a healthy dose of syntactic sugar to the expression of RDF statements in Perl. Instead of forcing the mechanics of storage and representation inline with the statements made within a program, you can use a standard syntax for making RDF statements in Perl using regular Perl expressions and variables without regard to the model being used in the background, or the means to output it.

In order to create an RDF model, a series of RDF triples consisting of (subject, predicate, object) need to be constructed. The model is based on making a series of statements about a subject. In Perl, there needs to be an easy way to assert these statements inline with code.

Making Statements in Perl

The following examples assume the reader is familiar with the ntriple representation of RDF as recommended by the W3 Consortium.

In fact, we can demonstrate the examples from the W3's n3 primer.

    # <#pat> <#knows> <#jo> .
    $doc->{pat}->knows($doc->{jo});

This was a simple statement that pat knows jo. The knows method called on $doc->{pat} acted as the predicate for the statement, and is assumed to be a URI relative to the current $doc prefix. More on that below.

It's possible to make further statements about pat.

    $doc->{pat}
        ->knows($doc->{jo})
        ->age(24)
    ;

We've now made two statements about pat: pat knows jo, and pat age 24. This example shows how statements against the same subject can be chained into a single Perl expression.

Also, it's possible for a single predicate to have multiple objects.

    $doc->{pat}
        ->child($doc->{al}, $doc->{chaz}, $doc->{mo})
        ->age(24)
        ->eyecolor("blue")
    ;

In this way, it's possible to chain together an entire description of pat into a single Perl expression.

However, there are times when you want to reference data without an identifier. These blank RDF nodes are important containers for aggregate data and are available from the document.

    $doc->{pat}
        ->child(
            $doc->()
                ->age(4),
            $doc->(),
                ->age(3))
    ;

In that example, the $doc->() expression was creating blank nodes which had age statements made with them as the subject. Those nodes were returned to be listed as a child of pat.

Using Prefixes

Any document can use resources and attributes defined in another RDF document. To ease the use of these documents, they are often referenced using prefixes within the document; by xmlns in XML, and @prefix in n3.

In Perl, these prefixes can be created and used as well.

    $doc->{dc} = 'http://purl.org/dc/elements/1.1/';
    $doc
        ->dc
            ->title("POD - Learning to use RDF::Laces")
    ;

The prefix was created by assigning a URI (or an RDF::Laces object) to the name of the desired prefix, dc. By assigning to $doc->{dc}, it caused the dc to be interpreted as the name of a prefix that should be created.

Once a prefix is created, it's possible to use that prefix by calling it in the method chain without arguments. It's possible to set $doc's prefix permanently by calling $doc->dc or whatever the prefix's name you want is. Also, it is possible to use multiple prefixes per statement.

    $doc->()
        ->name("jo")
        ->rdf
            ->type($doc->{Person})
        ->rdfs
            ->range($doc->rdfs->{Resource})
            ->domain($doc->rdfs->{Resource})
    ;

TODO

Currently, this module only prints out the N3 statements created by a Perl expression. There will be a back-end interface for plugging in various RDF modules, such as RDF::Redland and RDF::Core. When it exists, it should be documented.

Also, this module may be doing stuff which needs to be documented. I dunno.

SEE ALSO

Check out RDF::Redland. And, of course, visit http://www.w3.org/ for a full description of RDF, n3, and all the other topics and terms discussed in this document.

AUTHOR

Ashley Winters

COPYRIGHT AND LICENSE

Copyright 2003 by Ashley Winters

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 159:

=pod directives shouldn't be over one line long! Ignoring all 2 lines of content