3 SELECT evergreen.upgrade_deps_block_check('1194', :eg_version);
5 CREATE OR REPLACE FUNCTION public.naco_normalize( TEXT, TEXT ) RETURNS TEXT AS $func$
8 use Unicode::Normalize;
14 # Apply NACO normalization to input string; based on
15 # https://www.loc.gov/aba/pcc/naco/documents/SCA_PccNormalization_Final_revised.pdf
17 # Note that unlike a strict reading of the NACO normalization rules,
18 # output is returned as lowercase instead of uppercase for compatibility
19 # with previous versions of the Evergreen naco_normalize routine.
21 # Convert to upper-case first; even though final output will be lowercase, doing this will
22 # ensure that the German eszett (ß) and certain ligatures (ff, fi, ffl, etc.) will be handled correctly.
23 # If there are any bugs in Perl's implementation of upcasing, they will be passed through here.
26 # remove non-filing strings
27 $str =~ s/\x{0098}.*?\x{009C}//g;
30 # Replace unicode curly single and double quote-like characters with straight
31 $str =~ s/[\x{2018}\x{2019}\x{201B}\x{FF07}\x{201A}]/\x{0027}/g;
32 $str =~ s/[\x{201C}\x{201D}\x{201F}\x{FF0C}\x{201E}\x{2E42}]/\x{0022}/g;
36 # additional substitutions - 3.6.
37 $str =~ s/\x{00C6}/AE/g;
38 $str =~ s/\x{00DE}/TH/g;
39 $str =~ s/\x{0152}/OE/g;
40 $str =~ tr/\x{0110}\x{00D0}\x{00D8}\x{0141}\x{2113}\x{02BB}\x{02BC}]['/DDOLl/d;
42 # transformations based on Unicode category codes
43 $str =~ s/[\p{Cc}\p{Cf}\p{Co}\p{Cs}\p{Lm}\p{Mc}\p{Me}\p{Mn}]//g;
45 if ($sf && $sf =~ /^a/o) {
46 my $commapos = index($str, ',');
48 if ($commapos != length($str) - 1) {
49 $str =~ s/,/\x07/; # preserve first comma
54 # since we've stripped out the control characters, we can now
55 # use a few as placeholders temporarily
56 $str =~ tr/+&@\x{266D}\x{266F}#/\x01\x02\x03\x04\x05\x06/;
57 $str =~ s/[\p{Pc}\p{Pd}\p{Pe}\p{Pf}\p{Pi}\p{Po}\p{Ps}\p{Sk}\p{Sm}\p{So}\p{Zl}\p{Zp}\p{Zs}]/ /g;
58 $str =~ tr/\x01\x02\x03\x04\x05\x06\x07/+&@\x{266D}\x{266F}#,/;
61 $str =~ tr/\x{0660}-\x{0669}\x{06F0}-\x{06F9}\x{07C0}-\x{07C9}\x{0966}-\x{096F}\x{09E6}-\x{09EF}\x{0A66}-\x{0A6F}\x{0AE6}-\x{0AEF}\x{0B66}-\x{0B6F}\x{0BE6}-\x{0BEF}\x{0C66}-\x{0C6F}\x{0CE6}-\x{0CEF}\x{0D66}-\x{0D6F}\x{0E50}-\x{0E59}\x{0ED0}-\x{0ED9}\x{0F20}-\x{0F29}\x{1040}-\x{1049}\x{1090}-\x{1099}\x{17E0}-\x{17E9}\x{1810}-\x{1819}\x{1946}-\x{194F}\x{19D0}-\x{19D9}\x{1A80}-\x{1A89}\x{1A90}-\x{1A99}\x{1B50}-\x{1B59}\x{1BB0}-\x{1BB9}\x{1C40}-\x{1C49}\x{1C50}-\x{1C59}\x{A620}-\x{A629}\x{A8D0}-\x{A8D9}\x{A900}-\x{A909}\x{A9D0}-\x{A9D9}\x{AA50}-\x{AA59}\x{ABF0}-\x{ABF9}\x{FF10}-\x{FF19}/0-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-9/;
63 # intentionally skipping step 8 of the NACO algorithm; if the string
64 # gets normalized away, that's fine.
66 # leading and trailing spaces
72 $func$ LANGUAGE 'plperlu' STRICT IMMUTABLE;
74 CREATE OR REPLACE FUNCTION public.search_normalize( TEXT, TEXT ) RETURNS TEXT AS $func$
77 use Unicode::Normalize;
83 # Apply NACO normalization to input string; based on
84 # https://www.loc.gov/aba/pcc/naco/documents/SCA_PccNormalization_Final_revised.pdf
86 # Note that unlike a strict reading of the NACO normalization rules,
87 # output is returned as lowercase instead of uppercase for compatibility
88 # with previous versions of the Evergreen naco_normalize routine.
90 # Convert to upper-case first; even though final output will be lowercase, doing this will
91 # ensure that the German eszett (ß) and certain ligatures (ff, fi, ffl, etc.) will be handled correctly.
92 # If there are any bugs in Perl's implementation of upcasing, they will be passed through here.
95 # remove non-filing strings
96 $str =~ s/\x{0098}.*?\x{009C}//g;
98 # Replace unicode curly single and double quote-like characters with straight
99 $str =~ s/[\x{2018}\x{2019}\x{201B}\x{FF07}\x{201A}]/\x{0027}/g;
100 $str =~ s/[\x{201C}\x{201D}\x{201F}\x{FF0C}\x{201E}\x{2E42}]/\x{0022}/g;
105 # additional substitutions - 3.6.
106 $str =~ s/\x{00C6}/AE/g;
107 $str =~ s/\x{00DE}/TH/g;
108 $str =~ s/\x{0152}/OE/g;
109 $str =~ tr/\x{0110}\x{00D0}\x{00D8}\x{0141}\x{2113}\x{02BB}\x{02BC}][/DDOLl/d;
111 # transformations based on Unicode category codes
112 $str =~ s/[\p{Cc}\p{Cf}\p{Co}\p{Cs}\p{Lm}\p{Mc}\p{Me}\p{Mn}]//g;
114 if ($sf && $sf =~ /^a/o) {
115 my $commapos = index($str, ',');
116 if ($commapos > -1) {
117 if ($commapos != length($str) - 1) {
118 $str =~ s/,/\x07/; # preserve first comma
123 # since we've stripped out the control characters, we can now
124 # use a few as placeholders temporarily
125 $str =~ tr/+&@\x{266D}\x{266F}#/\x01\x02\x03\x04\x05\x06/;
126 $str =~ s/[\p{Pc}\p{Pd}\p{Pe}\p{Pf}\p{Pi}\p{Po}\p{Ps}\p{Sk}\p{Sm}\p{So}\p{Zl}\p{Zp}\p{Zs}]/ /g;
127 $str =~ tr/\x01\x02\x03\x04\x05\x06\x07/+&@\x{266D}\x{266F}#,/;
130 $str =~ tr/\x{0660}-\x{0669}\x{06F0}-\x{06F9}\x{07C0}-\x{07C9}\x{0966}-\x{096F}\x{09E6}-\x{09EF}\x{0A66}-\x{0A6F}\x{0AE6}-\x{0AEF}\x{0B66}-\x{0B6F}\x{0BE6}-\x{0BEF}\x{0C66}-\x{0C6F}\x{0CE6}-\x{0CEF}\x{0D66}-\x{0D6F}\x{0E50}-\x{0E59}\x{0ED0}-\x{0ED9}\x{0F20}-\x{0F29}\x{1040}-\x{1049}\x{1090}-\x{1099}\x{17E0}-\x{17E9}\x{1810}-\x{1819}\x{1946}-\x{194F}\x{19D0}-\x{19D9}\x{1A80}-\x{1A89}\x{1A90}-\x{1A99}\x{1B50}-\x{1B59}\x{1BB0}-\x{1BB9}\x{1C40}-\x{1C49}\x{1C50}-\x{1C59}\x{A620}-\x{A629}\x{A8D0}-\x{A8D9}\x{A900}-\x{A909}\x{A9D0}-\x{A9D9}\x{AA50}-\x{AA59}\x{ABF0}-\x{ABF9}\x{FF10}-\x{FF19}/0-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-9/;
132 # intentionally skipping step 8 of the NACO algorithm; if the string
133 # gets normalized away, that's fine.
135 # leading and trailing spaces
141 $func$ LANGUAGE 'plperlu' STRICT IMMUTABLE;