-
Notifications
You must be signed in to change notification settings - Fork 4
Adding transliterate feature #69
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,8 @@ | |
| becomes u, ç becomes c. | ||
| --trim Enables removing newlines representations from end and beginning. Newline | ||
| representations detected are '\\n', '\\r', '\n', '\r', '<br>', and '<br />'. | ||
| --transliterate <language> Transliterate a strings, for example "ipsum" becomes "իպսում". Language is iso | ||
| 2 letter code. Examples: ru, sr, ua | ||
|
Contributor
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. Wellicht de volledige output van hier toevoegen? |
||
|
|
||
| Add modules (Modify a line, but keep the original as well): | ||
| --add-lower If a line contains a capital letter this will add the lower case variant | ||
|
|
@@ -169,10 +171,11 @@ | |
| from nltk import str2tuple | ||
| from nltk.tokenize import WhitespaceTokenizer | ||
| from tqdm import tqdm | ||
| from transliterate import translit | ||
| from unidecode import unidecode | ||
|
|
||
|
|
||
| version = '4.5.1' | ||
| version = '4.6.0' | ||
|
|
||
| # Search from start to finish for the string $HEX[], with block of a-f0-9 with even number | ||
| # of hex chars. The first match group is repeated. | ||
|
|
@@ -680,6 +683,23 @@ def clean_cut(line, delimiters, fields): | |
| return False, line | ||
|
|
||
|
|
||
| def clean_transliterate(line, language): | ||
| """Transliterate a string | ||
|
|
||
| Params: | ||
| line (Unicode) | ||
|
zyronix marked this conversation as resolved.
|
||
| language (str) | ||
|
|
||
| Returns: | ||
| line (Unicode) | ||
| """ | ||
| cleaned_line = translit(line, language, reversed=True) | ||
| if line != cleaned_line: | ||
| return True, cleaned_line | ||
| else: | ||
| return False, line | ||
|
|
||
|
|
||
| def clean_non_ascii(line): | ||
| """Replace non ascii chars with there ascii representation. | ||
|
|
||
|
|
@@ -1129,6 +1149,12 @@ def clean_up(lines): | |
| if status and config['debug']: | ||
| log.append(f'Clean_umlaut; umlaut replaced; {line_decoded}{linesep}') | ||
|
|
||
| # Transliterate | ||
| if config.get('transliterate') and not stop: | ||
| status, line_decoded = clean_transliterate(line_decoded, config.get('transliterate')) | ||
| if status and config['debug']: | ||
| log.append(f'Clean_transliterate; translitatered; {line_decoded}{linesep}') | ||
|
|
||
| # Replace non-ascii | ||
| if config.get('non-ascii') and not stop: | ||
| status, line_decoded = clean_non_ascii(line_decoded) | ||
|
|
@@ -1409,6 +1435,7 @@ def main(): | |
| 'umlaut': False, | ||
| 'non-ascii': False, | ||
| 'title_case': False, | ||
| 'transliterate': False, | ||
|
|
||
| # Check | ||
| 'length': False, | ||
|
|
@@ -1543,6 +1570,9 @@ def main(): | |
| if arguments.get('--trim'): | ||
| config['trim'] = True | ||
|
|
||
| if arguments.get('--transliterate'): | ||
| config['transliterate'] = arguments.get('--transliterate') | ||
|
zyronix marked this conversation as resolved.
|
||
|
|
||
| # Check modules | ||
| if arguments.get('--check-min-length'): | ||
| config['check-length'] = True | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ nltk | |
| ftfy | ||
| unidecode | ||
| tqdm | ||
| transliterate | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hier ook -s bij "strings"