Transliterate English text using the Greek alphabet: Difference between revisions

From Rosetta Code
Content added Content deleted
(Adding python task)
 
(24 intermediate revisions by 11 users not shown)
Line 1: Line 1:
{{draft task}}
{{task}}
[[Category: String manipulation]]
[[Category: String manipulation]]
[[Category:Simple]]
[[Category:Simple]]
Line 96: Line 96:
<br>
<br>



=={{header|J}}==
{{trans|Julia}}
Implementation:
<syntaxhighlight lang="j">endings=: {{
W=. (#~ tolower=toupper) (32}.127{.a.)-.":1234567890x
,(x,"1 0 W);&(7&u:)"1 y,"1 0 W
}}

trans=: rplc&(7 u:L:0 ".{{)n
'ch';'χ'; 'th';'θ'; 'ps';'ψ'; 'ph';'f'; ('s' endings 'ς'), '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';'Ξ'
}} -.LF)^:_</syntaxhighlight>

Examples:
<syntaxhighlight lang="j">txt1=:'The quick brown fox jumped over the lazy dog.'
txt2=:{{)n
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.
}}

txt3=: 'sphinx of black quartz, judge my vow.'

trans txt1
Θε κυικ βροων φοξ ιυμπεδ οβερ θε λαζυ δογ.
trans txt2
I ωας λωκινγ ατ σομε ροδοδενδρονς ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ χακι σηορτς, ωηεν θε τελεφονε ρανγ.
Aς I ανσωερεδ ιτ, I χηρφυλλυ γλιμψεδ θατ θε Iυλυ συν
καυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.

trans txt3
σφινξ οφ βλακ κυαρτζ, ιυδγε μυ βοω.</syntaxhighlight>

=={{header|Java}}==
<syntaxhighlight lang="java">
import java.util.List;

