[librecat-dev] binder with MARC to MARC convertor

Patrick Hochstenbach Patrick.Hochstenbach at UGent.be
Mon Oct 3 07:53:08 CEST 2016


Yes.

A MARC record in Catmandu is just a ‘record’ key containing an array of arrays (one array for each MARC field). To make it easier to manipulate this array-of-arrays Catmandu marc_map, marc_add, marc_set etc fixes were created. 

There is a Bind marc_each() that loops over a MARC record (it loops over all the fields). You use this most often in combination with a marc_match condition:

do marc_each()
   # If the current field is 100 and matches some regex
   if marc_match(“100”,”.*”) 
       marc_map(100a,myfield)
       lookup(myfield,’list.csv’)
       marc_set(100a,$.myfield)
   end
end

The marc_each is only required when you do no-trivial things on repeated fields. The 100 field is usually not a repeated field so the Fix below would do exactly the same (and much faster):

marc_map(100a,myfield)
lookup(myfield,’list.csv’)
marc_set(100a,$.myfield)

The marc_add field adds new (sub)fields to the record. E.g. add a 101a to the MARC

marc_add(‘100', a, 'test’ )


or an 100a with indicators set:

marc_add(‘100', ‘ind1', 1 , ‘ind2', 4, ‘a', 'test’ )

Indicators are not required..in Catmandu that is..maybe they are in MARC for some fields but that is another topic

Patrick

> On 02 Oct 2016, at 23:34, Jason Loeffler <j at minorscience.com> wrote:
> 
> I've worked through CSV to JSON and JSON to JSON converters using binds in order to operate on an object-value pair using the contents of an external text file/dictionary. 
> 
> E.g. 
> 
> # linked_agents.ref
> do list(path => linked_agents)
>   add_field("foor","bar")
>   replace_all("ref","[^a-zA-z0-9\s]","");
>   lookup("ref","list.csv");
> end
> 
> This works very well. But is there a way to execute a similar task with a MARC to MARC conversion?
> 
> Something like firing a lookup in the marc_each context?
> 
> do marc_each()
>     lookup('some datafield', 'list.csv')
> end
> 
> Jason Loeffler
> Technology Consultant | The American Academy in Rome
> 
> _______________________________________________
> librecat-dev mailing list
> - send list mails to librecat-dev at lists.uni-bielefeld.de
> - to unsubscribe or change options, visit https://lists.uni-bielefeld.de/mailman2/cgi/unibi/listinfo/librecat-dev
> - project website: http://librecat.org/

Patrick Hochstenbach - digital architect
University Library Ghent
Sint-Hubertusstraat 8 - 9000 Ghent - Belgium
patrick.hochstenbach at ugent.be
+32 (0)9 264 7980




More information about the librecat-dev mailing list