[librecat-dev] non-unique keys in lookup list?
Patrick Hochstenbach
Patrick.Hochstenbach at UGent.be
Thu Oct 13 10:09:23 CEST 2016
The ‘lookup’ fix requires a CSV file input with unique values, indeed. But with catmandu you can easily transform your CSV file into such an unique key file.
Given a file ‘list.csv’ with the follwing content (to have a ‘key,value’ as header is important the hashmap bind below needs these field names):
key,value
777,"Solveig"
888,"Patrick"
888,"Nicolas"
888,"Jason"
999,”Brian"
You can transform this CSV into a one with a unique key like:
$ catmandu convert CSV to Null --fix 'do hashmap(exporter:CSV,join:",");nothing();end' < list.csv > lookup.csv
$ cat lookup.csv
_id,value
777,Solveig
888,"Patrick,Nicolas,Jason"
999,Brian
This one you can use to create your MARC. E.g. when given an input YAML file:
data.yaml:
---
_id: 777
---
_id: 888
---
_id: 999
…
And a Fix script:
marc.fix:
lookup(_id,lookup.csv)
split_field(_id,",")
do list(path:_id,var:c)
marc_add('666','a','$.c')
end
This will produce 3 MARC records where the second has 3 fields (I use the MARCMaker to show the MARC in a human readable form):
$ catmandu convert YAML to MARC --type MARCMaker --fix marc.fix < data.yaml
=LDR
=666 \\$aSolveig
=LDR
=666 \\$aPatrick
=666 \\$aNicolas
=666 \\$aJason
=LDR
=666 \\$aBrian
Cheers
Patrick
> On 12 Oct 2016, at 20:38, Jason Loeffler <j at minorscience.com> wrote:
>
> 777,"Solveig"
> 888,"Patrick"
> 888,"Nicolas"
> 888,"Jason"
> 999,"Brian"
Patrick Hochstenbach - digital architect
University Library Ghent
Sint-Hubertusstraat 8 - 9000 Ghent - Belgium
patrick.hochstenbach at ugent.be
+32 (0)9 264 7980
More information about the librecat-dev
mailing list