public final class TransliterateEnglishTextUsingTheGreekAlphabet {

public static void main(String[] args) {
List<String> tests = List.of(
"The quick brown fox jumps over the lazy dog.", // Note: "jumps" not "jumped"
"""
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.");
String[][] pairs = new String[][] {
{ "CH", "Χ" }, { "Ch", "Χ" }, { "ch", "χ" }, { "CK", "Κ" }, { "Ck", "Κ" }, { "ck", "κ" },
{ "EE", "Η" }, { "Ee", "Η" }, { "ee", "η" }, { "KH", "Χ" }, { "Kh", "Χ" }, { "kh", "χ" },
{ "OO", "Ω" }, { "Oo", "Ω" }, { "oo", "ω" }, { "PH", "Φ" }, { "Ph", "Φ" }, { "ph", "ϕ" },
{ "PS", "Ψ" }, { "Ps", "Ψ" }, { "ps", "ψ" }, { "RH", "Ρ" }, { "Rh", "Ρ" }, { "rh", "ρ" },
{ "TH", "Θ" }, { "Th", "Θ" }, { "th", "θ" }, { "A", "Α" }, { "a", "α" }, { "B", "Β" },
{ "b", "β" }, { "C", "Κ" }, { "c", "κ" }, { "D", "Δ" }, { "d", "δ" }, { "E", "Ε" }, { "e", "ε" },
{ "F", "Φ" }, { "f", "ϕ" }, { "G", "Γ" }, { "g", "γ" }, { "H", "Ε" }, { "h", "ε" }, { "I", "Ι" },
{ "i", "ι" }, { "J", "Ι" }, { "j", "ι" }, { "K", "Κ" }, { "k", "κ" }, { "L", "Λ" }, { "l", "λ" },
{ "M", "Μ" }, { "m", "μ" }, { "N", "Ν" }, { "n", "ν" }, { "O", "Ο" }, { "o", "ο" }, { "P", "Π" },
{ "p", "π" }, { "Q", "Κ" }, { "q", "κ" }, { "R", "Ρ" }, { "r", "ρ" }, { "S", "Σ" }, { "s", "σ" },
{ "T", "Τ" }, { "t", "τ" }, { "U", "Υ" }, { "u", "υ" }, { "V", "Β" }, { "v", "β" }, { "W", "Ω" },
{ "w", "ω" }, { "X", "Ξ" }, { "x", "ξ" }, { "Y", "Υ" }, { "y", "υ" }, { "Z", "Ζ" }, { "z", "ζ" } };

for ( String test : tests ) {
String greek = test;
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));
}
}

}
</syntaxhighlight>
<pre>
The quick brown fox jumps 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.
=>
σϕινξ οϕ βλακ κυαρτζ, ιυδγε μυ βοω.
=================================================================
</pre>

=={{header|jq}}==
'''Adapted from [[#Julia]]'''

A point of interest in adapting the approach taken in the Julia entry is that, since jq strings for interpolating variables are not themselves JSON strings, the special case of "ς" must be handled differently.
<syntaxhighlight lang=jq>
def texts: [

"The quick brown fox jumped over the lazy dog.",

"I was looking at some rhododendrons in my back garden,\n" +
"dressed in my khaki shorts, when the telephone rang.\n" +
"\n" +
"As I answered it, I cheerfully glimpsed that the July sun\n" +
"caused a fragment of black pine wax to ooze on the velvet quilt\n" +
"laying in my patio.",

"sphinx of black quartz, judge my vow."
];

# "ς" is handled separately
def replacements:
{
"ch" : "χ", "th" : "θ", "ps" : "ψ", "ph" : "f", "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" : "Ξ" };

def translate($replacements):
gsub("s(?<W>\\W)"; "ς\(.W)")
| reduce ($replacements|keys_unsorted[]) as $key (.;
gsub($key; $replacements[$key])) ;

replacements as $replacements
| texts[]
| ., "=>", translate($replacements), ""
</syntaxhighlight>
'''Invocation'''
<pre>
jq -nr -f transliterate-english-using-Greek.jq
</pre>
{{Output}}
<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.
=>
I ωασ λωκινγ ατ σομε ροδοδενδρονσ ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ χακι σηορτσ, ωηεν θε τελεφονε ρανγ.

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.
=>
Aσ I ανσωερεδ ιτ, I χηρφυλλυ γλιμψεδ θατ θε Iυλυ συν
καυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.

sphinx of black quartz, judge my vow.
=>
σφινξ οφ βλακ κυαρτζ, ιυδγε μυ βοω.
</pre>


=={{header|Julia}}==
=={{header|Julia}}==
<lang ruby>const texts = [
<syntaxhighlight lang="julia">const texts = [
"""The quick brown fox jumped over the lazy dog.""",
"""The quick brown fox jumped over the lazy dog.""",
"""I was looking at some rhododendrons in my back garden,
"""I was looking at some rhododendrons in my back garden,
Line 110: Line 299:
const replacements = [
const replacements = [
"ch" => "χ", "th" => "θ", "ps" => "ψ", "ph" => "f", r"s(\W)" => s"ς\1", "Ch" => "Χ",
"ch" => "χ", "th" => "θ", "ps" => "ψ", "ph" => "f", r"s(\W)" => s"ς\1", "Ch" => "Χ",
"Th" => "Θ", "Ps" => "Ψ", "Ph" => "F", "ee" => "h", "ck" => "κ", "rh" => "r", "kh" => "κ",
"Th" => "Θ", "Ps" => "Ψ", "Ph" => "F", "ee" => "h", "ck" => "κ", "rh" => "r", "kh" => "χ",
"Kh" => "Κ", "oo" => "w", "a" => "α", "b" => "β", "c" => "κ", "d" => "δ", "e" => "ε",
"Kh" => "Χ", "oo" => "w", "a" => "α", "b" => "β", "c" => "κ", "d" => "δ", "e" => "ε",
"f" => "φ", "g" => "γ", "h" => "η", "i" => "ι", "j" => "ι", "k" => "κ", "l" => "λ",
"f" => "φ", "g" => "γ", "h" => "η", "i" => "ι", "j" => "ι", "k" => "κ", "l" => "λ",
"m" => "μ", "n" => "ν", "o" => "ο", "p" => "π", "q" => "κ", "r" => "ρ", "s" => "σ",
"m" => "μ", "n" => "ν", "o" => "ο", "p" => "π", "q" => "κ", "r" => "ρ", "s" => "σ",
Line 125: Line 314:
println("$txt\n", "="^65)
println("$txt\n", "="^65)
end
end
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
Line 138: Line 327:
laying in my patio.
laying in my patio.
=>
=>
Ι ωας λωκινγ ατ σομε ροδοδενδρονς ιν μυ βακ γαρδεν,
I ωας λωκινγ ατ σομε ροδοδενδρονς ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ κακι σηορτς, ωηεν θε τελεφονε ρανγ.
δρεσσεδ ιν μυ χακι σηορτς, ωηεν θε τελεφονε ρανγ.


Ας Ι ανσωερεδ ιτ, Ι χηρφυλλυ γλιμψεδ θατ θε Iυλυ συν
I ανσωερεδ ιτ, I χηρφυλλυ γλιμψεδ θατ θε Iυλυ συν
cαυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
καυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.
λαυινγ ιν μυ πατιο.
=================================================================
=================================================================
Line 150: Line 339:
=================================================================
=================================================================
</pre>
</pre>
=={{header|M2000 Interpreter}}==

<syntaxhighlight lang="m2000 interpreter">
process1=lambda -> {
a=list:="ee":="η", "ch":="χ", "kh":="χ", "ph":="φ", "ps":="ψ", "th":="θ", "ck":="κ", "oo":="ω", "rh":="ρ"
b=list:="a":="α","b":="β","v":="β","g":="γ","d":="δ","e":="ε","z":="ζ","h":="η","i":="ι","j":="ι","c":="κ"
append b, "k":="κ","q":="κ","l":="λ","m":="μ","n":="ν","x":="ξ","o":="ο","p":="π","r":="ρ"
append b, "s":="σ","t":="τ","u":="υ","y":="υ","f":="φ","w":="ω"
=lambda a, b (s as string, no as integer) -> {
long i=1, j=len(s)
string r, rc, crlf={
}
while i<=j
if exist(a, lcase$(mid$(s,i,2))) then
rc=eval$(a)
if mid$(s,i,1)<>left$(eval$(a!),1) then
r+=ucase$(left$(rc,1))
else
r+=rc
end if
i+=2
else.if exist(b,lcase$(mid$(s,i,1))) then
rc=eval$(b) // eval$(b!) is the key
if mid$(s,i,1)<>eval$(b!) then
r+=ucase$(rc)
else.if rc="σ" then
if exist(b,lcase$(mid$(s,i+1,1))) then
r+=rc
else
r+="ς"
end if
else
r+=rc
end if
i++
else
r+=mid$(s,i,1)
i++
end if
end while
=">>>> Text "+no+crlf+s+crlf+" =>"+crlf+r+crlf+crlf
}
}

trans=process1()

report trans("The quick brown fox jumped over the lazy dog.", 1)

eng$={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.}
Report trans(eng$, 2)

Report trans("sphinx of black quartz, judge my vow.", 3)
</syntaxhighlight>
{{out}}
<pre>
>>>> Text 1
The quick brown fox jumped over the lazy dog.
=>
Θε κυικ βροων φοξ ιυμπεδ οβερ θε λαζυ δογ.

>>>> Text 2
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.
=>
Ι ωας λωκινγ ατ σομε ροδοδενδρονς ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ χακι σηορτς, ωηεν θε τελεφονε ρανγ.

Ας Ι ανσωερεδ ιτ, Ι χηρφυλλυ γλιμψεδ θατ θε Ιυλυ συν
καυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.

>>>> Text 3
sphinx of black quartz, judge my vow.
=>
σφινξ οφ βλακ κυαρτζ, ιυδγε μυ βοω.
</pre>

=={{header|Nim}}==
<syntaxhighlight lang="Nim">import std/[strutils, unicode]

const Text = """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."""

# Replacement table.
# It includes greek characters which look like ASCII ones but are actually different
# and coded using specific Unicode code points (as Α, Β, Ε, etc.).
const Replacements = {"CH": "Χ", "Ch": "Χ", "ch": "χ", "CK": "Κ", "Ck": "Κ", "ck": "κ",
"EE": "Η", "Ee": "Η", "ee": "η", "KH": "Χ", "Kh": "Χ", "kh": "χ",
"OO": "Ω", "Oo": "Ω", "oo": "ω", "PH": "Φ", "Ph": "Φ", "ph": "ϕ",
"PS": "Ψ", "Ps": "Ψ", "ps": "ψ", "RH": "Ρ", "Rh": "Ρ", "rh": "ρ",
"TH": "Θ", "Th": "Θ", "th": "θ", "A": "Α", "a": "α", "B": "Β",
"b": "β", "C": "Κ", "c": "κ", "D": "Δ", "d": "δ", "E": "Ε", "e": "ε",
"F": "Φ", "f": "ϕ", "G": "Γ", "g": "γ", "H": "Ε", "h": "ε", "I": "Ι",
"i": "ι", "J": "Ι", "j": "ι", "K": "Κ", "k": "κ", "L": "Λ", "l": "λ",
"M": "Μ", "m": "μ", "N": "Ν", "n": "ν", "O": "Ο", "o": "ο", "P": "Π",
"p": "π", "Q": "Κ", "q": "κ", "R": "Ρ", "r": "ρ", "S": "Σ", "s": "σ",
"T": "Τ", "t": "τ", "U": "Υ", "u": "υ", "V": "Β", "v": "β", "W": "Ω",
"w": "ω", "X": "Ξ", "x": "ξ", "Y": "Υ", "y": "υ", "Z": "Ζ", "z": "ζ"}

# All replacements are done using a single call to "multiReplace".
var text = Text.multiReplace(Replacements)

# Replacing "σ" with "ς" is a bit more complicated, as we have to deal with Unicode strings.
const Sigma1 = "σ".toRunes[0]
const Sigma2 = "ς".toRunes[0]
var runes = text.toRunes
for i in 0..runes.high:
let rune = runes[i]
if rune == Sigma1:
if i == runes.high or not runes[i + 1].isAlpha:
runes[i] = Sigma2
echo runes
</syntaxhighlight>

{{out}}
<pre>Ι ωας λωκινγ ατ σομε ροδοδενδρονς ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ χακι σεορτς, ωεεν θε τελεϕονε ρανγ.

Ας Ι ανσωερεδ ιτ, Ι χηρϕυλλυ γλιμψεδ θατ θε Ιυλυ συν
καυσεδ α ϕραγμεντ οϕ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.
</pre>

=={{header|Perl}}==
<syntaxhighlight lang="perl">use v5.36;
use experimental 'for_list';
use utf8;
binmode(STDOUT, ':utf8');

sub to_Greek ($string) {
my %pre = qw<Ph F ck k ee h J I rh r oo w ph f ch χ th θ ps ψ Ch Χ Th Θ Ps Ψ kh χ 's ' 'ς '>;
my %post = split '', 'aαbβdδeεfφgγhηiιjιkκlλmμnνoοpπqκrρsσtτuυvβwωxξyυzζAΑBΒDΔEΕFΦGΓHΗIΙLΛMΜNΝOΟPΠQΚRΡSΣTΤUΥWΩXΞZΖ';
for my ($k,$v) (%pre, %post) { $string =~ s/$k/$v/g }
$string
}

say "$_\n" . to_Greek $_ . "\n" for
'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.';</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.
Ασ Ι ανσωερεδ ιτ, Ι χηρφυλλυ γλιμψεδ θατ θε Ιυλυ συν cαυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ λαυινγ ιν μυ πατιο.</pre>


=={{header|Phix}}==
=={{header|Phix}}==
Line 155: Line 506:
Just for a laugh, figure out the rules directly from the task description.
Just for a laugh, figure out the rules directly from the task description.
You can run this online [http://phix.x10.mx/p2js/greek.htm here] (and it'll probably look better in a browser than on a Windows console).
You can run this online [http://phix.x10.mx/p2js/greek.htm here] (and it'll probably look better in a browser than on a Windows console).
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">rules</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">task</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">task</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
alpha a
<span style="color: #004080;">sequence</span> <span style="color: #000000;">replacements</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #000000;">task</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
beta b or v
gamma g
delta d
epsilon e (but not ee)
zeta z
eta h or ee (but not ch, kh, ph, rh or th)
theta th
iota i or j
kappa c, k, q or ck (but not ch and kh)
lambda l
mu m
nu n
xi x
omicron o (but not oo)
pi p (but not ph or ps)
rho r or rh
sigma s (but not ps)
tau t (but not th)
upsilon u or y
phi f or ph
chi ch or kh
psi ps
omega w or oo
"""</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">rules</span><span style="color: #0000FF;">()</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">replacements</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #000000;">task</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">suborder</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">,</span><span style="color: #000000;">49</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">","</span><span style="color: #0000FF;">,</span><span style="color: #000000;">50</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">"."</span><span style="color: #0000FF;">,</span><span style="color: #000000;">51</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">52</span><span style="color: #0000FF;">}},</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">rs</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ir</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">(</span><span style="color: #000000;">suborder</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">names</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">reinstate</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">52</span><span style="color: #0000FF;">),</span><span style="color: #000000;">ir</span><span style="color: #0000FF;">,</span><span style="color: #000000;">rs</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">done</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span> <span style="color: #008080;">in</span> <span style="color: #000000;">replacements</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span> <span style="color: #008080;">in</span> <span style="color: #000000;">replacements</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute_all</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">" or"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" and"</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">","</span><span style="color: #0000FF;">,</span><span style="color: #008000;">","</span><span style="color: #0000FF;">})</span>
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute_all</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">" or"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" and"</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">","</span><span style="color: #0000FF;">,</span><span style="color: #008000;">","</span><span style="color: #0000FF;">})</span>
Line 168: Line 549:
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">k</span><span style="color: #0000FF;">-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">k</span><span style="color: #0000FF;">-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #008000;">","</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">),</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">)[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..$]</span>
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #008000;">","</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">),</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">k</span><span style="color: #0000FF;">=</span> <span style="color: #7060A8;">max</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">))</span>
<span style="color: #000000;">names</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"&lt;"</span> <span style="color: #0000FF;">&</span> <span style="color: #7060A8;">proper</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">])</span> <span style="color: #0000FF;">&</span> <span style="color: #008000;">"&gt;"</span>
<span style="color: #000000;">replacements</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">k</span><span style="color: #0000FF;">,</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #000000;">nots</span><span style="color: #0000FF;">}</span>
<span style="color: #000000;">names</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">24</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"&lt;"</span> <span style="color: #0000FF;">&</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">&</span> <span style="color: #008000;">"&gt;"</span>
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..$]</span>
<span style="color: #000000;">k</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">max</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">&</span><span style="color: #000000;">nots</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">))</span>
<span style="color: #000000;">replacements</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">k</span><span style="color: #0000FF;">,</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">reverse</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">),</span><span style="color: #000000;">nots</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">replacements</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">replacements</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">replacements</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">replacements</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">done</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{},</span>
<span style="color: #000000;">suborder</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">,</span><span style="color: #000000;">49</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">","</span><span style="color: #0000FF;">,</span><span style="color: #000000;">50</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">"."</span><span style="color: #0000FF;">,</span><span style="color: #000000;">51</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">52</span><span style="color: #0000FF;">}}</span>
<span style="color: #008080;">while</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">replacements</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">while</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">replacements</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">replacements</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">to</span> <span style="color: #000000;">1</span> <span style="color: #008080;">by</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">replacements</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">to</span> <span style="color: #000000;">1</span> <span style="color: #008080;">by</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span>
Line 193: Line 575:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">(</span><span style="color: #000000;">suborder</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #0000FF;">{</span><span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">(</span><span style="color: #000000;">suborder</span><span style="color: #0000FF;">),</span><span style="color: #000000;">names</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">task</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
<span style="color: #004080;">sequence</span> <span style="color: #0000FF;">{{</span><span style="color: #000000;">sub</span><span style="color: #0000FF;">,</span><span style="color: #000000;">rep</span><span style="color: #0000FF;">},</span><span style="color: #000000;">names</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">rules</span><span style="color: #0000FF;">(),</span>
alpha a
beta b or v
gamma g
delta d
epsilon e (but not ee)
zeta z
eta h or ee (but not ch, kh, ph, rh or th)
theta th
iota i or j
kappa c, k, q or ck (but not ch and kh)
lambda l
mu m
nu n
xi x
omicron o (but not oo)
pi p (but not ph or ps)
rho r or rh
sigma s (but not ps)
tau t (but not th)
upsilon u or y
phi f or ph
chi ch or kh
psi ps
omega w or oo
"""</span><span style="color: #0000FF;">,</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">sub</span><span style="color: #0000FF;">,</span><span style="color: #000000;">rep</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">rules</span><span style="color: #0000FF;">(</span><span style="color: #000000;">task</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">gulp</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">utf8_to_utf32</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ"</span><span style="color: #0000FF;">&</span>
<span style="color: #000000;">gulp</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">utf8_to_utf32</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ"</span><span style="color: #0000FF;">&</span>
<span style="color: #008000;">"αβγδεζηθικλμνξοπρστυφχψω ,.\n"</span><span style="color: #0000FF;">),</span>
<span style="color: #008000;">"αβγδεζηθικλμνξοπρστυφχψω ,.\n"</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">texts</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span>
<span style="color: #000000;">text</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
<span style="color: #008000;">"""The quick brown fox jumped over the lazy dog."""</span><span style="color: #0000FF;">,</span>
The quick brown fox jumped over the lazy dog.
<span style="color: #008000;">"""I was looking at some rhododendrons in my back garden,
I was looking at some rhododendrons in my back garden,
dressed in my khaki shorts, when the telephone rang.
dressed in my khaki shorts, when the telephone rang.
As I answered it, I cheerfully glimpsed that the July sun
As I answered it, I cheerfully glimpsed that the July sun
caused a fragment of black pine wax to ooze on the velvet quilt
caused a fragment of black pine wax to ooze on the velvet quilt
laying in my patio."""</span><span style="color: #0000FF;">,</span>
laying in my patio.
<span style="color: #008000;">"""sphinx of black quartz, judge my vow."""</span><span style="color: #0000FF;">}</span>
sphinx of black quartz, judge my vow."""</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">e</span> <span style="color: #008080;">in</span> <span style="color: #000000;">texts</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">g</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">utf32_to_utf8</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">extract</span><span style="color: #0000FF;">(</span><span style="color: #000000;">gulp</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">substitute_all</span><span style="color: #0000FF;">(</span><span style="color: #000000;">text</span><span style="color: #0000FF;">,</span><span style="color: #000000;">sub</span><span style="color: #0000FF;">,</span><span style="color: #000000;">rep</span><span style="color: #0000FF;">)))</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">g</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">extract</span><span style="color: #0000FF;">(</span><span style="color: #000000;">gulp</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">substitute_all</span><span style="color: #0000FF;">(</span><span style="color: #000000;">e</span><span style="color: #0000FF;">,</span><span style="color: #000000;">sub</span><span style="color: #0000FF;">,</span><span style="color: #000000;">rep</span><span style="color: #0000FF;">))</span>
<span style="color: #000000;">g</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute_all</span><span style="color: #0000FF;">(</span><span style="color: #000000;">g</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">"σ "</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"σ,"</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">"ς "</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"ς,"</span><span style="color: #0000FF;">})</span>
<span style="color: #000000;">g</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute_all</span><span style="color: #0000FF;">(</span><span style="color: #000000;">g</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">"σ "</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"σ,"</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">"ς "</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"ς,"</span><span style="color: #0000FF;">})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s\n=&gt;\n%s\n\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">text</span><span style="color: #0000FF;">,</span><span style="color: #000000;">g</span><span style="color: #0000FF;">})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s\n=&gt;\n%s\n=====\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">e</span><span style="color: #0000FF;">,</span><span style="color: #000000;">g</span><span style="color: #0000FF;">})</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">thedog</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"the dog"</span>
<span style="color: #000000;">g</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">extract</span><span style="color: #0000FF;">(</span><span style="color: #000000;">names</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">substitute_all</span><span style="color: #0000FF;">(</span><span style="color: #000000;">thedog</span><span style="color: #0000FF;">,</span><span style="color: #000000;">sub</span><span style="color: #0000FF;">,</span><span style="color: #000000;">rep</span><span style="color: #0000FF;">)),</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s\n=&gt;\n%s\n\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">thedog</span><span style="color: #0000FF;">,</span><span style="color: #000000;">g</span><span style="color: #0000FF;">})</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.

