spit out data from unicorn style holding tags from marc
[migration-tools.git] / Migration Data Work HOWTO.txt
1  
2 Migration Data Work HOWTO / Toolkit
3 The following is for migrating into an existing system like PINES:
4
5 Get the incoming bib data, and translate to UTF-8 MARCXML.  It may contain holdings.  It may contain XML or MARC errors that you have to sanitize before your tools will work.
6 This is one way to translate MARC-8 MARC21 to UTF-8 MARCXML:
7 yaz-marcdump -f MARC-8 -t UTF-8 -o marcxml incoming.mrc » incoming.mrc.xml
8
9
10 If you need to trim the bibs to a subset based on the presence of a certain value in a specific tag/subfield (for example, if you have the bibs for all libraries in a foreign system and only need bibs belonging to a specific migrating library, you might filter based on their holding tags)
11 trim_marc_based_on_tag_subfield_value.pl 999 m BRANCH_CODE incoming.mrc.xml » incoming.filtered.mrc.xml
12
13
14 Embed potential native record ids into the incumbent records
15
16 set_record_ids.pl 100000 903 a incoming.mrc.xml » incoming.renumbered.mrc.xml
17
18
19 Get primary fingerprints for incoming data and get a bib dump of matching records from the incumbent system
20
21 fingerprints.pl primary 903 a incoming.renumbered.mrc.xml » incoming.primary.fp 2» incoming.primary.fp_err
22
23 Edit the query_for_primary_matching_incumbent_record.pl script to point to the correct Evergreen database and table holding the incumbent primary fingerprints (FIXME add in how to create such a table).
24 query_for_primary_matching_incumbent_record.pl incoming.primary.fp | sort | uniq » primary_matching_incumbent.record_ids
25
26 In a postgres shell, you create a temporary table to hold these id's:
27 CREATE TABLE primary_matching_incumbent_records_for_incoming_library ( id BIGINT );
28 COPY primary_matching_incumbent_records_for_incoming_library FROM 'primary_matching_incumbent.record_ids';
29
30 To dump the matching incumbent records to a file, in a postgres shell do:
31 \t
32 \o matching_incumbent_records.dump
33 select b.id, b.tcn_source, b.tcn_value, regexp_replace(b.marc,E'\n','','g') from biblio.record_entry as b join primary_matching_incumbent_records_for_incoming_library as c using ( id ) ;
34
35 Now to turn that dump into a MARCXML file with record numbers and TCN embedded in tag 901, do:
36 marc_add_ids -f id -f tcn_source -f tcn_value -f marc « matching_incumbent_records.dump » matching_incumbent_records.mrc.xml
37
38
39 It's possible that this file may need to be itself sanitized some.  This will transform code=""" into code="&x0022;", for example:
40 cat matching_incumbent_records.mrc.xml | sed 's/code=\"\"\"/code=\"\"\"/' » matching_incumbent_records.escaped.mrc.xml
41
42 Get full fingerprints for both datasets and match them.
43
44 fingerprints.pl full 901 c matching_incumbent_records.mrc.xml » incumbent.fp 2» incumbent.fp_err
45 fingerprints.pl full 903 a incoming.renumbered.mrc.xml » incoming.fp 2» incoming.fp_err
46
47 The script below will produce matched groupings, and can optionally take a 4th and 5th parameter providing scoring information for determining lead records.  In the past, this would consider certain metrics for MARC quality, but in the latest incarnation, it assumes an incumbent record will be the lead record, and looks at # of holdings and possible matching of tag 245 subfield b for determining which of the incumbent records would be the lead record.  The example invocation below does not use scoring.
48
49 match_fingerprints.pl "name of dataset for dedup interface" incumbent.fp incoming.fp
50
51 This will produce two files, match.groupings and match.record_ids.  The format for match.groupings is suitable for insertion into the db for the dedup interface.  
52
53 Import these matches and records into the legacy dedup interface for viewing:
54
55 Now to tar up the specific MARC records involved for the dedup interface:
56
57 cat match.groupings | cut -d^ -f3 » incumbent.record_ids
58 cat match.groupings | cut -d^ -f5 | cut -d, -f2- | sed 's/,/\n/g' » incoming.record_ids
59
60 mkdir dataset ; cd dataset
61 select_marc.pl ../incumbent.record_ids 901 c ../matching_incumbent_records.mrc.xml
62 select_marc.pl ../incoming.record_ids 903 a ../incoming.renumbered.mrc.xml
63 cd .. 
64 tar cvf dataset.tar dataset
65
66 In a mysql shell for the database used with the dedup interface:
67 LOAD DATA LOCAL INFILE 'match.groupings' INTO TABLE record_group FIELDS TERMINATED BY '^' ( status, dataset, best_record,records,original_records );
68
69
70 Create a pretty printed text dump of the non-matching incoming records:
71
72 dump_inverse_select_marc.pl incoming.record_ids 903 a incoming.renumbered.mrc.xml » non_matching_incoming.mrc.txt 2» non_matching_incoming.mrc.txt.err
73
74