Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to perform a lookup? #356

Closed
jasloe opened this issue Oct 26, 2018 · 2 comments
Closed

How to perform a lookup? #356

jasloe opened this issue Oct 26, 2018 · 2 comments

Comments

@jasloe
Copy link

jasloe commented Oct 26, 2018

A quick support request. It's been a long time since I've worked with Catmandu so bear with me.

I have a list of 008 control fields that were generated elsewhere which I'd like to incorporate into my MARC records.

The 001 control field is the key I'll use to join the 008 data to their respective records.

Given the following in test.csv:

key,value
80201,070806t20071976nyusgnn\sabfi\\\\\n\eng\d
80202,070802r20101976nyusnnn\sabi\\\\\\n\zxx\d

Copy 001 to a temporary variable:

marc_copy(001, var)

Compare that variable to a list:

lookup(tmp,"test.csv",sep_char:",")

Set the resulting value to the 008 field, then paste after 007:

set_field(var.$first.tag,008)
marc_paste(tmp, at: 007)

Unfortunately, the lookup appears to not work. The script simply copies 001 to tmp, pastes to 008 and entirely ignores the lookup.

Am I missing something?

@phochste
Copy link
Member

phochste commented Oct 26, 2018

The lookup fix requires as first parameter a field which contains a string. This string will be matched with the CSV file in the second parameter. E.g.

# tmp will contain the record number
marc_map(001,tmp)

# the record number in tmp will be replaced with the value found in file.csv
lookup(tmp,file.csv)

In your case you need some MARC magic to create a new 008 field. This can be done like:

# Create a new field an lookup the content in a CSV file
add_field(tmp.tag,'008')
add_field(tmp.ind1,' ')
add_field(tmp.ind2,' ')
marc_map(001,tmp.content)
lookup(tmp.content,file.csv)

# Paste the new field after an existing 007 field in the record
marc_paste(tmp,at:007)

remove_field(tmp)

All this assumes that the 001 and 007 exist in every record you are going to process. The current marc_paste lacks functionality to add the 008 at the correct place even it 007 doesn't exist in the record. I'll made a ticket for that LibreCat/Catmandu-MARC#90

@jasloe
Copy link
Author

jasloe commented Oct 26, 2018

That works just fine. I don't think I've seen the *.tag and *.content patterns before. Is there documentation available?

@jasloe jasloe closed this as completed May 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants