source: trunk/aeres/scripts/build_firstname_id.py @ 182

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

try to progress in author list

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