3 INSERT INTO config.upgrade_log (version) VALUES ('0357'); -- dbs
5 DELETE FROM config.metabib_field_index_norm_map
8 FROM config.index_normalizer
9 WHERE func IN ('first_word', 'naco_normalize', 'split_date_range')
14 CREATE OR REPLACE FUNCTION public.translate_isbn1013( TEXT ) RETURNS TEXT AS $func$
19 # For each ISBN found in a single string containing a set of ISBNs:
20 # * Normalize an incoming ISBN to have the correct checksum and no hyphens
21 # * Convert an incoming ISBN10 or ISBN13 to its counterpart and return
26 foreach my $word (split(/\s/, $input)) {
27 my $isbn = Business::ISBN->new($word);
29 # First check the checksum; if it is not valid, fix it and add the original
30 # bad-checksum ISBN to the output
31 if ($isbn && $isbn->is_valid_checksum() == Business::ISBN::BAD_CHECKSUM) {
32 $output .= $isbn->isbn() . " ";
33 $isbn->fix_checksum();
36 # If we now have a valid ISBN, convert it to its counterpart ISBN10/ISBN13
37 # and add the normalized original ISBN to the output
38 if ($isbn && $isbn->is_valid()) {
39 my $isbn_xlated = ($isbn->type eq "ISBN13") ? $isbn->as_isbn10 : $isbn->as_isbn13;
40 $output .= $isbn->isbn . " ";
42 # If we successfully converted the ISBN to its counterpart, add the
43 # converted ISBN to the output as well
44 $output .= ($isbn_xlated->isbn . " ") if ($isbn_xlated);
47 return $output if $output;
49 # If there were no valid ISBNs, just return the raw input
51 $func$ LANGUAGE PLPERLU;
53 COMMENT ON FUNCTION public.translate_isbn1013(TEXT) IS $$
55 * Copyright (C) 2010 Merrimack Valley Library Consortium
56 * Jason Stephenson <jstephenson@mvlc.org>
57 * Copyright (C) 2010 Laurentian University
58 * Dan Scott <dscott@laurentian.ca>
60 * The translate_isbn1013 function takes an input ISBN and returns the
61 * following in a single space-delimited string if the input ISBN is valid:
62 * - The normalized input ISBN (hyphens stripped)
63 * - The normalized input ISBN with a fixed checksum if the checksum was bad
64 * - The ISBN converted to its ISBN10 or ISBN13 counterpart, if possible