-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better cleaning #8
base: master
Are you sure you want to change the base?
Changes from 7 commits
c2490d1
253cb54
3f75ccf
6d59df3
4e5be21
454ca50
045c8f0
2261c92
5f11ac4
330169a
fd5d9ee
3ccc267
9b90da3
a3017f8
bb92a1d
01cfa2a
f6e2e0b
221584a
904ac5c
60acc23
5ecc80f
3b2faa7
25c3461
35709fe
aaf5f95
30e3f3b
2a5e3b2
1e1b9ca
3000457
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,14 +50,17 @@ | |
|
||
|
||
def clean_query(q): | ||
q = re.sub(r'([\d]{5})', r' \1 ', q, flags=re.IGNORECASE) | ||
q = re.sub(r'(^| )(boite postale|b\.?p\.?|cs|tsa|cidex) *(n(o|°|) *|)[\d]+ *', r'\1', q, flags=re.IGNORECASE) | ||
q = re.sub(r'([\d]{2})[\d]{3}(.*)c(e|é)dex ?[\d]*', r'\1\2', q, flags=re.IGNORECASE) | ||
q = re.sub(r'([^\d ])([\d]{5})([^\d]|$)', r'\1 \2 ', q, flags=re.IGNORECASE) | ||
q = re.sub('c(e|é)dex ?[\d]*', '', q, flags=re.IGNORECASE) | ||
q = re.sub(r'\b(bp|cs|tsa|cidex) *[\d]*', '', q, flags=re.IGNORECASE) | ||
q = re.sub('\d{,2}(e|[eè]me) ([eé]tage)', '', q, flags=re.IGNORECASE) | ||
q = re.sub(r'((fax|t[eé]l|t[eé]l[eé]copieur)[ :,\.]*|)(\d{10}|[0-9][0-9][ -\./]\d\d[-\./ ]\d\d[-\./ ]\d\d[-\./ ]\d\d)', '', q, flags=re.IGNORECASE) | ||
q = re.sub(' {2,}', ' ', q, flags=re.IGNORECASE) | ||
q = re.sub('[ -]s/[ -]', ' sur ', q, flags=re.IGNORECASE) | ||
q = re.sub('[ -]s/s[ -]', ' sous ', q, flags=re.IGNORECASE) | ||
q = re.sub('^lieux?[ -]?dits?\\b(?=.)', '', q, flags=re.IGNORECASE) | ||
q = re.sub(r'(^| )(([A-Z]) ([A-Z]) (([A-Z]) )?(([A-Z]) )?(([A-Z])( |$))?)', r'\1\2\3\4\6\8\10 ', q, flags=re.IGNORECASE) | ||
q = q.strip() | ||
return q | ||
|
||
|
@@ -116,14 +119,17 @@ def flag_housenumber(tokens): | |
|
||
def fold_ordinal(s): | ||
"""3bis => 3b.""" | ||
if s[0].isdigit() and not s.isdigit(): | ||
if s is not None and s !='' and s[0].isdigit() and not s.isdigit(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this needs to be fixed properly beforehand. I'll have a look. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No way to reproduce the issue, neither from the shell, the pyshell or the http API. Can you be a bit more specific on how you get the issue here? A simple way to reproduce from shell or pyshell would help :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs either a reproducable test case (so we can understand) either removal :) |
||
try: | ||
number, ordinal = FOLD_PATTERN.findall(s)[0] | ||
except (IndexError, ValueError): | ||
pass | ||
else: | ||
s = s.update('{}{}'.format(number, | ||
try: | ||
s = s.update('{}{}'.format(number, | ||
FOLD.get(ordinal.lower(), ordinal))) | ||
except: | ||
pass | ||
return s | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regex is quite slow, I'm not sure we wanna go that far in cleaning.
Have you had a look on perfs? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regexp are not that slow (I measured 3µs for this one)... and it is called just once to clean the query