=>
Θε κυικκ βροων φοξ ιυμπεδ οβερ θε λαζυ δογ.
=====
I was looking at some rhododendrons in my back garden,
I was looking at some rhododendrons in my back garden,
dressed in my khaki shorts, when the telephone rang.
dressed in my khaki shorts, when the telephone rang.
Line 252: Line 608:
caused a fragment of black pine wax to ooze on the velvet quilt
caused a fragment of black pine wax to ooze on the velvet quilt
laying in my patio.
laying in my patio.
sphinx of black quartz, judge my vow.
=>
=>
Θε κυικ βροων φοξ ιυμπεδ οβερ θε λαζυ δογ.
Ι ωας λωκινγ ατ σομε ρηοδοδενδρονς ιν μυ βακκ γαρδεν,

Ι ωας λωκινγ ατ σομε ροδοδενδρονς ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ χακι σηορτς, ωηεν θε τελεφονε ρανγ.
δρεσσεδ ιν μυ χακι σηορτς, ωηεν θε τελεφονε ρανγ.
Ας Ι ανσωερεδ ιτ, Ι χηρφυλλυ γλιμψεδ θατ θε Ιυλυ συν
Ας Ι ανσωερεδ ιτ, Ι χηρφυλλυ γλιμψεδ θατ θε Ιυλυ συν
καυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
καυσεδ α φραγμεντ οφ βλακκ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.
λαυινγ ιν μυ πατιο.
σφινξ οφ βλακ κυαρτζ, ιυδγε μυ βοω.
=====

