From 36da02feaf635168f08ea06471fc1bfc38ebc3d4 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 3 Feb 2004 19:42:57 +0000 Subject: Tidy files, add copyright notices, add make dist target svn:r84 --- metaphone.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'metaphone.py') diff --git a/metaphone.py b/metaphone.py index 99ae068..9c261d6 100644 --- a/metaphone.py +++ b/metaphone.py @@ -1,4 +1,13 @@ #!/usr/bin/python2 +# Copyright 2003-2004, Nick Mathewson. See LICENSE for licensing info. + +"""metaphone.py -- Pure-python metaphone implementation. + + (This is not guaranteed to match the real metaphone algorithm; I + haven't tested it thorougly enough. Let me know if you find bugs. + + Based on the original C++ metaphone implementation.) +""" import string @@ -36,16 +45,15 @@ SINGLETONS = { 'v': 'f', 'x': 'ks', 'z': 's', - - } ALLCHARS = "".join(map(chr, range(256))) NONLCCHARS = "".join([c for c in ALLCHARS if not c.islower()]) def metaphone(s): + """Return the metaphone equivalent of a provided string""" s = s.lower() s = s.translate(ALLCHARS, NONLCCHARS) - + if not s: return "" # If ae, gn, kn, pn, wr then drop the first letter. @@ -180,11 +188,11 @@ def metaphone(s): def demo(a): print a, "=>", metaphone(a) -print __name__ +print __name__ if __name__ == '__main__': demo("Nick. Mathewson") demo("joe schmidt") demo("Beethoven") - demo("Andrea Plaid") + demo("Because the world is round") -- cgit v1.2.3-70-g09d2