[librecat-dev] string operations, defining functions in Catmandu

Patrick Hochstenbach Patrick.Hochstenbach at UGent.be
Fri Jun 30 08:58:49 CEST 2017

Alas there is currently no way to create your own named functions using only the Fix language (but there are some idea how this could be done). Alas, you need to copy and paste code for now.

The main use case was to transform MARC to something else ;). But there is more and more support to change MARC itself.  This needs to be cleaned up in the near future.

marc_add does have the functionality you can add values to a separate record field:

marc_add('900', ind1 , ' ' , a, 'test' , 'b', test , record:record2)

Alas I didn't add it to the marc_set, marc_remove and marc_replace_all fixes.

It is quite comming in Fix to extract fields out of the MARC in temporary fields. If you only export to MARC, then these temporary fields are ignored. The MARC exporters only look at the 'record' field.

To log or export fields in a stream processing I would suggest to look at the add_to_exporter fix:




From: Uldis Bojars <captsolo at gmail.com>
Sent: Thursday, June 29, 2017 3:49 PM
To: Patrick Hochstenbach
Cc: librecat-dev at lists.uni-bielefeld.de
Subject: Re: [librecat-dev] string operations, defining functions in Catmandu

On 29 June 2017 at 14:28, Patrick Hochstenbach <Patrick.Hochstenbach at ugent.be<mailto:Patrick.Hochstenbach at ugent.be>> wrote:

But while waiting for this new feature you can use a dirty trick to get the required result. The Fix script below will add the 100 subfields to the 400 field and adds a
period "." when required:


The trick is the append(record.$last.$last,".") line which knows that MARC is modeled as an array of arrays in Catmandu and adds a period to the last element.

Thanks! This trick + "marc_match(100aqbcd,"\.$")" saves the day :)

What if I need to reuse the result [ = the new field 400aqbcd with "." at the end ] multiple times (e.g. to create multiple 400 fields with more subfields added, different in each case)?

Is there a way to copy the full structure (with subfields) of a MARC field into a temporary field / variable and then create a new MARC field based on it?
  - another option is to hold this temporary value in a non-standard MARC field (e.g. "XYZ") but that feels like a hack

P.S. Is there a way to dump / log contents of a field (variable) from the Fix script?


> On 28 Jun 2017, at 18:41, Uldis Bojars <captsolo at gmail.com<mailto:captsolo at gmail.com>> wrote:
> Hi,
> Could you suggest how to do this in Catmandu:
> I need to form a new MARC field ("400") that consist of some subfields (in this order: $a $q $b $c $d) of an existing field ("100"). That much is not difficult, but there's another condition:
> "." must be added to the last subfield that exists (e.g. if $d exists append "." to it unless it already ends with ".", otherwise do the same with $c, [...]) .
> Questions:
> 1) how to determine if a field (e.g. fld_100d created via marc_map) ends with "." ?
> 2) is there a way to "package" some functionality and call it when needed?
> In this case it would be good to create a function that appends "." to the field provided as a parameter unless it already ends with ".".
> Then what is needed could be achieved like this:
> if exists("fld_100d"):
>    my_function("fld_100d")
> elsif exists("fld_100c"):
>    my_function("fld_100c")
> elsif [...]
>    [...]
> end
> P.S. Perhaps there is a more idiomatic way how to do this in Catmandu?
> Thanks,
> Uldis
> _______________________________________________
> librecat-dev mailing list
> - send list mails to librecat-dev at lists.uni-bielefeld.de<mailto: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/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.uni-bielefeld.de/mailman2/unibi/public/librecat-dev/attachments/20170630/55a68173/attachment.html>

More information about the librecat-dev mailing list