1 Migration Data Work HOWTO / Toolkit
2 ========================================================================
3 The following is for migrating into an existing system like PINES:
5 Get the incoming bib data, and translate to UTF-8 MARCXML. It may
6 contain holdings. It may contain XML or MARC errors that you have to
7 sanitize before your tools will work. This is one way to translate
8 MARC-8 MARC21 to UTF-8 MARCXML:
10 yaz-marcdump -f MARC-8 -t UTF-8 -o marcxml \
11 incoming.marc > incoming.marc.xml
13 If you need to trim the bibs to a subset based on the presence of a
14 certain value in a specific tag/subfield (for example, if you have the
15 bibs for all libraries in a foreign system and only need bibs
16 belonging to a specific migrating library, you might filter based on
19 trim_marc_based_on_tag_subfield_value.pl 999 m BRANCH_CODE \
20 incoming.marc.xml > incoming.filtered.marc.xml
22 Embed potential native record ids into the incumbent records
24 renumber_marc -rf 100000 -t 903 -s a -o incoming.renumbered.marc.xml \
27 Get primary fingerprints for incoming data and get a bib dump of
28 matching records from the incumbent system
30 fingerprinter -r primary -t 903 -s a -o incoming.primary.fp \
31 -x incoming.primary.ex incoming.renumbered.mrc.xml
33 Edit the query_for_primary_matching_incumbent_record.pl script to
34 point to the correct Evergreen database and table holding the
35 incumbent primary fingerprints (FIXME add in how to create such a
38 query_for_primary_matching_incumbent_record.pl incoming.primary.fp \
39 | sort | uniq > primary_matching_incumbent.record_ids
41 In a postgres shell, you create a temporary table to hold these id's:
43 CREATE TABLE primary_matching_incumbent_records_for_incoming_library
45 COPY primary_matching_incumbent_records_for_incoming_library
46 FROM 'primary_matching_incumbent.record_ids';
48 To dump the matching incumbent records to a file, in a postgres shell
51 matching_incumbent_records.dump SELECT b.id, b.tcn_source, b.tcn_value,
52 regexp_replace(b.marc,E'\n','','g')
53 FROM biblio.record_entry AS b
54 JOIN primary_matching_incumbent_records_for_incoming_library
57 Now to turn that dump into a MARCXML file with record numbers and TCN
58 embedded in tag 901, do:
60 marc_add_ids -f id -f tcn_source -f tcn_value -f marc \
61 < matching_incumbent_records.dump > matching_incumbent_records.marc.xml
63 It's possible that this file may need to be itself sanitized some.
64 This will transform code=""" into code="&x0022;", for example:
66 cat matching_incumbent_records.marc.xml | \
67 sed 's/code=\"\"\"/code=\"\"\"/' \
68 > matching_incumbent_records.escaped.mrc.xml
70 Get full fingerprints for both datasets and match them.
72 fingerprinter -r full -t 901 -s c -o incumbent.fp -x incumbent.ex \
73 matching_incumbent_records.marc.xml
74 fingerprinter -r full -t 903 -s a -o incoming.fp -x incoming.ex \
75 incoming.renumbered.marc.xml
77 The script below will produce matched groupings, and can optionally
78 take a 4th and 5th parameter providing scoring information for
79 determining lead records. In the past, this would consider certain
80 metrics for MARC quality, but in the latest incarnation, it assumes an
81 incumbent record will be the lead record, and looks at # of holdings
82 and possible matching of tag 245 subfield b for determining which of
83 the incumbent records would be the lead record. The example
84 invocation below does not use scoring.
86 match_fingerprints.pl "name of dataset for dedup interface" \
87 incumbent.fp incoming.fp
89 This will produce two files, match.groupings and match.record_ids.
90 The format for match.groupings is suitable for insertion into the db
91 for the dedup interface.
93 Import these matches and records into the legacy dedup interface for viewing:
95 Now to tar up the specific MARC records involved for the dedup interface:
97 cat match.groupings | cut -d^ -f3 > incumbent.record_ids
98 cat match.groupings | cut -d^ -f5 | cut -d, -f2- | sed 's/,/\n/g' \
100 mkdir dataset ; cd dataset
101 select_marc.pl ../incumbent.record_ids 901 c \
102 ../matching_incumbent_records.mrc.xml
103 select_marc.pl ../incoming.record_ids 903 a \
104 ../incoming.renumbered.mrc.xml
106 tar cvf dataset.tar dataset
108 In a mysql shell for the database used with the dedup interface:
110 LOAD DATA LOCAL INFILE 'match.groupings' INTO TABLE record_group
111 FIELDS TERMINATED BY '^'
112 ( status, dataset, best_record,records,original_records );
114 Create a pretty printed text dump of the non-matching incoming records:
116 dump_inverse_select_marc.pl incoming.record_ids 903 a \
117 incoming.renumbered.mrc.xml > non_matching_incoming.mrc.txt 2> \
118 non_matching_incoming.mrc.txt.err