From: Kathy Lussier Date: Wed, 8 Feb 2017 20:11:19 +0000 (-0500) Subject: LP#1308090: Stamping upgrade script for trim trailing punctuation normalizer X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2644ddda0779f36a6a7955956d117741bd902ee9;p=working%2FEvergreen.git LP#1308090: Stamping upgrade script for trim trailing punctuation normalizer Signed-off-by: Kathy Lussier --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index c0b4613693..6c61454776 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -91,7 +91,7 @@ CREATE TRIGGER no_overlapping_deps BEFORE INSERT OR UPDATE ON config.db_patch_dependencies FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates'); -INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1005', :eg_version); -- csharp/berick +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1006', :eg_version); -- DPearl/kmlussier CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/1006.function.trim_trailing_punctuation.sql b/Open-ILS/src/sql/Pg/upgrade/1006.function.trim_trailing_punctuation.sql new file mode 100644 index 0000000000..5a4004aae5 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/1006.function.trim_trailing_punctuation.sql @@ -0,0 +1,52 @@ +SELECT evergreen.upgrade_deps_block_check('1006', :eg_version); + +BEGIN; + +-- This function is used to help clean up facet labels. Due to quirks in +-- MARC parsing, some facet labels may be generated with periods or commas +-- at the end. This will strip a trailing commas off all the time, and +-- periods when they don't look like they are part of initials. +-- Smith, John => no change +-- Smith, John, => Smith, John +-- Smith, John. => Smith, John +-- Public, John Q. => no change +CREATE OR REPLACE FUNCTION metabib.trim_trailing_punctuation ( TEXT ) RETURNS TEXT AS $$ +DECLARE + result TEXT; + last_char TEXT; +BEGIN + result := $1; + last_char = substring(result from '.$'); + + IF last_char = ',' THEN + result := substring(result from '^(.*),$'); + + ELSIF last_char = '.' THEN + IF substring(result from ' \w\.$') IS NULL THEN + result := substring(result from '^(.*)\.$'); + END IF; + END IF; + + RETURN result; + +END; +$$ language 'plpgsql'; + +INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES ( + 'Trim Trailing Punctuation', + 'Eliminate extraneous trailing commas and periods in text', + 'metabib.trim_trailing_punctuation', + 0 +); + +INSERT INTO config.metabib_field_index_norm_map (field,norm,pos) + SELECT m.id, + i.id, + -1 + FROM config.metabib_field m, + config.index_normalizer i + WHERE i.func = 'metabib.trim_trailing_punctuation' + AND m.id IN (7,8,9,10); + +COMMIT; + diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.trim_trailing_punctuation.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.trim_trailing_punctuation.sql deleted file mode 100644 index b13f66f129..0000000000 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.trim_trailing_punctuation.sql +++ /dev/null @@ -1,50 +0,0 @@ -BEGIN; - --- This function is used to help clean up facet labels. Due to quirks in --- MARC parsing, some facet labels may be generated with periods or commas --- at the end. This will strip a trailing commas off all the time, and --- periods when they don't look like they are part of initials. --- Smith, John => no change --- Smith, John, => Smith, John --- Smith, John. => Smith, John --- Public, John Q. => no change -CREATE OR REPLACE FUNCTION metabib.trim_trailing_punctuation ( TEXT ) RETURNS TEXT AS $$ -DECLARE - result TEXT; - last_char TEXT; -BEGIN - result := $1; - last_char = substring(result from '.$'); - - IF last_char = ',' THEN - result := substring(result from '^(.*),$'); - - ELSIF last_char = '.' THEN - IF substring(result from ' \w\.$') IS NULL THEN - result := substring(result from '^(.*)\.$'); - END IF; - END IF; - - RETURN result; - -END; -$$ language 'plpgsql'; - -INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES ( - 'Trim Trailing Punctuation', - 'Eliminate extraneous trailing commas and periods in text', - 'metabib.trim_trailing_punctuation', - 0 -); - -INSERT INTO config.metabib_field_index_norm_map (field,norm,pos) - SELECT m.id, - i.id, - -1 - FROM config.metabib_field m, - config.index_normalizer i - WHERE i.func = 'metabib.trim_trailing_punctuation' - AND m.id IN (7,8,9,10); - -COMMIT; -