-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Greek transliteration enhancements (#3)
* Enhancements: - greek_transliteration can handle some punctuation marks * Translitation function fixes, tests and readme
- Loading branch information
Showing
3 changed files
with
55 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,10 +1,30 @@ | ||
def greek_transliteration(string: str): | ||
eng = "abcdefghijklmnoprstuvwxyzABCDEFGHIJKLMNOPRSTUVWXYZ" | ||
el = "αβψδεφγηιξκλμνοπρστθωςχυζΑΒΨΔΕΦΓΗΙΞΚΛΜΝΟΠΡΣΤΘΩςΧΥΖ" | ||
eng = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
el = "αβψδεφγηιξκλμνοπ;ρστθωςχυζΑΒΨΔΕΦΓΗΙΞΚΛΜΝΟΠ:ΡΣΤΘΩςΧΥΖ" | ||
diaresis = {"i": "ϊ", "I": "Ϊ", "y": "ϋ", "Y": "Ϋ"} | ||
accent = {"a": "ά", "e": "έ", "h": "ή", "i": "ί", "o": "ό", "y": "ύ", "v": "ώ"} | ||
diaresis_accent = {"i": "ΐ", "y": "ΰ"} | ||
|
||
new_string = "" | ||
for i in string: | ||
if i in eng: | ||
new_string += el[eng.index(i)] | ||
for i, letter in enumerate(string): | ||
if letter in eng: | ||
if i != len(string) - 1 and letter == "W": | ||
if string[i + 1] in diaresis_accent.keys(): | ||
new_string += diaresis_accent[string[i + 1]] | ||
else: | ||
new_string += el[eng.index(letter)] | ||
elif (string[i - 1] == "W" and letter in diaresis.keys()) or ( | ||
string[i - 1] in (";", ":") | ||
and (letter in accent.keys() or letter in diaresis.keys()) | ||
): | ||
continue | ||
else: | ||
new_string += el[eng.index(letter)] | ||
elif letter in (";", ":"): | ||
if letter == ";": | ||
new_string += accent[string[i + 1]] | ||
else: | ||
new_string += diaresis[string[i + 1]] | ||
else: | ||
new_string += i | ||
new_string += letter | ||
return new_string |
This file contains 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