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

Uldis Bojars captsolo at gmail.com
Fri Jun 30 15:13:03 CEST 2017


> 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:
>
> $ cat marc.fix
> marc_map(100a,f100a)
> marc_map(100q,f100q)
> marc_map(100b,f100b)
> marc_map(100c,f100c)
> marc_map(100d,f100d)
>
> if marc_match(100aqbcd,"\.$")
>     # Do nothing
>     marc_add(400
>         ,a ,$.f100a
>         ,q ,$.f100q
>         ,b ,$.f100b
>         ,c ,$.f100c
>         ,d ,$.f100d)
>

1) Is it possible to also "copy" indicator values (from 100 field)? How
would you do this?

I think Catmandu docs mentioned that you can not read indicator values with
marc_map().
In that case knowing what the values are might be helpful: ind1 = (0, 1 or
3), ind3 = " ".

2) Is it possible to make a copy of a MARC field (within the record)?

E.g. copy the newly created 400 field to another field.

Another way to solve this would be if there were functions that can (a)
dump the "raw" structure of MARC field into a separate field and (b) put it
back as a new MARC field.

If I understand it correctly, there is a function for copying an arbitrary
JSON field (copy_field), but the challenge is finding the right JSON path
to identify the necessary MARC field. This part could be solved if
marc_map() had a "raw" mode that copies the raw JSON structure instead of
converting it to text, although that

3) In the other response you wrote:

The main use case was to transform MARC to something else ;). But there is
> more and more support to change MARC itself.


I see ;) - Yet it's great [for cases like this one] that Catmandu can also
convert MARC to MARC :)

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)
>

Hmm, what does it do?

I tried it but it did not do anything for me (i.e. it did not create
$.record.record2 - just created a regular 900 field inside $.record).

Thanks a lot,
Uldis



> > On 28 Jun 2017, at 18:41, Uldis Bojars <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
> > - 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/3f55546a/attachment.html>


More information about the librecat-dev mailing list