Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8ace511

Browse files
committed
This directory contains a module that implements the "Metaphone" code as
a PostgreSQL user-defined function. The Metaphone system is a method of matching similar sounding names (or any words) to the same code. Metaphone was invented by Lawrence Philips as an improvement to the popular name-hashing routine, Soundex. This metaphone code is from Michael Kuhn, and is detailed at http://aspell.sourceforge.net/metaphone/metaphone-kuhn.txt Joel Burton
1 parent 2c6373f commit 8ace511

File tree

7 files changed

+452
-2
lines changed

7 files changed

+452
-2
lines changed

contrib/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Header: /cvsroot/pgsql/contrib/Makefile,v 1.18 2001/03/14 00:57:43 tgl Exp $
1+
# $Header: /cvsroot/pgsql/contrib/Makefile,v 1.19 2001/05/09 23:00:44 momjian Exp $
22

33
subdir = contrib
44
top_builddir = ..
@@ -15,6 +15,7 @@ WANTED_DIRS = \
1515
lo \
1616
mSQL-interface \
1717
mac \
18+
metaphone \
1819
miscutil \
1920
noupdate \
2021
oid2name \

contrib/README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ mac -
7272
Support functions for MAC address types
7373
by Lawrence E. Rosenman <ler@lerctr.org>
7474

75+
metaphone -
76+
Improved Soundex function
77+
by Joel Burton <jburton@scw.org>
78+
7579
miscutil -
7680
PostgreSQL assert checking and various utility functions
7781
by Massimo Dal Zotto <dz@cs.unitn.it>

contrib/metaphone/Makefile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#
2+
# $Header: /cvsroot/pgsql/contrib/metaphone/Attic/Makefile,v 1.1 2001/05/09 23:00:44 momjian Exp $
3+
#
4+
5+
subdir = contrib/metaphone
6+
top_builddir = ../..
7+
include $(top_builddir)/src/Makefile.global
8+
9+
NAME := metaphone
10+
SONAME := $(NAME)$(DLSUFFIX)
11+
12+
override CPPFLAGS += -I$(srcdir)
13+
override CFLAGS += $(CFLAGS_SL)
14+
15+
all: $(SONAME) $(NAME).sql
16+
17+
$(NAME).sql: $(NAME).sql.in
18+
sed 's,@MODULE_FILENAME@,$(libdir)/contrib/$(SONAME),g' $< >$@
19+
20+
install: all installdirs
21+
$(INSTALL_SHLIB) $(SONAME) $(libdir)/contrib
22+
$(INSTALL_DATA) $(NAME).sql $(datadir)/contrib
23+
$(INSTALL_DATA) README.$(NAME) $(docdir)/contrib
24+
25+
installdirs:
26+
$(mkinstalldirs) $(libdir)/contrib $(datadir)/contrib $(docdir)/contrib
27+
28+
uninstall:
29+
rm -f $(libdir)/contrib/$(SONAME) $(datadir)/contrib/$(NAME).sql $(docdir)/contrib/README.$(NAME)
30+
31+
clean distclean maintainer-clean:
32+
rm -f $(SONAME) $(NAME).o $(NAME).sql
33+
34+
depend dep:
35+
$(CC) -MM -MG $(CFLAGS) *.c > depend
36+
37+
ifeq (depend,$(wildcard depend))
38+
include depend
39+
endif

contrib/metaphone/README.metaphone

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
This directory contains a module that implements the "Metaphone" code as
2+
a PostgreSQL user-defined function. The Metaphone system is a method of
3+
matching similar sounding names (or any words) to the same code.
4+
5+
Metaphone was invented by Lawrence Philips as an improvement to the popular
6+
name-hashing routine, Soundex.
7+
8+
This metaphone code is from Michael Kuhn, and is detailed at
9+
http://aspell.sourceforge.net/metaphone/metaphone-kuhn.txt
10+
11+
Code for this (including this help file!) was liberally borrowed from
12+
the soundex() module for PostgreSQL.
13+
14+
There are two functions:
15+
metaphone(text) : returns hash of a name
16+
metaphone(text,int) : returns hash (maximum length of int) of name
17+
18+
---
19+
20+
To install it, first configure the main source tree, then run make;
21+
make install in this directory. Finally, load the function definition
22+
with psql:
23+
24+
psql -f PREFIX/share/contrib/metaphone.sql
25+
26+
The following are some usage examples:
27+
28+
SELECT text_metaphone('hello world!');
29+
SELECT text_metaphone('hello world!', 4);
30+
31+
CREATE TABLE s (nm text)\g
32+
33+
insert into s values ('john')\g
34+
insert into s values ('joan')\g
35+
insert into s values ('wobbly')\g
36+
37+
select * from s
38+
where text_metaphone(nm) = text_metaphone('john')\g
39+
40+
select nm from s a, s b
41+
where text_metaphone(a.nm) = text_metaphone(b.nm)
42+
and a.oid <> b.oid\g
43+
44+
CREATE FUNCTION text_mp_eq(text, text) RETURNS bool AS
45+
'select text_metaphone($1) = text_metaphone($2)'
46+
LANGUAGE 'sql'\g
47+
48+
CREATE FUNCTION text_mp_lt(text,text) RETURNS bool AS
49+
'select text_metaphone($1) < text_metaphone($2)'
50+
LANGUAGE 'sql'\g
51+
52+
CREATE FUNCTION text_mp_gt(text,text) RETURNS bool AS
53+
'select text_metaphone($1) > text_metaphone($2)'
54+
LANGUAGE 'sql';
55+
56+
CREATE FUNCTION text_mp_le(text,text) RETURNS bool AS
57+
'select text_metaphone($1) <= text_metaphone($2)'
58+
LANGUAGE 'sql';
59+
60+
CREATE FUNCTION text_mp_ge(text,text) RETURNS bool AS
61+
'select text_metaphone($1) >= text_metaphone($2)'
62+
LANGUAGE 'sql';
63+
64+
CREATE FUNCTION text_mp_ne(text,text) RETURNS bool AS
65+
'select text_metaphone($1) <> text_metaphone($2)'
66+
LANGUAGE 'sql';
67+
68+
DROP OPERATOR #= (text,text)\g
69+
70+
CREATE OPERATOR #= (leftarg=text, rightarg=text, procedure=text_mp_eq,
71+
commutator=text_mp_eq)\g
72+
73+
SELECT *
74+
FROM s
75+
WHERE text_mp_eq(nm,'pillsbury')\g
76+
77+
SELECT *
78+
from s
79+
where s.nm #= 'pillsbury';

0 commit comments

Comments
 (0)