Add v0.0.1 of Hermes from source tarball
[hermes] / package / src / names.py
1 """Utilities for determing name variants.
2
3    Copyright (c) Andrew Flegg <andrew@bleb.org> 2009.
4    Released under the Artistic Licence."""
5
6 __names__ = [
7     ['Andrew', 'Andy', 'Andi', 'Drew'],
8     ['Christian', 'Chris'],
9     ['Christopher', 'Chris'],
10     ['David', 'Dave'],
11     ['Daniel', 'Dan', 'Danny'],
12     ['Michael', 'Mike', 'Mic', 'Mik', 'Micky'],
13     ['Peter', 'Pete'],
14     ['Robert', 'Rob', 'Bob', 'Bobby', 'Robbie'],
15   ]
16
17 __map__ = {}
18 for row in __names__:
19   for name in row:
20     if (not name in __map__):
21       __map__[name] = set(row)
22     else:
23       __map__[name] = __map__[name].union(row)
24
25 # -----------------------------------------------------------------------
26 def variants(name):
27     """Return a set of names which should be checked for given the input
28        name. Any word which is has a replacement will be replaced, and an
29        iterable list of all variants will be returned."""
30
31     result = set()
32     if (name is None):
33       return result
34     
35     result.add(name)
36     bits = name.split(' ')
37     for bit in bits:
38       if (bit in __map__):
39         for replacement in __map__[bit]:
40           result.add(name.replace(bit, replacement))
41
42     return result
43