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

Hemme, Felix f.hemme at zbw-online.eu
Fri Nov 17 14:10:06 CET 2023


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.





More information about the librecat-dev mailing list