3 -- This function is used to help clean up facet labels. Due to quirks in
4 -- MARC parsing, some facet labels may be generated with periods or commas
5 -- at the end. This will strip a trailing commas off all the time, and
6 -- periods when they don't look like they are part of initials.
7 -- Smith, John => no change
8 -- Smith, John, => Smith, John
9 -- Smith, John. => Smith, John
10 -- Public, John Q. => no change
11 CREATE OR REPLACE FUNCTION metabib.trim_trailing_punctuation ( TEXT ) RETURNS TEXT AS $$
17 last_char = substring(result from '.$');
19 IF last_char = ',' THEN
20 result := substring(result from '^(.*),$');
22 ELSIF last_char = '.' THEN
23 IF substring(result from ' \w\.$') IS NULL THEN
24 result := substring(result from '^(.*)\.$');
31 $$ language 'plpgsql';
33 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
34 'Trim Trailing Punctuation',
35 'Eliminate extraneous trailing commas and periods in text',
36 'metabib.trim_trailing_punctuation',
40 INSERT INTO config.metabib_field_index_norm_map (field,norm,pos)
44 FROM config.metabib_field m,
45 config.index_normalizer i
46 WHERE i.func = 'metabib.trim_trailing_punctuation'
47 AND m.id IN (7,8,9,10);