Python Codin

Bonjour ,

Je vous présente également un petit script que j’ai codé mais il m a rendu fou :/ !!

Alors le principe est du traiter des documents a la file et faire un traitement bien déterminer sur chaque document .

Bon tout est nickel , parfait sauf qu’au bout de 5 sec de l’exec, hé bin si on inspecte le comportement du CPU on trouve qu’il fait 5x que la normal .

Wala le script’oun et vous pouvez en servir volontairement :)


#!/usr/bin/python
import sys,locale,getopt,string
import re
def usage():
print """Usage: tokenizer.py """
def matchComma1(match1):
return match1.group(1)+ " "+ match1.group(2)+ " " +match1.group(3)

def matchComma2(match2):
return match2.group(1)+ " "+ match2.group(2)+ " " +match2.group(3)

def matchComma3(match3):
return match3.group(1)+ "_"+ match3.group(2)+ "_" +match3.group(3)+ "_" +match3.group(4)+ "_" + match3.group(5)

def matchComma4(match4):
return match4.group(1)+ " "+ match4.group(2)+ " "

def matchComma5(match5):
return match5.group(1)+match5.group(2) + "_" + match5.group(4)

def matchComma6(match6):
return match6.group(1) + match6.group(3)

def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "ho", ["help","option"])
except getopt.GetoptError:
usage()
sys.exit(2)

for o, a in opts:
if o in ("-h", "--help"):
usage()
sys.exit()
if o in ("-o","--option"):
optionVariable = a
comma1 = r'(\w)(\?|\+|\#|\!|\;|\:|\"|\(|\)|\/|\&|\%|\$|\*|\[|\]|\{|\})(\w)'
comma2 = r'(\D)(\,)(\D)'
comma3 = r'(\d{2})\.(\d{2})\.(\d{2})\.(\d{2})\.(\d{2})'
comma4 = r'(\w)(\.)'
comma5 = r'(N|Mr|MM|Mme|Mmes|Mle|Mlle|Melle|Mles|Mlles|Melles|Me|Dr|Pr|Prof|Ste|ste)(\.)( )(\w)'
comma6 = r'(\d)( )(\d)'

regComma1 = re.compile(comma1)
regComma2 = re.compile(comma2)
regComma3 = re.compile(comma3)
regComma4 = re.compile(comma4)
regComma5 = re.compile(comma5)
regComma6 = re.compile(comma6)
for line in sys.stdin.readlines():
line1 = regComma1.sub(matchComma1,line)
line2 = regComma2.sub(matchComma2,line1)
line3 = regComma6.sub(matchComma6,line2)
line4 = regComma3.sub(matchComma3,line3)
line5 = regComma5.sub(matchComma5,line4)
line6 = regComma4.sub(matchComma4,line5)
print line6,

if __name__ == "__main__":
main()

Si vous avez des améliorations n’hésitez pas à me les communiquer , comme ça je mes à jour mon demon :)

++

One Response to “Python Codin”

  1. francisco dit :

    Je comprend rien, mais j’aime bien…
    VVVVVOOOOOOOOOOOOIIIIIIIIIIIIIIIIIIIIIILLLLLLLLLLLAAAAAAAAAAA !

Leave a Reply