source: trunk/aeres/scripts/build_surname_id.py @ 183

Last change on this file since 183 was 182, checked in by pinsard, 12 years ago

try to progress in author list

File size: 1.9 KB
Line 
1#!/usr/bin/env python
2# -*- coding: iso-8859-1 -*-
3
4"""
5
6===================
7build_surname_id.py
8===================
9
10DESCRIPTION
11===========
12
13generation de la partie "nom" de l'id
14
15
16SEE ALSO
17========
18
19:ref:`surname_id.xsl`
20
21EXAMPLES
22========
23
24cf. doctest
25
26::
27
28    python -v build_surname_id
29
30TODO
31====
32
33EVOLUTIONS
34==========
35
36$Id$
37
38$URL$
39
40- fplod 20120409
41
42  * work with fake data
43
44- fplod 20120407
45
46  * creation
47
48"""
49
50import string
51import sys
52
53def build_surname_id(surname):
54
55
56    """
57    >>> surname = []
58    []
59    >>> surname.append(' Tartempillion ')
60    [' Tartempillion ']
61    >>> surname.append('Tar tempillion ')
62    [' Tartempillion ', 'Tar tempillion ']
63    >>> surname.append("T\'ar tempillion ")
64    [' Tartempillion ', 'Tar tempillion ', "T\'ar tempillion "]
65    >>> surname_id = build_surname_id(surname)
66    ['TARTEMPILLION','TARTEMPILLION','TARTEMPILLION']
67    """
68
69    if len(surname) == 0:
70        print('eee : surname empty')
71        sys.exit(-1)
72
73    # convert to str
74    surname_str = [str(item) for item in surname]
75    for item in surname:
76        print ('iii : item type %s : %s ' % (item, type(item)))
77
78    # remove white space before and after
79    surname_id = map(str.strip,surname_str)
80    #print ('1 sans blan debut fin %s' % surname_id)
81    #
82    # upper
83    surname_id = map(str.upper,surname_id)
84    #print ('2 upper %s' % surname_id)
85    #
86    # remove white space inside
87    surname_id_no_spaces = [x.replace(' ', '') for x in surname_id]
88    #print ('3 sans blanc milieu %s' % surname_id_no_spaces)
89    surname_id = surname_id_no_spaces
90    #
91    # remove punctuation
92    for c in string.punctuation:
93        surname_id_no_punctuation = [x.replace(c, '') for x in surname_id]
94        #print ('4 sans %s avec replace string.punctuation %s' % (c, surname_id_no_punctuation))
95        surname_id = surname_id_no_punctuation
96
97    return surname_id
98
99if __name__ == "__main__":
100    import doctest
101    doctest.testmod()
Note: See TracBrowser for help on using the repository browser.