Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcdd02cd

Browse files
committed
Sorry - I should have gotten to this sooner. Here's a patch which you should
be able to apply against what you just committed. It rolls soundex intofuzzystrmatch.Remove soundex/metaphone and merge into fuzzystrmatch.Joe Conway
1 parentfb5b85a commitcdd02cd

File tree

14 files changed

+166
-688
lines changed

14 files changed

+166
-688
lines changed

‎contrib/README

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fulltextindex -
5757

5858
fuzzystrmatch -
5959
Levenshtein and Metaphone fuzzy string matching
60-
by Joe Conway <joseph.conway@home.com>
60+
by Joe Conway <joseph.conway@home.com>, Joel Burton <jburton@scw.org>
6161

6262
intarray -
6363
Index support for arrays of int4, using GiST
@@ -86,7 +86,6 @@ mac -
8686

8787
metaphone -
8888
Improved Soundex function
89-
by Joel Burton <jburton@scw.org>
9089

9190
miscutil -
9291
PostgreSQL assert checking and various utility functions
@@ -149,9 +148,6 @@ seg -
149148
Confidence-interval datatype (GiST indexing example)
150149
by Gene Selkov, Jr. <selkovjr@mcs.anl.gov>
151150

152-
soundex -
153-
Soundex function
154-
155151
spi -
156152
Various trigger functions, examples for using SPI.
157153

‎contrib/fuzzystrmatch/README.fuzzystrmatch

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
* Metaphone was originally created by Lawrence Philips and presented in article
2121
* in "Computer Language" December 1990 issue.
2222
*
23+
* soundex()
24+
* -----------
25+
* Folded existing soundex contrib into this one. Renamed text_soundex() (C function)
26+
* to soundex() for consistency.
27+
*
2328
* Permission to use, copy, modify, and distribute this software and its
2429
* documentation for any purpose, without fee, and without a written agreement
2530
* is hereby granted, provided that the above copyright notice and this
@@ -40,12 +45,15 @@
4045
*/
4146

4247

43-
Version 0.1 (3 August, 2001):
48+
Version 0.2 (7 August, 2001):
4449
Functions to calculate the degree to which two strings match in a "fuzzy" way
4550
Tested under Linux (Red Hat 6.2 and 7.0) and PostgreSQL 7.2devel
4651

4752
Release Notes:
4853

54+
Version 0.2
55+
- folded soundex contrib into this one
56+
4957
Version 0.1
5058
- initial release
5159

‎contrib/fuzzystrmatch/README.soundex

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
NOTE: Modified August 07, 2001 by Joe Conway. Updated for accuracy
2+
after combining soundex code into the fuzzystrmatch contrib
3+
---------------------------------------------------------------------
4+
The Soundex system is a method of matching similar sounding names
5+
(or any words) to the same code. It was initially used by the
6+
United States Census in 1880, 1900, and 1910, but it has little use
7+
beyond English names (or the English pronunciation of names), and
8+
it is not a linguistic tool.
9+
10+
The following are some usage examples:
11+
12+
SELECT soundex('hello world!');
13+
14+
CREATE TABLE s (nm text)\g
15+
16+
insert into s values ('john')\g
17+
insert into s values ('joan')\g
18+
insert into s values ('wobbly')\g
19+
20+
select * from s
21+
where soundex(nm) = soundex('john')\g
22+
23+
select nm from s a, s b
24+
where soundex(a.nm) = soundex(b.nm)
25+
and a.oid <> b.oid\g
26+
27+
CREATE FUNCTION text_sx_eq(text, text) RETURNS bool AS
28+
'select soundex($1) = soundex($2)'
29+
LANGUAGE 'sql'\g
30+
31+
CREATE FUNCTION text_sx_lt(text,text) RETURNS bool AS
32+
'select soundex($1) < soundex($2)'
33+
LANGUAGE 'sql'\g
34+
35+
CREATE FUNCTION text_sx_gt(text,text) RETURNS bool AS
36+
'select soundex($1) > soundex($2)'
37+
LANGUAGE 'sql';
38+
39+
CREATE FUNCTION text_sx_le(text,text) RETURNS bool AS
40+
'select soundex($1) <= soundex($2)'
41+
LANGUAGE 'sql';
42+
43+
CREATE FUNCTION text_sx_ge(text,text) RETURNS bool AS
44+
'select soundex($1) >= soundex($2)'
45+
LANGUAGE 'sql';
46+
47+
CREATE FUNCTION text_sx_ne(text,text) RETURNS bool AS
48+
'select soundex($1) <> soundex($2)'
49+
LANGUAGE 'sql';
50+
51+
DROP OPERATOR #= (text,text)\g
52+
53+
CREATE OPERATOR #= (leftarg=text, rightarg=text, procedure=text_sx_eq,
54+
commutator=text_sx_eq)\g
55+
56+
SELECT *
57+
FROM s
58+
WHERE text_sx_eq(nm,'john')\g
59+
60+
SELECT *
61+
from s
62+
where s.nm #= 'john';

