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

Patrick Hochstenbach Patrick.Hochstenbach at UGent.be
Tue Jul 4 15:48:31 CEST 2017


Indeed if you don’t use marc specific fixes, then you need to process the ‘raw’ JSON (which is an array of an array in the case of MARC).
Carsten Klee and I have been working on two new Fixes the last 2 days that could make copying and pasting MARC fields a bit easier than processing raw data.
In Catmandu::MARC 1.16 you’ll have the `marc_copy` and `marc_paste` fix available:

# Copy the content of the 100 field to a temporary variable
marc_copy(245,tmp)

`tmp` will contain always an array of copied MARC field, this will be more easily structured somewhat like a MARC-in-JSON hash which you can edit with catmandu:

    [{
            "tag" : “245”,
	    "ind1" : " ",
            "ind2" : “0”
            "subfields" : [
                {
                    "a" : "Web servers."
                }
            ],
    }]

# Change the tag of the first (and only probably) copied field to ‘400'
set_field(tmp.0.tag,400)

# And..paste it back into the recod
marc_paste(tmp)

# Or, paste is after the other 400 fields
marc_paste(tmp,at:’400’)

There are more options that you can read in the documenten when the 1.16 code will be available on CPAN (in the next few hours)

Hope this gets you a step further

> On 3 Jul 2017, at 18:49, Uldis Bojars <captsolo at gmail.com> wrote:
> 
> 
> 
> On 1 July 2017 at 13:58, Patrick Hochstenbach <Patrick.Hochstenbach at ugent.be> wrote:
> 
> >> 1) Is it possible to also "copy" indicator values (from 100 field)? How would you do this?
> >> 2) Is it possible to make a copy of a MARC field (within the record)?
> 
> With Fix you can do anything you want with JSON. A MARC record is just a 'record' key in a JSON document which contains an ARRAY of ARRAY values. All the fixes copy_field, move_field, etc etc can operate on each type of JSON document. A copy of a MARC field could be implemented with something like:
> 
> # Copy the 100 field to 400
> do list(path:record, var:c)
>   if all_match(c.0,100)
>    copy_field(c,copy.$append)
>    replace_all(copy.$end.0,100,400)
>   end
> end
> 
> move_field(copy.*,record.$append)
> remove_field(copy)
> 
> This does not quite work - the 100 field gets duplicated (added to the end of the record) but its type is never changed from 100 to 400.
> 
> Any idea how to fix it? - I realise that everything that is necessary can be done using ARRAY operations but I don't yet know how to correctly write them.
> 
> Also: how would you read the value of the 1st indicator of a certain MARC field?
>    - [in this case] it is OK to assume that the field appears in the record just once
> 
> Thanks,
> Uldis

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.uni-bielefeld.de/mailman2/unibi/public/librecat-dev/attachments/20170704/367fcb8f/attachment.asc>


More information about the librecat-dev mailing list