Package: cologne-phonetics
Cologne-phoneticsContentsCologne-phoneticsIntroductionExamplesInstallationUsageModule contentsencodecompareExamplesCommand line interfaceSpecial charactersWord breaks and hyphensUmlaut and special character replacementChangelog1.2.01.2.11.2.21.2.31.2.41.3.01.3.12.0.0IntroductionCologne-phonetics is a phonetic algorithm similar to Soundex, wich encodes words
into a phonetic code, making it possible to compare how theysoundrather than how they’rewritten.
It was developed by Hans Postel and contrary to Soundex, it’s designed specific
for the german language.It involves three steps:Generate a code by representing every letter from left to right with a digit, according to a conversion tableRemove double digitsRemove every occurrence of ‘0’, except as a leading digitThe module itself is quite simple and consists only of theencodeandcomparefunctions
and a simple command line interface.Examples$cologne_phonetics.py"peter pédter"127,127$cologne_phonetics.py"umwelt umhwält"06352,06352$cologne_phonetics.py"urlaub uhrlaup"0751,0751As you can see, similar sounding names produce the same result, with respect to thecorrectpronunciation.$cologne_phonetics.py"peter peta"127,12This does not give the same result for each word because they maylooksimilar,
but (when pronounced correctly) don’t reallysoundalike.Installationcologne_phonetics runs with Python 3.4+ or PyPy 3.5.
It is available onPyPiand can be installed it via pip:pipinstallcologne_phoneticsUsageModule contentsencode(data,concat=False)Return a list of result tuples.Each tuple consists of the string that was encoded and its result.If the input string is altered in any way before encoding, the tuple will
contain the altered version.>>>cologne_phonetics.encode("bäteS")>>>[('baetes','128')]Ifconcat=Trueis passed, words connected with hyphens will be treated as
a single words.Most of the time, the list will belen(result_list) == 1. Only if the input string
contains a space character or a hyphen it is splitted into substrings and each
substring will be encoded seperately.compare(*data,concat=False)Parameter*data. Either at last 2 positional arguments or an iterableReturnsTrueif all encoded strings are equal, elseFalseRaisesValueError.
If only one value is submitted or the submitted Iterable is of lenght 1.Command line interface$cologne_phonetics.pyhello05$cologne_phonetics.pyhelloworld05,3752Optional arguments-h,--helpshow this help message and exit-c,--concattreat words connected by hyphens as seperate words-v,--verboseshow detailed information-p,--prettyformat output nicelySpecial charactersSpecial characters are all characters that are not ascii-characters between A and Z.
Most special characters are simply ignored, but even within the set of special characters,
there are some that are evenmorespecial.Word breaks and hyphensBy default, words connected by hyphens, e.g.meier-lüdenscheidare seperated.
Someier-lüdenscheidwould become'67', '52682'. If you
want it to be treated as a single word, you can pass aconcat=Trueto the encode functions.While at first this doesn’t seem to make a difference in the result, other than it being split
into a list of strings, in some cases it can make a difference.>>>cologne_phonetics.encode("weiss-chemie")>>>[('weiss','38'),('chemie','46')]>>>cologne_phonetics.encode("weiss-chemie",concat=True)>>>[('weiss-chemie','386')]As you can see, a4got lost here.
In case youreallywant to compare the concatenated words you may use this option,
but in general there’s not much use to it.Umlaut and special character replacementUmlaute and some other special characters are converted to their non-special equivalent.UmlautconversionüueöoeäaeßséeèeáaàaChangelog1.2.0Removedencode_many()encode()now allways returns a list of result tuplesAdded–verboseand–prettyoptions to CLINew function:compare()1.2.1Fixed an error that would lead to case sensitive comparison incompare1.2.2Another error incomparewas found (and fixed); Compare didn’t actually compare output. It compared input. This was due to bad tests and introduced in 1.2.0, with the change that madeencodealways return a tuple as a result1.2.3PyPy 3.5 is now officially supportedA bug was fixed that would leadencodeto sometimes an preprocessed rather than the altered string in the result tuple1.2.4Drop support for Python 3.4 and 3.5Add tests for Python 3.8 and 3.9Remove deprecatedIterableimport. See #11.3.0Add more robust replacement of diacritic usingunicodedata(provided byTobias Bengfort)Add type hintsFix issue whereconcatparameter ofcomparewasn’t passed toencode1.3.1Run tests against Python 3.10Add missing Readme to pyproject.tomlDrop Python 3.6 support2.0.0Drop Python 3.7 supportTest against Python 3.11 and 3.12