#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Cologne_phonetics is a Python implementation of the cologne-phonetics, a phonetic algorithm similar to soundex but optimized for the german language Documentation can be found at https://github.com/provinzkraut/cologne_phonetics A detailed explanation of the cologne phonetics can be found at: https://en.wikipedia.org/wiki/Cologne_phonetics """ __author__ = "Janek Nouvertné" __version__ = "1.2.2" __license__ = "MIT" import sys import re from collections import Iterable from argparse import ArgumentParser, ArgumentTypeError RGX_SPECIAL_CHARS = re.compile(r"[äüößéèáàç]") RGX_SPECIAL_CHAR_REPLACEMENTS = [ (re.compile(r"ä"), "ae"), (re.compile(r"ö"), "oe"), (re.compile(r"ü"), "ue"), (re.compile(r"ß"), "s"), (re.compile(r"é"), "e"), (re.compile(r"è"), "e"), (re.compile(r"á"), "a"), (re.compile(r"à"), "a"), (re.compile(r"ç"), "c"), ] RGX_RULES = [ # ignore special characters that have not been replaced at this point (re.compile(r"[^a-z]"), ''), ## d,t replacements # not before c,s,z (re.compile(r"[dt](?![csz])"), '2'), # before c,s,z (re.compile(r"[dt](?=[csz])"), '8'), ### x replacements # not after c,k,q (re.compile(r"(?