Skip to content
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

remove all spécial caracters from the sentence #97

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/corporacreator/preprocessors/fr.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
import re

# All special characters
FILTER_SYMBOLES_REG = re.compile(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While FILTER_SYMBOLES_REG seems useful what might be better is a white list instead of a black list.

For example, the characters 男性 are not in your black list and would pass through un-altered.

r'[\{\}\[\]«»_:\|\(\)\\…"(^—)=&\ô*'
r'/µ#@℗`~¹½¼¾¿º±↨↑↓▼→▲←↔∟§°‼¸‰'
r'‘¶“”•—´☺☻♥♦♠♣•◘○◙♂►♀☼♫♪¢¦Ξ≈˜†'
r'√ƒοΔδΛΓκιςζυσρΣγτθΘφΦηχξβωγΩΨ◊░▒▓'
r'│├╚┼┬┴└┐┤╝╗╬╣║ßÞ═™›³ª¯¬®]+|( \-)|(\- )')


# Detect abreviation ex: TVA, T V A
EXCLUDE_ABBREVIATION_REG = re.compile(r'([A-Z]){2,3}|(( [A-Z] )( ?[A-Z]){1, })|([A-Z][.]+)|( [A-Z] )')



def fr(client_id, sentence):
"""Cleans up the passed sentence, removing or reformatting invalid data.

Expand All @@ -9,4 +25,7 @@ def fr(client_id, sentence):
(str): Cleaned up sentence. Returning None or a `str` of whitespace flags the sentence as invalid.
"""
# TODO: Clean up fr data
sentence = FILTER_SYMBOLES_REG.sub('', sentence)
if EXCLUDE_ABBREVIATION_REG.search(sentence) is not None:
return None
return sentence