[librecat-dev] Catmandu get headings tag

Patrick Hochstenbach Patrick.Hochstenbach at UGent.be
Fri Dec 22 09:33:02 CET 2017


With Catmandu::MARC 1.231 you can do this to get a list of all record id and authority tags:


$ catmandu convert MARC --type RAW to JSON --fix auth.fix < auth_test_links.mrc

[{"_id":"59de6bd221c0c8f86d4863f9","heading":"200"}]


with `auth.fix` as:


marc_map(001,_id)

do marc_each(var:this)
  if all_match(this.tag,"^2..")
    copy_field(this.tag,heading)
  end
end

retain(_id,heading)

You could store this list for instance in a SQLLite database to use to the authority identifiers in lookups:

$ catmandu import MARC --type RAW to DBI --data_source dbi:SQLite:auth.sqlite < auth_test_links.mrc


You can use this SQLLite database to create for instance a TSV file with all matching $3 links to authority records (use Null to supress the normal output and use exporters inside the fix script)


$ catmandu convert MARC --type RAW to Null --fix lookup.fix < bib_test_links.mrc

00id 01tag 02auth_id 03heading
59de80bc21c0c8f86d4b9e6e 606 59de6bd221c0c8f86d4863f9 200
59de80bc21c0c8f86d4b9e6e 606 59de6bd221c0c8f86d48f223 NOT FOUND
59de80bc21c0c8f86d4b9e6e 701 59de6bd221c0c8f86d48595e NOT FOUND
59de80bc21c0c8f86d4b9e6e 712 59de6bd321c0c8f86d4944ca NOT FOUND

With `lookup.fix` as:

marc_map(001,_id)

do marc_each(var:this)
    # Get every $3 subfield
    marc_map('***3',auth_id)

    # If there is an $3 try to find it in the auth.sqlite database
    if exists(auth_id)
      lookup_in_store(auth_id,DBI, data_source: "dbi:SQLite:auth.sqlite")

      # Create a TSV output with 4 columns: id, tag, auth_id and the heading (if found)
      copy_field(_id,output.00id)
      copy_field(this.tag,output.01tag)

      if exists(auth_id.heading)
        copy_field(auth_id._id,output.02auth_id)
        copy_field(auth_id.heading,output.03heading)
      else
        copy_field(auth_id,output.02auth_id)
        add_field(output.03heading,"NOT FOUND")
      end

      add_to_exporter(output,TSV)

      remove_field(auth_id)
      remove_field(output)
    end
end

retain(_id,auth_id)

Probably you want to process this TSV file further to find mistakes in the $3 -> authority tag but this shouldn't be hard now.

I'm now off to my Christmas diners. Good luck and until 2018.


________________________________
From: librecat-dev-bounces at lists.uni-bielefeld.de <librecat-dev-bounces at lists.uni-bielefeld.de> on behalf of Spiros Antonio <spiros.antonio at gmail.com>
Sent: Friday, December 22, 2017 8:33 AM
To: librecat-dev at lists.uni-bielefeld.de
Subject: [librecat-dev] Catmandu get headings tag

Hello,

i need to use a catmandu fix in my code, in order to be able to get the headings tag

out of a given authorities file.

In our case, the headings tag in each authority record is a 2.. (2xx) tag

Only one 2xx tag exists in each authority record.

I know how i could get the 2xx value, but in this case i need to know the tag value,

thank you

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


More information about the librecat-dev mailing list