sphinx of black quartz, judge my vow.
the dog
=>
=>
<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>
</pre>


=={{header|Raku}}==
=={{header|Raku}}==
<lang perl6>sub to-Greek (Str $string is copy) {
<syntaxhighlight lang="raku" line>sub to-Greek (Str $string is copy) {
my %pre = :Ph<F>, :ck<k>, :ee<h>, :J<I>, :rh<r>,:oo<w>, :ph<f>, 's ' => 'ς ';
my %pre = :Ph<F>, :ck<k>, :ee<h>, :J<I>, :rh<r>,:oo<w>, :ph<f>, :ch<χ>,
:th<θ>, :ps<ψ>, :Ch<Χ>, :Th<Θ>, :Ps<Ψ>, :kh<χ>, 's ' => 'ς ';
my %post =
:ch<χ>, :th<θ>, :ps<ψ>, :Ch<Χ>, :Th<Θ>, :Ps<Ψ>, :kh<χ>, :a<α>, :b<β>, :d<δ>,
my %post = :a<α>, :b<β>, :d<δ>, :e<ε>, :f<φ>, :g<γ>, :h<η>, :i<ι>, :j<ι>,
:e<ε>, :f<φ>, :g<γ>, :h<η>, :i<ι>, :j<ι>, :k<κ>, :l<λ>, :m<μ>, :n<ν>, :o<ο>,
:k<κ>, :l<λ>, :m<μ>, :n<ν>, :o<ο>, :p<π>, :q<κ>, :r<ρ>, :s<σ>,
:p<π>, :q<κ>, :r<ρ>, :s<σ>, :t<τ>, :u<υ>, :v<β>, :w<ω>, :x<ξ>, :y<υ>, :z<ζ>,
:t<τ>, :u<υ>, :v<β>, :w<ω>, :x<ξ>, :y<υ>, :z<ζ>, :A<Α>, :B<Β>,
:A<Α>, :B<Β>, :D<Δ>, :E<Ε>, :F<Φ>, :G<Γ>, :H<Η>, :I<Ι>, :L<Λ>, :M<Μ>, :N<Ν>,
:D<Δ>, :E<Ε>, :F<Φ>, :G<Γ>, :H<Η>, :I<Ι>, :L<Λ>, :M<Μ>, :N<Ν>,
:O<Ο>, :P<Π>, :Q<Κ>, :R<Ρ>, :S<Σ>, :T<Τ>, :U<Υ>, :W<Ω>, :X<Ξ>, :Z<Ζ>;
:O<Ο>, :P<Π>, :Q<Κ>, :R<Ρ>, :S<Σ>, :T<Τ>, :U<Υ>, :W<Ω>, :X<Ξ>,
:Z<Ζ>;


$string.=subst(:g, .key, .value ) for flat %pre, %post;
$string.=subst(:g, .key, .value ) for flat %pre, %post;
Line 301: Line 729:
'<' ~ .uniname.subst( /.+<?after LETTER\s>/).lc ~ '>'
'<' ~ .uniname.subst( /.+<?after LETTER\s>/).lc ~ '>'
}).join
}).join
given 'sphinx of black quartz, judge my vow.';</lang>
given 'sphinx of black quartz, judge my vow.';</syntaxhighlight>
{{out}}
{{out}}
<pre>English:
<pre>English:
Line 318: Line 746:
"Greek":
"Greek":


