NAME

RDF::RDB2RDF::DirectMapping - map relational database to RDF directly

SYNOPSIS

my $mapper = RDF::RDB2RDF->new('DirectMapping',
  prefix => 'http://example.net/data/');
print $mapper->process_turtle($dbh);

DESCRIPTION

This module makes it stupidly easy to dump a relational SQL database as an RDF graph, but at the cost of flexibility. Other than providing a base prefix for class, property and instance URIs, all mapping is done automatically, with very little other configuration at all.

This class offers support for the W3C Direct Mapping, based on the 20 Sept 2011 working draft.

Constructor

  • RDF::RDB2RDF::DirectMapping->new([prefix => $prefix_uri] [, %opts])

  • RDF::RDB2RDF->new('DirectMapping' [, prefix => $prefix_uri] [, %opts])

The prefix defaults to the empty string - i.e. relative URIs.

Two extra options are supported: rdfs which controls whether extra Tbox statements are included in the mapping; warn_sql carps statements to STDERR whenever the database is queried.

Methods

  • process($source [, $destination])

    Given a database handle, produces RDF data. Can optionally be passed a destination for triples: either an existing model to add data to, or a reference to a callback function.

    $source can be a DBI database handle, or an arrayref pair of a handle plus a schema name.

    $destination = sub {
      print $_[0]->as_string . "\n";
    };
    $dbh    = DBI->connect('dbi:Pg:dbname=mytest');
    $schema = 'fred';
    $mapper->process([$dbh, $schema], $destination);

    Returns the destination.

  • process_turtle($dbh, %options)

    As per process, but returns a string in Turtle format.

    Returns a string.

  • handle_table($source, $destination, $table, [\%where], [\@cols])

    As per process but must always be passed an explicit destination (doesn't return anything useful), and only processes a single table.

    If %where is provided, selects only certain rows from the table. Hash keys are column names, hash values are column values.

    If @cols is provided, selects only particular columns. (The primary key columns will always be selected.)

    This method allows you to generate predictable subsets of the mapping output. It's used fairly extensively by RDF::RDB2RDF::DirectMapping::Store.

  • handle_table_sql($source, $destination, $table)

    As per handle_table but only generates the RDFS/OWL schema data. Note that handle_table already includes this data (unless %where or @cols was passed to it).

    If the rdfs option passed to the constructor was not true, then there will be no RDFS/OWL schema data generated.

SEE ALSO

RDF::Trine, RDF::RDB2RDF.

RDF::RDB2RDF::DirectMapping::Store.

http://perlrdf.org/.

http://www.w3.org/TR/2011/WD-rdb-direct-mapping-20110920/.

AUTHOR

Toby Inkster <tobyink@cpan.org>.

COPYRIGHT

Copyright 2011 Toby Inkster

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