Subject: | How to get a MARC::Record object into Catmandu? |
Date: | Wed, 27 Nov 2013 11:20:27 +0100 |
To: | bug-Catmandu-MARC [...] rt.cpan.org |
From: | Magnus Enger <magnus [...] enger.priv.no> |
Hi!
*** Background
We want to make it possible to automatically convert MARC records from
Koha into RDF and save them in a triplestore, as they are being edited
and saved in Koha.
*** First attempt
Here is one way we have thought about doing it:
https://gitorious.org/koha-marc2rdf/koha-marc2rdf/source/7c863b4ef1289b987f1303a7996eef95512fed4a:lib/Koha/MARC2RDF.pm
Using Catmandu::RDF looks much nicer, though...
Here is where that code gets used in the workflow:
https://gitorious.org/koha/mainline/commit/ff19b7040d550811ec0f5eaee93f6fb6c6f9a014
Basically what happens is that we get MARC data from somwhere (the
cataloging screen or a command line import script) in the form of a
MARC::Record object. After serializing and saving the MARC to MySQL,
we want to convert it to RDF and push that version to a triplestore.
*** Problem
How do we get our MARC::Record object into Catmandu and
specifically Catmandu::RDF? As far as I can see, Catmandu::Importer::MARC
is mostly about getting MARC from files...
*** Possible solution 1
Make it possible to pass a MARC::Record object (or an array of such
objects) to Catmandu::Importer::MARC, something like:
my $records = Catmandu::Importer::MARC->new(
marc_object => $record,
);
(Where $record is a MARC::Record object.)
*** Possible solution 2
Abstract out the parts of Catmandu::Importer::MARC that turns a
MARC::Record into the internal data structure of Catmandu (an array
of arrays, I believe?), into a function that could be used to turn
a MARC::Record into a Catmandu structure that could be passed directly
to Catmandu::Exporter::RDF, something like:
$marc_as_structure = marcobecject2marcstructure( $record );
my $exporter = Catmandu::Exporter::RDF->new(
type => 'Turtle',
fix => 'marc2rdf.fix'
);
$exporter->add( $marc_as_structure );
*** Conclusion
Any thoughts on what would be the best solution and how doable it
would be?
Best regards,
Magnus Enger