Τηε κυικ βροων φοξ ιυμπεδ οβερ τηε λαζυ δογ.
Θε κυικ βροων φοξ ιυμπεδ οβερ θε λαζυ δογ.


Ι ωας λωκινγ ατ σομε ροδοδενδρονς ιν μυ βακ γαρδεν,
Ι ωας λωκινγ ατ σομε ροδοδενδρονς ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ κηακι σηορτσ, ωηεν τηε τελεφονε ρανγ.
δρεσσεδ ιν μυ χακι σηορτσ, ωηεν θε τελεφονε ρανγ.


Ας Ι ανσωερεδ ιτ, Ι χηρφυλλυ γλιμπσεδ τηατ τηε Ιυλυ συν
Ας Ι ανσωερεδ ιτ, Ι χηρφυλλυ γλιμψεδ θατ θε Ιυλυ συν
cαυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον τηε βελβετ κυιλτ
cαυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.
λαυινγ ιν μυ πατιο.


Line 333: Line 761:
sphinx of black quartz, judge my vow.
sphinx of black quartz, judge my vow.
<sigma><phi><iota><nu><xi> <omicron><phi> <beta><lamda><alpha><kappa> <kappa><upsilon><alpha><rho><tau><zeta>, <iota><upsilon><delta><gamma><epsilon> <mu><upsilon> <beta><omicron><omega>.</pre>
<sigma><phi><iota><nu><xi> <omicron><phi> <beta><lamda><alpha><kappa> <kappa><upsilon><alpha><rho><tau><zeta>, <iota><upsilon><delta><gamma><epsilon> <mu><upsilon> <beta><omicron><omega>.</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby" line>replacements =
{"ch" => "χ", "th" => "θ", "ps" => "ψ", "ph" => "f", "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" => "Ξ"}
pattern = Regexp.union(replacements.keys)

english =
"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."

puts english.gsub(pattern, replacements).gsub(/σ(\b)/, "ς")
</syntaxhighlight>
{{out}}
<pre>I ωας λwκινγ ατ σομε rοδοδενδρονς ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ χακι σηορτς, ωηεν θε τελεfονε ρανγ.

Aς I ανσωερεδ ιτ, I χhρφυλλυ γλιμψεδ θατ θε Iυλυ συν
καυσεδ α φραγμεντ οφ βλακ πινε ωαξ το wζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.
</pre>


=={{header|Wren}}==
=={{header|Wren}}==
{{libheader|Wren-str}}
{{libheader|Wren-str}}
<lang ecmascript>import "./str" for Char, Greek
<syntaxhighlight lang="wren">import "./str" for Char, Greek


var English2Greek = Fn.new { |text|
var English2Greek = Fn.new { |text|
Line 432: Line 890:
}
}
System.print("The last example using the names of the Greek letters instead:")
System.print("The last example using the names of the Greek letters instead:")
var letters = Greek.names
var alphabet = "αβγδεζηθικλμνξοπρςστυφχψω".codePoints.toList
var e2gl = {}
for (i in 0...alphabet.count) e2gl[String.fromCodePoint(alphabet[i])] = letters[i]
var greek = English2Greek.call(texts[2])
var greek = English2Greek.call(texts[2])
var s = ""
var s = ""
Line 443: Line 897:
c = g
c = g
} else {
} else {
c = "<" + e2gl[g] + ">"
c = "<" + Greek.name(g) + ">"
}
}
s = s + c
s = s + c
}
}
System.print(s)</lang>
System.print(s)</syntaxhighlight>


{{out}}
{{out}}

Latest revision as of 09:53, 1 March 2024

Task
Transliterate English text using the Greek alphabet
You are encouraged to solve this task according to the task description, using any language you may know.
Rules

A rather silly little task intended as a bit of fun as well as a simple exercise in text substitution. So, if you're a Greek speaker or an expert in ancient Greek, please don't take it too seriously!

As there isn't a one-to-one correspondence between the English and Greek alphabets, we need some rules:

Greek letter Corresponding English letter(s)
alpha a
beta b or v
gamma g
delta d
epsilon e (but not ee)
zeta z
eta h or ee (but not ch, kh, ph, rh or th)
theta th
iota i or j
kappa c, k, q or ck (but not ch and kh)
lambda l
mu m
nu n
xi x
omicron o (but not oo)
pi p (but not ph or ps)
rho r or rh
sigma s (but not ps)
tau t (but not th)
upsilon u or y
phi f or ph
chi ch or kh
psi ps
omega w or oo

In the case of lower-case sigma, use ς when s is the final letter of an English word or σ otherwise.

Ignore Greek diacritics (accents and breathings) but use the same capitalization, spacing and punctuation as in the English text.

Example

English: The quick brown fox jumped over the lazy dog.

Greek: Θε κυικ βροων φοξ ιυμπεδ οβερ θε λαζυ δογ.

Task

Transliterate the following English text into Greek using the above rules:

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.

If your language does not support the printing of non-ascii characters, then you can instead transliterate the following lower-case pangram:

sphinx of black quartz, judge my vow.

Just represent the Greek letters by their names in angle brackets. For example:

the dog => <theta><epsilon> <delta><omicron><gamma>
Reference


Other tasks related to string operations:
Metrics
Counting
Remove/replace
Anagrams/Derangements/shuffling
Find/Search/Determine
Formatting
Song lyrics/poems/Mad Libs/phrases
Tokenize
Sequences



J

Translation of: Julia

Implementation:

endings=: {{
  W=. (#~ tolower=toupper) (32}.127{.a.)-.":1234567890x
  ,(x,"1 0 W);&(7&u:)"1 y,"1 0 W
}}

trans=: rplc&(7 u:L:0 ".{{)n
    'ch';'χ'; 'th';'θ'; 'ps';'ψ'; 'ph';'f'; ('s' endings 'ς'), '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';'Ξ'
}} -.LF)^:_

Examples:

txt1=:'The quick brown fox jumped over the lazy dog.'
txt2=:{{)n
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.
}}

txt3=: 'sphinx of black quartz, judge my vow.'

   trans txt1
Θε κυικ βροων φοξ ιυμπεδ οβερ θε λαζυ δογ.
   trans txt2
I ωας λωκινγ ατ σομε ροδοδενδρονς ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ χακι σηορτς, ωηεν θε τελεφονε ρανγ.
 
 I ανσωερεδ ιτ, I χηρφυλλυ γλιμψεδ θατ θε Iυλυ συν
καυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.

   trans txt3
σφινξ οφ βλακ κυαρτζ, ιυδγε μυ βοω.

Java

import java.util.List;

public final class TransliterateEnglishTextUsingTheGreekAlphabet {

