[librecat-dev] Catmandu copy field and operate on it, replacing and extracting stuff

Patrick Hochstenbach Patrick.Hochstenbach at UGent.be
Fri Nov 17 14:56:28 CET 2023


Hi,

I don't think al the fixes in your fix script I can recognise as intended usage of marc fixes. But, I understood hopefully the gist of what you are trying to achieve. Here is my take on a script that can do that for you


do marc_each()

  if marc_has('773w')

    marc_map('773w',tmp,split:1)

  end

end


do list(path:tmp,var:c)

  if all_match(c,'^\(DE-627\).*')

    replace_all(c,'^\([^\)]+\)(.*)$','$1')

    copy_field(c,'relation\.journalppn.$append')

  end


  if all_match(c,'^\(DE-600\).*')

    replace_all(c,'^\([^\)]+\)(.*)$','$1')

    copy_field(c,'relation\.journalzdbid.$append')

  end

end


join_field('relation\.journalppn','|')

join_field('relation\.journalzdbid','|')


remove_field(tmp)


BR

Patrick

________________________________
From: librecat-dev-bounces at lists.uni-bielefeld.de <librecat-dev-bounces at lists.uni-bielefeld.de> on behalf of Hemme, Felix <f.hemme at zbw-online.eu>
Sent: 17 November 2023 14:10
To: librecat-dev at lists.uni-bielefeld.de <librecat-dev at lists.uni-bielefeld.de>
Subject: [librecat-dev] Catmandu copy field and operate on it, replacing and extracting stuff

Hi Catmandu users, (sorry for a longer email),

I'm working on a MARC record containing 773 fields like this:

<datafield tag="773" ind1="0" ind2="8">
        <subfield code="i">Enthalten in</subfield>
        <subfield code="t">Athens journal of business & economics</subfield>
        <subfield code="d">Athens : Business & Law Research Division and the
Economics Research Unit of ATINER, 2015</subfield>
        <subfield code="d">Athens : Business & Law Research Division and the
Economics Research Unit of ATINER, 2015</subfield>
        <subfield code="g">6(2020), 2 vom: Apr., Seite 127-144</subfield>
        <subfield code="h">Online-Ressource</subfield>
        <subfield code="h">Online-Ressource</subfield>
        <subfield code="w">(DE-627)85561451X</subfield>
        <subfield code="w">(DE-600)2851008-2</subfield>
        <subfield code="w">(DE-576)462896099</subfield>
        <subfield code="x">2241-794X</subfield>
        <subfield code="7">nnns</subfield>
</datafield>

I want to map the values from $w to multiple fields, depending of the source
of the ID that is specified in parentheses, e.g. (DE-627) = K10plus union
catalog and (DE-600) = ZDB.

Here is what I've done in a fix file to filter for those ID's:

# Journal PPN id
# only for target owc-de-206 and nl-zeitschriften
do marc_each()
  if all_match('target','owc-de-206')
    if marc_any_match('7737|||s','s')
      if marc_any_match('773w','(DE-627)')
        marc_copy('773w','773wFixed2')
        marc_replace_all('773wFixed2','^((?!DE-627).)*$','')

marc_replace_all('773wFixed2','^(\(DE-627\))(\d{8,9}[\dxX]{1}$)','$2')
        marc_map('773wFixed2','relation\.journalppn.$append')
      end
    end
  end
end
join_field('relation\.journalppn','|')

This condition is working and extracts the value "85561451X". In order to
not delete all 773's that don't match the given Regex, I copied the content
to a tmp field "773wFixed1" and operate on it. The next part won't extract
anything and I don't know why:

# ZDB id for journals
do marc_each()
  if marc_any_match('7737|||s','s')
    if marc_any_match('773w','(DE-600)')
      marc_copy('773w','773wFixed3')
      marc_replace_all('773wFixed3','^((?!DE-600).)*$','')
      #marc_replace_all('773wFixed3','^(\(DE-600\))(\d{7}-[\dxX]{1}$)','$2')
      marc_map('773wFixed3','relation\.journalzdbid.$append')
    end
  end
end
join_field('relation\.journalzdbid','|')

It should extract the value 2851008-2.

Happy for any advice you might have. Felix

Best regards,
Felix Hemme
..........................................
People's gender identity cannot be reliably deduced from either their
appearance or their name. Let me know how you would like to be addressed.

FELIX HEMME
Metadata Management
Pronouns: he/him

ZBW - Leibniz Information Centre for Economics
Duesternbrooker Weg 120
24105 Kiel
Germany
T: +49 431 8814-355
E: f.hemme at zbw-online.eu
*Due to the change of our e-mail system you can currently reach me via this
e-mail address.



_______________________________________________
librecat-dev mailing list
- send list mails to librecat-dev at lists.uni-bielefeld.de
- to unsubscribe or change options, visit https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.uni-bielefeld.de%2Fmailman2%2Fcgi%2Funibi%2Flistinfo%2Flibrecat-dev&data=05%7C01%7CPatrick.Hochstenbach%40UGent.be%7C9b85275ed5e74758d00508dbe76ec70b%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C638358235198507411%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=CTzgipu635INGHiBlI4hqt2uLVAdb2dyuMt7h%2F2yI1I%3D&reserved=0<https://lists.uni-bielefeld.de/mailman2/cgi/unibi/listinfo/librecat-dev>
- project website: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Flibrecat.org%2F&data=05%7C01%7CPatrick.Hochstenbach%40UGent.be%7C9b85275ed5e74758d00508dbe76ec70b%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C638358235198507411%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Ok9%2FRQtlu1Z%2B9RRw8MKl9%2F8b6m03a2irchuDLNfo5Zk%3D&reserved=0<http://librecat.org/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.uni-bielefeld.de/mailman2/unibi/public/librecat-dev/attachments/20231117/92b121d8/attachment.html>


More information about the librecat-dev mailing list