Help-Site Computer Manuals
  Algorithms & Data Structures   Programming Languages   Revision Control
  Cameras   Computers   Displays   Keyboards & Mice   Motherboards   Networking   Printers & Scanners   Storage
  Windows   Linux & Unix   Mac

A module to string together RDF statements from Perl syntax

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



  $doc = new RDF::Laces('');

  $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


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


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.





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.


        ->child($doc->{al}, $doc->{chaz}, $doc->{mo})




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.








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} = '';



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










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.


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


Ashley Winters


Copyright 2003 by Ashley Winters