‎contrib/fuzzystrmatch/fuzzystrmatch.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,3 +629,71 @@ int _metaphone (
629629

630630
return(META_SUCCESS);
631631
}/* END metaphone */
632+
633+
634+
/*
635+
* SQL function: soundex(text) returns text
636+
*/
637+
PG_FUNCTION_INFO_V1(soundex);
638+
639+
Datum
640+
soundex(PG_FUNCTION_ARGS)
641+
{
642+
charoutstr[SOUNDEX_LEN+1];
643+
char*arg;
644+
645+
arg=_textout(PG_GETARG_TEXT_P(0));
646+
647+
_soundex(arg,outstr);
648+
649+
PG_RETURN_TEXT_P(_textin(outstr));
650+
}
651+
652+
staticvoid
653+
_soundex(constchar*instr,char*outstr)
654+
{
655+
intcount;
656+
657+
AssertArg(instr);
658+
AssertArg(outstr);
659+
660+
outstr[SOUNDEX_LEN]='\0';
661+
662+
/* Skip leading non-alphabetic characters */
663+
while (!isalpha((unsignedchar)instr[0])&&instr[0])
664+
++instr;
665+
666+
/* No string left */
667+
if (!instr[0])
668+
{
669+
outstr[0]= (char)0;
670+
return;
671+
}
672+
673+
/* Take the first letter as is */
674+
*outstr++= (char)toupper((unsignedchar)*instr++);
675+
676+
count=1;
677+
while (*instr&&count<SOUNDEX_LEN)
678+
{
679+
if (isalpha((unsignedchar)*instr)&&
680+
soundex_code(*instr)!=soundex_code(*(instr-1)))
681+
{
682+
*outstr=soundex_code(instr[0]);
683+
if (*outstr!='0')
684+
{
685+
++outstr;
686+
++count;
687+
}
688+
}
689+
++instr;
690+
}
691+
692+
/* Fill with 0's */
693+
while (count<SOUNDEX_LEN)
694+
{
695+
*outstr='0';
696+
++outstr;
697+
++count;
698+
}
699+
}

‎contrib/fuzzystrmatch/fuzzystrmatch.h

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,42 @@
5151
#include"utils/builtins.h"
5252

5353

54-
#defineMAX_LEVENSHTEIN_STRLEN255
55-
#defineMAX_METAPHONE_STRLEN255
56-
57-
typedefstructdynmatrix
58-
{
59-
intvalue;
60-
}dynmat;
61-
6254

6355
/*
6456
* External declarations
6557
*/
6658
externDatumlevenshtein(PG_FUNCTION_ARGS);
6759
externDatummetaphone(PG_FUNCTION_ARGS);
60+
externDatumsoundex(PG_FUNCTION_ARGS);
6861

6962
/*
70-
*Internal declarations
63+
*Soundex
7164
*/
65+
staticvoid_soundex(constchar*instr,char*outstr);
7266

67+
#defineSOUNDEX_LEN 4
68+
#define_textin(str) DirectFunctionCall1(textin, CStringGetDatum(str))
69+
#define_textout(str) DatumGetPointer(DirectFunctionCall1(textout, PointerGetDatum(str)))
7370

71+
/*ABCDEFGHIJKLMNOPQRSTUVWXYZ */
72+
staticconstchar*soundex_table="01230120022455012623010202";
7473

74+
#definesoundex_code(letter) soundex_table[toupper((unsigned char) (letter)) - 'A']
75+
76+
77+
/*
78+
* Levenshtein
79+
*/
7580
#defineSTRLEN(p) strlen(p)
7681
#defineCHAREQ(p1,p2) (*(p1) == *(p2))
7782
#defineNextChar(p) ((p)++)
83+
#defineMAX_LEVENSHTEIN_STRLEN255
84+
7885

86+
/*
87+
* Metaphone
88+
*/
89+
#defineMAX_METAPHONE_STRLEN255
7990

8091
/*
8192
* Original code by Michael G Schwern starts here.

‎contrib/fuzzystrmatch/fuzzystrmatch.sql.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ CREATE FUNCTION levenshtein (text,text) RETURNS int
33

44
CREATE FUNCTION metaphone (text,int) RETURNS text
55
AS 'MODULE_PATHNAME','metaphone' LANGUAGE 'c' with (iscachable, isstrict);
6+
7+
CREATE FUNCTION soundex(text) RETURNS text
8+
AS 'MODULE_PATHNAME', 'soundex' LANGUAGE 'c' with (iscachable, isstrict);
9+
10+
CREATE FUNCTION text_soundex(text) RETURNS text
11+
AS 'MODULE_PATHNAME', 'soundex' LANGUAGE 'c';

‎contrib/metaphone/Makefile

Lines changed: 0 additions & 40 deletions
This file was deleted.

‎contrib/metaphone/README.metaphone

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp