Transliterate English text using the Greek alphabet: Difference between revisions

Adding python task
(New post.)
(Adding python task)
 
(2 intermediate revisions by 2 users not shown)
Line 150:
public static void main(String[] args) {
List<String> tests = List.of(
"The quick brown fox jumpedjumps over the lazy dog.", // Note: "jumps" not "jumped"
"""
I was looking at some rhododendrons in my back garden,
Line 176:
for ( String test : tests ) {
String greek = test;
for ( String[] pair : pairs ) {
greek = greek.replace(pair[0], pair[1]);
}
for ( int i = 0; i < greek.length(); i++ ) {
if ( greek.charAt(i) == 'σs' && ! Character.isAlphabetic(greek.charAt(i + 1)) ) {
greek = greek.substring(0, i) + 'ς' + greek.substring(i + 1);
}
}
}
for ( String[] pair : pairs ) {
greek = greek.replace(pair[0], pair[1]);
}
System.out.println(test + System.lineSeparator() + " =>" + System.lineSeparator() + greek);
System.out.println("=".repeat(65));
Line 193:
</syntaxhighlight>
<pre>
The quick brown fox jumpedjumps over the lazy dog.
=>
Θε κυικ βροων ϕοξ ιυμπεδιυμπς οβερ θε λαζυ δογ.
=================================================================
I was looking at some rhododendrons in my back garden,
Line 623:
=>
<theta><epsilon> <delta><omicron><gamma>
</pre>
 
=={{header|Python}}==
{{trans|Julia}}
Implementation:
<syntaxhighlight lang="python">import re
 
# Input texts
texts = [
"The quick brown fox jumped over the lazy dog.",
"""I was looking at some rhododendrons in my back garden,
dressed in my khaki shorts, when the telephone rang.
 
As I answered it, I cheerfully glimpsed that the July sun
caused a fragment of black pine wax to ooze on the velvet quilt
laying in my patio.""",
"sphinx of black quartz, judge my vow."
]
 
# Mapping of replacements
replacements = [
("ch", "χ"), ("th", "θ"), ("ps", "ψ"), ("ph", "f"), (r"s(\W)", r"ς\1"), ("Ch", "Χ"),
("Th", "Θ"), ("Ps", "Ψ"), ("Ph", "F"), ("ee", "h"), ("ck", "κ"), ("rh", "r"), ("kh", "χ"),
("Kh", "Χ"), ("oo", "w"), ("a", "α"), ("b", "β"), ("c", "κ"), ("d", "δ"), ("e", "ε"),
("f", "φ"), ("g", "γ"), ("h", "η"), ("i", "ι"), ("j", "ι"), ("k", "κ"), ("l", "λ"),
("m", "μ"), ("n", "ν"), ("o", "ο"), ("p", "π"), ("q", "κ"), ("r", "ρ"), ("s", "σ"),
("t", "τ"), ("u", "υ"), ("v", "β"), ("w", "ω"), ("x", "ξ"), ("y", "υ"), ("z", "ζ"),
("D", "Δ"), ("F", "Φ"), ("G", "Γ"), ("J", "I"), ("L", "Λ"), ("P", "Π"), ("Q", "Κ"),
("R", "Ρ"), ("S", "Σ"), ("Y", "U"), ("W", "Ω"), ("X", "Ξ")
]
 
# Function to apply replacements
def replace_text(text, replacements):
for old, new in replacements:
if re.search(r"\W", old): # If the key contains special characters, treat it as a regex
text = re.sub(old, new, text)
else:
text = text.replace(old, new)
return text
 
# Apply replacements and print the results
for txt in texts:
print(f"{txt}\n=>")
txt = replace_text(txt, replacements)
print(f"{txt}\n" + "="*65)</syntaxhighlight>{{out}}
<pre>
The quick brown fox jumped over the lazy dog.
=>
Θε κυικ βροων φοξ ιυμπεδ οβερ θε λαζυ δογ.
=================================================================
I was looking at some rhododendrons in my back garden,
dressed in my khaki shorts, when the telephone rang.
 
As I answered it, I cheerfully glimpsed that the July sun
caused a fragment of black pine wax to ooze on the velvet quilt
laying in my patio.
=>
I ωας λωκινγ ατ σομε ροδοδενδρονς ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ χακι σηορτς, ωηεν θε τελεφονε ρανγ.
 
Aς I ανσωερεδ ιτ, I χηρφυλλυ γλιμψεδ θατ θε Iυλυ συν
καυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.
=================================================================
sphinx of black quartz, judge my vow.
=>
σφινξ οφ βλακ κυαρτζ, ιυδγε μυ βοω.
=================================================================
</pre>
 
Line 726 ⟶ 794:
=={{header|Wren}}==
{{libheader|Wren-str}}
<syntaxhighlight lang="ecmascriptwren">import "./str" for Char, Greek
 
var English2Greek = Fn.new { |text|
3

edits