	public static void main(String[] args) {
		List<String> tests = List.of(
			"The quick brown fox jumps over the lazy dog.", // Note: "jumps" not "jumped"
		    """
		    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.");	
		
		String[][] pairs = new String[][] {
			{ "CH", "Χ" }, { "Ch", "Χ" }, { "ch", "χ" }, { "CK", "Κ" }, { "Ck", "Κ" }, { "ck", "κ" },
			{ "EE", "Η" }, { "Ee", "Η" }, { "ee", "η" }, { "KH", "Χ" }, { "Kh", "Χ" }, { "kh", "χ" },
			{ "OO", "Ω" }, { "Oo", "Ω" }, { "oo", "ω" }, { "PH", "Φ" }, { "Ph", "Φ" }, { "ph", "ϕ" },
			{ "PS", "Ψ" }, { "Ps", "Ψ" }, { "ps", "ψ" }, { "RH", "Ρ" }, { "Rh", "Ρ" }, { "rh", "ρ" },
			{ "TH", "Θ" }, { "Th", "Θ" }, { "th", "θ" }, { "A", "Α" }, { "a", "α" }, { "B", "Β" },
			{ "b", "β" }, { "C", "Κ" }, { "c", "κ" }, { "D", "Δ" }, { "d", "δ" }, { "E", "Ε" }, { "e", "ε" },
			{ "F", "Φ" }, { "f", "ϕ" }, { "G", "Γ" }, { "g", "γ" }, { "H", "Ε" }, { "h", "ε" }, { "I", "Ι" },
			{ "i", "ι" }, { "J", "Ι" }, { "j", "ι" }, { "K", "Κ" }, { "k", "κ" }, { "L", "Λ" }, { "l", "λ" },
			{ "M", "Μ" }, { "m", "μ" }, { "N", "Ν" }, { "n", "ν" }, { "O", "Ο" }, { "o", "ο" }, { "P", "Π" },
			{ "p", "π" }, { "Q", "Κ" }, { "q", "κ" }, { "R", "Ρ" }, { "r", "ρ" }, { "S", "Σ" }, { "s", "σ" },
			{ "T", "Τ" }, { "t", "τ" }, { "U", "Υ" }, { "u", "υ" }, { "V", "Β" }, { "v", "β" }, { "W", "Ω" },
			{ "w", "ω" }, { "X", "Ξ" }, { "x", "ξ" }, { "Y", "Υ" }, { "y", "υ" }, { "Z", "Ζ" }, { "z", "ζ" } };

		for ( String test : tests ) {
			String greek = test;
			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));
		}			
	}

}
The quick brown fox jumps 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.
    =>
σϕινξ οϕ βλακ κυαρτζ, ιυδγε μυ βοω.
=================================================================

jq

Adapted from #Julia

A point of interest in adapting the approach taken in the Julia entry is that, since jq strings for interpolating variables are not themselves JSON strings, the special case of "ς" must be handled differently.

def texts: [

  "The quick brown fox jumped over the lazy dog.",

  "I was looking at some rhododendrons in my back garden,\n" +
  "dressed in my khaki shorts, when the telephone rang.\n" +
  "\n" +
  "As I answered it, I cheerfully glimpsed that the July sun\n" +
  "caused a fragment of black pine wax to ooze on the velvet quilt\n" +
  "laying in my patio.",

  "sphinx of black quartz, judge my vow."
];

# "ς" is handled separately
def replacements:
 {
    "ch" : "χ", "th" : "θ", "ps" : "ψ", "ph" : "f", "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" : "Ξ" };

def translate($replacements):
  gsub("s(?<W>\\W)"; "ς\(.W)")
  | reduce ($replacements|keys_unsorted[]) as $key (.;
      gsub($key; $replacements[$key])) ;

replacements as $replacements
| texts[]
| ., "=>", translate($replacements), ""

Invocation

jq -nr -f transliterate-english-using-Greek.jq
Output:
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.
=>
I ωασ λωκινγ ατ σομε ροδοδενδρονσ ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ χακι σηορτσ, ωηεν θε τελεφονε ρανγ.

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.
=>
Aσ I ανσωερεδ ιτ, I χηρφυλλυ γλιμψεδ θατ θε Iυλυ συν
καυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.

sphinx of black quartz, judge my vow.
=>
σφινξ οφ βλακ κυαρτζ, ιυδγε μυ βοω.

Julia

const 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."""]

const replacements = [
    "ch" => "χ", "th" => "θ", "ps" => "ψ", "ph" => "f", r"s(\W)" => s\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" => "Ξ"]

for txt in texts
    println("$txt\n=>")
    for pair in replacements
        txt = replace(txt, pair)
    end
    println("$txt\n", "="^65)
end
Output:
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.
=>
σφινξ οφ βλακ κυαρτζ, ιυδγε μυ βοω.
=================================================================

M2000 Interpreter

process1=lambda -> {
	a=list:="ee":="η", "ch":="χ", "kh":="χ", "ph":="φ", "ps":="ψ", "th":="θ", "ck":="κ", "oo":="ω", "rh":="ρ"
	b=list:="a":="α","b":="β","v":="β","g":="γ","d":="δ","e":="ε","z":="ζ","h":="η","i":="ι","j":="ι","c":="κ"
	append b, "k":="κ","q":="κ","l":="λ","m":="μ","n":="ν","x":="ξ","o":="ο","p":="π","r":="ρ"
	append b, "s":="σ","t":="τ","u":="υ","y":="υ","f":="φ","w":="ω"
	=lambda a, b (s as string, no as integer) -> {
		long i=1, j=len(s)
		string r, rc, crlf={
		}
		while i<=j
			if exist(a, lcase$(mid$(s,i,2))) then
				rc=eval$(a)
				if mid$(s,i,1)<>left$(eval$(a!),1) then
					r+=ucase$(left$(rc,1))
				else
					r+=rc
				end if
				i+=2
			else.if exist(b,lcase$(mid$(s,i,1))) then
				rc=eval$(b)  // eval$(b!) is the key
				if mid$(s,i,1)<>eval$(b!) then
					r+=ucase$(rc)
				else.if rc="σ" then
					if exist(b,lcase$(mid$(s,i+1,1))) then
						r+=rc
					else
						r+="ς"
					end if
				else
					r+=rc
				end if
				i++
			else
				r+=mid$(s,i,1)
				i++
			end if
		end while
		=">>>> Text "+no+crlf+s+crlf+"     =>"+crlf+r+crlf+crlf
	}
}

trans=process1()

report trans("The quick brown fox jumped over the lazy dog.", 1)

eng$={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.}
Report trans(eng$, 2)

Report trans("sphinx of black quartz, judge my vow.", 3)
Output:
>>>> Text 1
The quick brown fox jumped over the lazy dog.
     =>
Θε κυικ βροων φοξ ιυμπεδ οβερ θε λαζυ δογ.

>>>> Text 2
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.
     =>
Ι ωας λωκινγ ατ σομε ροδοδενδρονς ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ χακι σηορτς, ωηεν θε τελεφονε ρανγ.

Ας Ι ανσωερεδ ιτ, Ι χηρφυλλυ γλιμψεδ θατ θε Ιυλυ συν
καυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.

>>>> Text 3
sphinx of black quartz, judge my vow.
     =>
σφινξ οφ βλακ κυαρτζ, ιυδγε μυ βοω.

Nim

import std/[strutils, unicode]

const Text = """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."""

# Replacement table.
# It includes greek characters which look like ASCII ones but are actually different
# and coded using specific Unicode code points (as Α, Β, Ε, etc.).
const Replacements = {"CH": "Χ", "Ch": "Χ", "ch": "χ", "CK": "Κ", "Ck": "Κ", "ck": "κ",
                      "EE": "Η", "Ee": "Η", "ee": "η", "KH": "Χ", "Kh": "Χ", "kh": "χ",
                      "OO": "Ω", "Oo": "Ω", "oo": "ω", "PH": "Φ", "Ph": "Φ", "ph": "ϕ",
                      "PS": "Ψ", "Ps": "Ψ", "ps": "ψ", "RH": "Ρ", "Rh": "Ρ", "rh": "ρ",
                      "TH": "Θ", "Th": "Θ", "th": "θ", "A": "Α", "a": "α", "B": "Β",
                      "b": "β", "C": "Κ", "c": "κ", "D": "Δ", "d": "δ", "E": "Ε", "e": "ε",
                      "F": "Φ", "f": "ϕ", "G": "Γ", "g": "γ", "H": "Ε", "h": "ε", "I": "Ι",
                      "i": "ι", "J": "Ι", "j": "ι", "K": "Κ", "k": "κ", "L": "Λ", "l": "λ",
                      "M": "Μ", "m": "μ", "N": "Ν", "n": "ν", "O": "Ο", "o": "ο", "P": "Π",
                      "p": "π", "Q": "Κ", "q": "κ", "R": "Ρ", "r": "ρ", "S": "Σ", "s": "σ",
                      "T": "Τ", "t": "τ", "U": "Υ", "u": "υ", "V": "Β", "v": "β", "W": "Ω",
                      "w": "ω", "X": "Ξ", "x": "ξ", "Y": "Υ", "y": "υ", "Z": "Ζ", "z": "ζ"}

# All replacements are done using a single call to "multiReplace".
var text = Text.multiReplace(Replacements)

# Replacing "σ" with "ς" is a bit more complicated, as we have to deal with Unicode strings.
const Sigma1 = "σ".toRunes[0]
const Sigma2 = "ς".toRunes[0]
var runes = text.toRunes
for i in 0..runes.high:
  let rune = runes[i]
  if rune == Sigma1:
    if i == runes.high or not runes[i + 1].isAlpha:
      runes[i] = Sigma2
echo runes
Output:
Ι ωας λωκινγ ατ σομε ροδοδενδρονς ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ χακι σεορτς, ωεεν θε τελεϕονε ρανγ.

Ας Ι ανσωερεδ ιτ, Ι χηρϕυλλυ γλιμψεδ θατ θε Ιυλυ συν
καυσεδ α ϕραγμεντ οϕ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.

Perl

use v5.36;
use experimental 'for_list';
use utf8;
binmode(STDOUT, ':utf8');

sub to_Greek ($string) {
    my %pre  = qw<Ph F ck k ee h J I rh r oo w ph f ch χ th θ ps ψ Ch Χ Th Θ Ps Ψ kh χ 's ' 'ς '>;
    my %post = split '', 'aαbβdδeεfφgγhηiιjιkκlλmμnνoοpπqκrρsσtτuυvβwωxξyυzζAΑBΒDΔEΕFΦGΓHΗIΙLΛMΜNΝOΟPΠQΚRΡSΣTΤUΥWΩXΞZΖ';
    for my ($k,$v) (%pre, %post) { $string =~ s/$k/$v/g }
    $string
}

say "$_\n" . to_Greek $_ . "\n" for
    '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.';
Output:
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.
Ασ Ι ανσωερεδ ιτ, Ι χηρφυλλυ γλιμψεδ θατ θε Ιυλυ συν cαυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ λαυινγ ιν μυ πατιο.

Phix

Library: Phix/online

Just for a laugh, figure out the rules directly from the task description. You can run this online here (and it'll probably look better in a browser than on a Windows console).

with javascript_semantics
constant task = """
alpha   a
beta    b or v
gamma   g
delta   d
epsilon e (but not ee)
zeta    z
eta     h or ee (but not ch, kh, ph, rh or th)
theta   th
iota    i or j
kappa   c, k, q or ck (but not ch and kh)
lambda  l
mu      m
nu      n
xi      x
omicron o (but not oo)
pi      p (but not ph or ps)
rho     r or rh
sigma   s (but not ps)
tau     t (but not th)
upsilon u or y
phi     f or ph
chi     ch or kh
psi     ps
omega   w or oo
"""
function rules()
    sequence replacements = split(task,"\n"),
             suborder = {{" ",49},{",",50},{".",51},{"\n",52}},
	     {rs,ir} = columnize(suborder),
	     names = reinstate(repeat(0,52),ir,rs),
             done = {}
    for i,s in replacements do
        s = substitute_all(s,{" or"," and"},{",",","})
        integer k = match("(but not ",s)
        sequence nots = {}
        if k then
            assert(s[$]=')' and s[k-1]=' ')
            nots = split(s[k+9..$-1],", ")
            s = s[1..k-2]
        end if
        s = split(substitute(s,",","")," ")
	names[i] = "<" & proper(s[1]) & ">"
	names[i+24] = "<" & s[1] & ">"
	s = s[2..$]
        k = max(apply(s&nots,length))
        replacements[i] = {k,i,reverse(s),nots}
    end for
    replacements = sort(replacements)
    while length(replacements) do
        for i=length(replacements) to 1 by -1 do
            bool missing = false
            for s in replacements[i][4] do
                missing += not find(s,done)
            end for
            if not missing then
		integer g = replacements[i][2]
                for s in replacements[i][3] do
                    done = append(done,s)
                    suborder &= {{s,g+24}}
                    s[1] = upper(s[1])
                    suborder &= {{s,g}}
                end for
                replacements[i..i] = {}
            end if
        end for
    end while
    return {columnize(suborder),names}
end function

sequence {{sub,rep},names} = rules(),
gulp = utf8_to_utf32("ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ"&
		     "αβγδεζηθικλμνξοπρστυφχψω ,.\n"),
text = """
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."""
string g = utf32_to_utf8(extract(gulp,substitute_all(text,sub,rep)))
g = substitute_all(g,{"σ ","σ,"},{"ς ","ς,"})
printf(1,"%s\n=>\n%s\n\n",{text,g})
string thedog = "the dog"
g = join(extract(names,substitute_all(thedog,sub,rep)),"")      
printf(1,"%s\n=>\n%s\n\n",{thedog,g})
Output:
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.
=>
Θε κυικ βροων φοξ ιυμπεδ οβερ θε λαζυ δογ.

Ι ωας λωκινγ ατ σομε ροδοδενδρονς ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ χακι σηορτς, ωηεν θε τελεφονε ρανγ.
 
Ας Ι ανσωερεδ ιτ, Ι χηρφυλλυ γλιμψεδ θατ θε Ιυλυ συν
καυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.
σφινξ οφ βλακ κυαρτζ, ιυδγε μυ βοω.

the dog
=>
<theta><epsilon> <delta><omicron><gamma>

Python

Translation of: Julia

Implementation:

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)
Output:
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.
=>
σφινξ οφ βλακ κυαρτζ, ιυδγε μυ βοω.
=================================================================

Raku

sub to-Greek (Str $string is copy) {
    my %pre =  :Ph<F>, :ck<k>, :ee<h>, :J<I>, :rh<r>,:oo<w>, :ph<f>, :ch<χ>,
               :th<θ>, :ps<ψ>, :Ch<Χ>, :Th<Θ>, :Ps<Ψ>, :kh<χ>, 's ' => 'ς ';
    my %post = :a<α>, :b<β>, :d<δ>, :e<ε>, :f<φ>, :g<γ>, :h<η>, :i<ι>, :j<ι>,
               :k<κ>, :l<λ>, :m<μ>, :n<ν>, :o<ο>, :p<π>, :q<κ>, :r<ρ>, :s<σ>,
               :t<τ>, :u<υ>, :v<β>, :w<ω>, :x<ξ>, :y<υ>, :z<ζ>, :A<Α>, :B<Β>,
               :D<Δ>, :E<Ε>, :F<Φ>, :G<Γ>, :H<Η>, :I<Ι>, :L<Λ>, :M<Μ>, :N<Ν>,
               :O<Ο>, :P<Π>, :Q<Κ>, :R<Ρ>, :S<Σ>, :T<Τ>, :U<Υ>, :W<Ω>, :X<Ξ>,
               :Z<Ζ>;

    $string.=subst(:g, .key, .value ) for flat %pre, %post;
    $string
}

my $text = chomp q:to/ENGLISH/;
    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.
    ENGLISH

say "English:\n\n" ~ $text ~ "\n" ~ '=' x 80;

say "\"Greek\":\n\n" ~ $text.&to-Greek ~ "\n" ~ '=' x 80;

say "Or, to named characters:\n\n$_\n" ~
  .&to-Greek.comb.map({ .match(/\W/) ?? $_ !!
      '<' ~ .uniname.subst( /.+<?after LETTER\s>/).lc ~ '>'
  }).join
  given 'sphinx of black quartz, judge my vow.';
Output:
English:

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.
================================================================================
"Greek":

Θε κυικ βροων φοξ ιυμπεδ οβερ θε λαζυ δογ.

Ι ωας λωκινγ ατ σομε ροδοδενδρονς ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ χακι σηορτσ, ωηεν θε τελεφονε ρανγ.

Ας Ι ανσωερεδ ιτ, Ι χηρφυλλυ γλιμψεδ θατ θε Ιυλυ συν
cαυσεδ α φραγμεντ οφ βλακ πινε ωαξ το ωζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.

σφινξ οφ βλακ κυαρτζ, ιυδγε μυ βοω.
================================================================================
Or, to named characters:

sphinx of black quartz, judge my vow.
<sigma><phi><iota><nu><xi> <omicron><phi> <beta><lamda><alpha><kappa> <kappa><upsilon><alpha><rho><tau><zeta>, <iota><upsilon><delta><gamma><epsilon> <mu><upsilon> <beta><omicron><omega>.

Ruby

replacements = 
    {"ch" => "χ", "th" => "θ", "ps" => "ψ", "ph" => "f", "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" => "Ξ"}
pattern = Regexp.union(replacements.keys)

english =
"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."

puts english.gsub(pattern, replacements).gsub(/σ(\b)/, "ς")
Output:
I ωας λwκινγ ατ σομε rοδοδενδρονς ιν μυ βακ γαρδεν,
δρεσσεδ ιν μυ χακι σηορτς, ωηεν θε τελεfονε ρανγ.

Aς I ανσωερεδ ιτ, I χhρφυλλυ γλιμψεδ θατ θε Iυλυ συν
καυσεδ α φραγμεντ οφ βλακ πινε ωαξ το wζε ον θε βελβετ κυιλτ
λαυινγ ιν μυ πατιο.

Wren

Library: Wren-str
import "./str" for Char, Greek

var English2Greek = Fn.new { |text|
    // make appropriate substitutions using rarely used control characters
    // for Greek letters which have no single English letter equivalents
    var subs = [
        ["v", "b"],
        ["j", "i"],
        ["y", "u"],
        ["ch", "\x01"], // chi (l/c)
        ["kh", "\x01"], // chi (l/c)
        ["ph", "f"],
        ["rh", "r"],
        ["th", "\x02"], // theta (l/c)
        ["Ch", "\x04"], // chi (u/c)
        ["Kh", "\x04"], // chi (u/c)
        ["Ph", "F"],
        ["Rh", "R"],
        ["Th", "\x05"], // theta (u/c)
        ["ee", "h"],
        ["ck", "q"],
        ["c", "q"],
        ["k", "q"],
        ["oo", "w"],
        ["ps", "\x03"], // psi(l/c)
        ["Ps", "\x06"], // psi(u/c)
        ["V", "B"],
        ["J", "I"],
        ["Y", "U"],
        ["CH", "\x04"], // chi (u/c)
        ["KH", "\x04"], // chi (u/c)
        ["PH", "F"],
        ["RH", "R"],
        ["TH", "\x05"], // theta (u/c)
        ["EE", "H"],
        ["CK", "Q"],
        ["C", "Q"],
        ["K", "Q"],
        ["OO", "W"],
        ["PS", "\x06"], // psi(u/c)
    ]
    for (sub in subs) text = text.replace(sub[0], sub[1])

    // now look for final English lower case 's' and use 'DEL' to substitute for that
    var letters = text.toList
    for (i in 1...letters.count) {
        var c = letters[i]
        if ((Char.isWhitespace(c) || Char.isPunctuation(c)) && letters[i-1] == "s") {
            letters[i-1] = "\x7f"
        }
    }

    // finally substitute the remaining English 'letters' with Greek ones
    // note that some of them look the same but are different codepoints
    var e2g = {
        "a": "α", "b": "β", "d": "δ", "e": "ε", "f": "φ", "g": "γ", "h": "η", 
        "i": "ι", "l": "λ", "m": "μ", "n": "ν", "o": "ο", "p": "π", "q": "κ", 
        "r": "ρ", "s": "σ", "t": "τ", "u": "υ", "w": "ω", "x": "ξ", "z": "ζ", 
        "A": "Α", "B": "Β", "D": "Δ", "E": "Ε", "F": "Φ", "G": "Γ", "H": "Η", 
        "I": "Ι", "L": "Λ", "M": "Μ", "N": "Ν", "O": "Ο", "P": "Π", "Q": "Κ",
        "R": "Ρ", "S": "Σ", "T": "Τ", "U": "Υ", "W": "Ω", "X": "Ξ", "Z": "Ζ",
        "\x01": "χ", "\x02": "θ", "\x03": "ψ", "\x7f": "ς",
        "\x04": "Χ", "\x05": "Θ", "\x06": "Ψ"
    }

    var greek = List.filled(letters.count, null)
    for (i in 0...greek.count) {
        var c = letters[i]
        if (Char.isWhitespace(c) || Char.isPunctuation(c)) {
            greek[i] = c
        } else {
            greek[i] = e2g[letters[i]]
        }
    }
    return greek.join("")
}

var 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."
]
for (text in texts) {
    System.print(text)
    System.print()
    System.print(English2Greek.call(text))
    System.print("=" * 65)
}
System.print("The last example using the names of the Greek letters instead:")
var greek = English2Greek.call(texts[2])
var s = ""
for (g in greek) {
    var c
    if (Char.isWhitespace(g) || Char.isPunctuation(g)) {
        c = g
    } else {
        c = "<" + Greek.name(g) + ">"
    }
    s = s + c
}
System.print(s)
Output:
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.

σφινξ οφ βλακ κυαρτζ, ιυδγε μυ βοω.
=================================================================
The last example using the names of the Greek letters instead:
<sigma><phi><iota><nu><xi> <omicron><phi> <beta><lambda><alpha><kappa> <kappa><upsilon><alpha><rho><tau><zeta>, <iota><upsilon><delta><gamma><epsilon> <mu><upsilon> <beta><omicron><omega>.