
RDF::Redland::Model::ExifTool - extends RDF model to process Exif meta data

Version 0.09

use Image::ExifTool;
use RDF::Redland;
use RDF::Redland::Model::ExifTool;
# creates an RDF model in memory
$storage = new RDF::Redland::Storage("hashes", "exif_meta_data",
"new='yes',hash-type='memory'");
$model = new RDF::Redland::Model::ExifTool($storage, "");
$EMPTY_MODEL_N_STATEMENTS = $model->size;
# processes Exif meta data from each file into RDF statements
# in model and prints any errors
$exiftool = new Image::ExifTool;
foreach $file (@ARGV) {
$exiftool->ImageInfo($file, $model->get_exif_tags);
foreach $error ($model->add_exif_statements($exiftool)) {
print STDERR $error . "\n";
}
}
$model->sync;
# prints any RDF statements in model with Turtle syntax
if ($EMPTY_MODEL_N_STATEMENTS < $model->size) {
$serializer = new RDF::Redland::Serializer("turtle");
print $serializer->serialize_model_to_string(
new RDF::Redland::URINode("http://www.theflints.net.nz/"),
$model);
undef $serializer; # prevents librdf_serializer null exception
}
For a more complete example see script exif2rdf .

Exif meta data is in tag and value pairs. ExifTool reads, writes and updates Exif meta data stored in files. See also ExifTool web site http://www.sno.phy.queensu.ca/~phil/exiftool/. RDF meta data is in statements - subject, predicate or verb and object triples. Redland Libraries provide support for RDF.
This class extends the Redland set of RDF statements RDF::Redland::Model to process Exif meta data read from instances of ExifTool Image::ExifTool.
Sadly the version of Redland currently offered by CPAN is out of date and fails testing. For Debian or Fedora download the packages from the Redland RDF Libraries web site http://librdf.org/, for Ubuntu install package librdf-perl otherwise build from source.
This RDF model processes Exif meta data from a file read through an ExifTool as follows:
file:///...This class' configuration is a hash of data structures that can be set from a file (with "set_exif_config_from_file") or variable ("set_exif_config"). For example a variable configuration:
$config = {
ParseTag => ["Comment"],
ParseSyntax => ["turtle", "rdfxml"],
TranslateTag => {
Aperture =>
"http://www.w3.org/2003/12/exif/ns#apertureValue",
Comment => "http://www.w3.org/2003/12/exif/ns#userComment",
ISO => "http://www.w3.org/2003/12/exif/ns#ISOSpeedRatings",
ShutterSpeed =>
"http://www.w3.org/2003/12/exif/ns#shutterSpeedValue",
},
};
this configuration gets exposure data (Aperture, ISO and ShutterSpeed) then tries to parse RDF statements from any Comment value as Turtle or RDF/XML and failing that treats as text.
list of ExifTool tags whose values are parsed for RDF statements for example Comment.
If ParseTag is set then ParseSyntax must be too. TranslateTag must be set if ParseTag is not.
list of Redland RDF syntax used in parsing tag values for example rdfxml, ntriples, turtle and guess. See parse command on rdfproc man page for a list of syntax.
hash of ExifTool tag and equivalent RDF predicate.
exiftool -s my.jpg # lists all tag and value pairs in file my.jpg
exiftool -list # lists all ExifTool's tags
Predicates must be absolute HTTP URIs. ParseTag and ParseSyntax must be set if TranslateTag is not.
The default configuration gets meta data including: user comment, image description, date/time of creation, camera model and exposure.

Processes Exif meta data from list of ExifTools into RDF statements stored in this model using "Configuration".
Returns empty list if successful otherwise returns list of error strings.
Returns copy of this RDF model's "Configuration".
Returns list of ExifTool tags that can be processed by this RDF model, the tags in "Configuration".
By default ExifTool's ImageInfo gets all tags from a file. Getting the subset of tags that this model can process reduces the work ExifTool has to do. For example:
$exiftool->ImageInfo("my.jpg", $model->get_exif_tags)
asks ExifTool to get from my.jpg only those tag and value pairs that model can process.
Replaces this RDF model's "Configuration".
Returns empty list if configuration replaced otherwise returns list of error strings.
Replaces this RDF model's "Configuration" from configuration file.
Returns empty list if configuration replaced otherwise returns list of error strings.
For example this is the file equivalent of the example "Configuration":
# Note: URI anchor char '#' must be escaped '\#' or it is treated as comment
<TranslateTag>
Aperture http://www.w3.org/2003/12/exif/ns\#apertureValue
Comment http://www.w3.org/2003/12/exif/ns\#userComment
ISO http://www.w3.org/2003/12/exif/ns\#ISOSpeedRatings
ShutterSpeed http://www.w3.org/2003/12/exif/ns\#shutterSpeedValue
</TranslateTag>
ParseTag Comment
ParseSyntax turtle
ParseSyntax rdfxml

Andrew Flint, <arnhemcr at cpan.org>

Please report any bugs or feature requests to bug-rdf-redland-model-exiftool at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=RDF-Redland-Model-ExifTool. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

You can find documentation for this class with the perldoc command.
perldoc RDF::Redland::Model::ExifTool
You can also look for information at:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=RDF-Redland-Model-ExifTool

Copyright 2008 Andrew Flint, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.