mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Move most /contrib README files into SGML. Some still need conversion
or will never be converted.
This commit is contained in:
@ -1,144 +0,0 @@
|
||||
/*
|
||||
* fuzzystrmatch.c
|
||||
*
|
||||
* Functions for "fuzzy" comparison of strings
|
||||
*
|
||||
* Joe Conway <mail@joeconway.com>
|
||||
*
|
||||
* Copyright (c) 2001-2007, PostgreSQL Global Development Group
|
||||
* ALL RIGHTS RESERVED;
|
||||
*
|
||||
* levenshtein()
|
||||
* -------------
|
||||
* Written based on a description of the algorithm by Michael Gilleland
|
||||
* found at http://www.merriampark.com/ld.htm
|
||||
* Also looked at levenshtein.c in the PHP 4.0.6 distribution for
|
||||
* inspiration.
|
||||
*
|
||||
* metaphone()
|
||||
* -----------
|
||||
* Modified for PostgreSQL by Joe Conway.
|
||||
* Based on CPAN's "Text-Metaphone-1.96" by Michael G Schwern <schwern@pobox.com>
|
||||
* Code slightly modified for use as PostgreSQL function (palloc, elog, etc).
|
||||
* Metaphone was originally created by Lawrence Philips and presented in article
|
||||
* in "Computer Language" December 1990 issue.
|
||||
*
|
||||
* dmetaphone() and dmetaphone_alt()
|
||||
* ---------------------------------
|
||||
* A port of the DoubleMetaphone perl module by Andrew Dunstan. See dmetaphone.c
|
||||
* for more detail.
|
||||
*
|
||||
* soundex()
|
||||
* -----------
|
||||
* Folded existing soundex contrib into this one. Renamed text_soundex() (C function)
|
||||
* to soundex() for consistency.
|
||||
*
|
||||
* difference()
|
||||
* ------------
|
||||
* Return the difference between two strings' soundex values. Kris Jurka
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose, without fee, and without a written agreement
|
||||
* is hereby granted, provided that the above copyright notice and this
|
||||
* paragraph and the following two paragraphs appear in all copies.
|
||||
*
|
||||
* IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
|
||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
|
||||
* LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
|
||||
* DOCUMENTATION, EVEN IF THE AUTHOR OR DISTRIBUTORS HAVE BEEN ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE AUTHOR AND DISTRIBUTORS HAS NO OBLIGATIONS TO
|
||||
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
Version 0.3 (30 June, 2004):
|
||||
|
||||
Release Notes:
|
||||
Version 0.3
|
||||
- added double metaphone code from Andrew Dunstan
|
||||
- change metaphone so that an empty input string causes an empty
|
||||
output string to be returned, instead of throwing an ERROR
|
||||
- fixed examples in README.soundex
|
||||
|
||||
Version 0.2
|
||||
- folded soundex contrib into this one
|
||||
|
||||
Version 0.1
|
||||
- initial release
|
||||
|
||||
Installation:
|
||||
Place these files in a directory called 'fuzzystrmatch' under 'contrib' in the PostgreSQL source tree. Then run:
|
||||
|
||||
make
|
||||
make install
|
||||
|
||||
You can use fuzzystrmatch.sql to create the functions in your database of choice, e.g.
|
||||
|
||||
psql -U postgres template1 < fuzzystrmatch.sql
|
||||
|
||||
installs following functions into database template1:
|
||||
|
||||
levenshtein() - calculates the levenshtein distance between two strings
|
||||
metaphone() - calculates the metaphone code of an input string
|
||||
|
||||
Documentation
|
||||
==================================================================
|
||||
Name
|
||||
|
||||
levenshtein -- calculates the levenshtein distance between two strings
|
||||
|
||||
Synopsis
|
||||
|
||||
levenshtein(text source, text target)
|
||||
|
||||
Inputs
|
||||
|
||||
source
|
||||
any text string, 255 characters max, NOT NULL
|
||||
|
||||
target
|
||||
any text string, 255 characters max, NOT NULL
|
||||
|
||||
Outputs
|
||||
|
||||
Returns int
|
||||
|
||||
Example usage
|
||||
|
||||
select levenshtein('GUMBO','GAMBOL');
|
||||
|
||||
==================================================================
|
||||
Name
|
||||
|
||||
metaphone -- calculates the metaphone code of an input string
|
||||
|
||||
Synopsis
|
||||
|
||||
metaphone(text source, int max_output_length)
|
||||
|
||||
Inputs
|
||||
|
||||
source
|
||||
any text string, 255 characters max, NOT NULL
|
||||
|
||||
max_output_length
|
||||
maximum length of the output metaphone code; if longer, the output
|
||||
is truncated to this length
|
||||
|
||||
Outputs
|
||||
|
||||
Returns text
|
||||
|
||||
Example usage
|
||||
|
||||
select metaphone('GUMBO',4);
|
||||
|
||||
==================================================================
|
||||
-- Joe Conway
|
||||
|
@ -1,66 +0,0 @@
|
||||
NOTE: Modified August 07, 2001 by Joe Conway. Updated for accuracy
|
||||
after combining soundex code into the fuzzystrmatch contrib
|
||||
---------------------------------------------------------------------
|
||||
The Soundex system is a method of matching similar sounding names
|
||||
(or any words) to the same code. It was initially used by the
|
||||
United States Census in 1880, 1900, and 1910, but it has little use
|
||||
beyond English names (or the English pronunciation of names), and
|
||||
it is not a linguistic tool.
|
||||
|
||||
When comparing two soundex values to determine similarity, the
|
||||
difference function reports how close the match is on a scale
|
||||
from zero to four, with zero being no match and four being an
|
||||
exact match.
|
||||
|
||||
The following are some usage examples:
|
||||
|
||||
SELECT soundex('hello world!');
|
||||
|
||||
SELECT soundex('Anne'), soundex('Ann'), difference('Anne', 'Ann');
|
||||
SELECT soundex('Anne'), soundex('Andrew'), difference('Anne', 'Andrew');
|
||||
SELECT soundex('Anne'), soundex('Margaret'), difference('Anne', 'Margaret');
|
||||
|
||||
CREATE TABLE s (nm text);
|
||||
|
||||
INSERT INTO s VALUES ('john');
|
||||
INSERT INTO s VALUES ('joan');
|
||||
INSERT INTO s VALUES ('wobbly');
|
||||
INSERT INTO s VALUES ('jack');
|
||||
|
||||
SELECT * FROM s WHERE soundex(nm) = soundex('john');
|
||||
|
||||
SELECT a.nm, b.nm FROM s a, s b WHERE soundex(a.nm) = soundex(b.nm) AND a.oid <> b.oid;
|
||||
|
||||
CREATE FUNCTION text_sx_eq(text, text) RETURNS boolean AS
|
||||
'select soundex($1) = soundex($2)'
|
||||
LANGUAGE SQL;
|
||||
|
||||
CREATE FUNCTION text_sx_lt(text, text) RETURNS boolean AS
|
||||
'select soundex($1) < soundex($2)'
|
||||
LANGUAGE SQL;
|
||||
|
||||
CREATE FUNCTION text_sx_gt(text, text) RETURNS boolean AS
|
||||
'select soundex($1) > soundex($2)'
|
||||
LANGUAGE SQL;
|
||||
|
||||
CREATE FUNCTION text_sx_le(text, text) RETURNS boolean AS
|
||||
'select soundex($1) <= soundex($2)'
|
||||
LANGUAGE SQL;
|
||||
|
||||
CREATE FUNCTION text_sx_ge(text, text) RETURNS boolean AS
|
||||
'select soundex($1) >= soundex($2)'
|
||||
LANGUAGE SQL;
|
||||
|
||||
CREATE FUNCTION text_sx_ne(text, text) RETURNS boolean AS
|
||||
'select soundex($1) <> soundex($2)'
|
||||
LANGUAGE SQL;
|
||||
|
||||
DROP OPERATOR #= (text, text);
|
||||
|
||||
CREATE OPERATOR #= (leftarg=text, rightarg=text, procedure=text_sx_eq, commutator = #=);
|
||||
|
||||
SELECT * FROM s WHERE text_sx_eq(nm, 'john');
|
||||
|
||||
SELECT * FROM s WHERE s.nm #= 'john';
|
||||
|
||||
SELECT * FROM s WHERE difference(s.nm, 'john') > 2;
|
Reference in New Issue
Block a user