I have a french regex, and there are accents on it.
I have a printed dictionary (not the pythonic data structure) : a list of words written in uppercase followed by there definition. I want to split my 20Mo dictionary by all the upper cases words.
The issue comes when I have a word itself composed of various words : I need to split the text following the suits of upper characters, with or without blanks. Furthermore the words can have accentuated character.
I have spent one day trying to make it happen, and could not find the answer.
Here is an example :
# -*- coding: utf-8 -*-
import codecs
import re
import string
print "debut pgm"
import regex
dico = """ARRHEMENT. s. m. L'action d'arrher. Achat de grains en vert et sur pied. ARRHER.v. a. S'assurer de quelque chose en donnant des arrhes. Arrher des marchandises.
Arrhé, ée. participe. ARRHES. s. f. pl. L'argent qu'on donne pour assurance de l'exécution d'un marché, et que l'on perd si lemarché n'a pas lieu par la faute de celui qui les a données. Le marché est−il conclu? donnez des arrhes. Il s'est engagé, il a pris des arrhes. Donner des arrhes au coche. •On dit familièrement, qu'On a donné des arrhes au coche, pour faire entendre qu'On s'est engagé dans quelque affaire, dans quelque société. Je ne puis
A 201"""
pattern = r'(?u)\p{Lu}+(?: \p{Lu}+)*|\p{Ll}+'
matches = regex.findall(pattern, dico)
n =0
i = 0
definition = ""
mot = ''
while i < len(matches):
if matches[i].isupper() and len(matches[i])>1:
print definition
definition =""
word = matches[i]
print "[",word,"]"
else:
definition += matches[i] + " "
i = i + 1
the result gives debut pgm
[ ARRHEMENT ]
s m L action d arrher A chat de grains en vert et sur pied
[ ARRHER ]
v a S assurer de quelque chose en donnant des arrhes A rrher des marchandises A rrh ? ? e participe
[ ARRHES ]
But I would like to keep the punctuation, (also to be able to detect the types (I have the list of the types like "s. m.")
I am sure it is crazily simple, so if you can help... Thanks, romain.