Conjugate a Latin verb: Difference between revisions

AWK (gawk) solution added
m (→‎{{header|Wren}}: Changed to Wren S/H)
imported>Meerkut
(AWK (gawk) solution added)
Line 223:
auditis
audiunt</pre>
=={{header|AWK}}==
{{works with|gawk|5.1.0 }}
<syntaxhighlight lang="AWK">
#!/usr/bin/env -S gawk -f
 
BEGIN {
ENDINGS["āre"]=1
ENDINGS["are"]=1
ENDINGS["ēre"]=2
ENDINGS["ere"]=3
ENDINGS["īre"]=4
ENDINGS["ire"]=4
first_person_singular=1
RULE[first_person_singular][1]="ō"
RULE[first_person_singular][2]="eō"
RULE[first_person_singular][3]="ō"
RULE[first_person_singular][4]="iō"
second_person_singular=2
RULE[second_person_singular][1]="ās"
RULE[second_person_singular][2]="ēs"
RULE[second_person_singular][3]="is"
RULE[second_person_singular][4]="īs"
third_person_singular=3
RULE[third_person_singular][1]="at"
RULE[third_person_singular][2]="et"
RULE[third_person_singular][3]="it"
RULE[third_person_singular][4]="it"
first_person_plural=4
RULE[first_person_plural][1]="āmus"
RULE[first_person_plural][2]="ēmus"
RULE[first_person_plural][3]="imus"
RULE[first_person_plural][4]="īmus"
second_person_plural=5
RULE[second_person_plural][1]="ātis"
RULE[second_person_plural][2]="ētis"
RULE[second_person_plural][3]="itis"
RULE[second_person_plural][4]="ītis"
third_person_plural=6
RULE[third_person_plural][1]="ant"
RULE[third_person_plural][2]="ent"
RULE[third_person_plural][3]="unt"
RULE[third_person_plural][4]="iunt"
print \
"infinitive│ ╭─person─╮ ╭─person─╮ \n"\
" │╭─────────── singular ──────────╮╭────────── plural ────────────╮\n"\
" ││ 1st 2nd 3rd ││ 1st 2nd 3rd │"
 
}
 
NF==0 || $1=="#" || index($1,"#")==1 {next}
 
1 {
printf "%-12s", $1
stem=substr($1,1,length($1)-3)
if (stem=="") { printf "%s\n", "* Can not conjugate"; next }
endn=substr($1,length($1)-2)
if (endn in ENDINGS) {
kind=ENDINGS[endn]
printf "%-11s", stem RULE[first_person_singular][kind]
printf "%-11s", stem RULE[second_person_singular][kind]
printf "%-11s", stem RULE[third_person_singular][kind]
printf "%-11s", stem RULE[first_person_plural][kind]
printf "%-11s", stem RULE[second_person_plural][kind]
printf "%-11s", stem RULE[third_person_plural][kind]
}
else {
printf "%s", "* Can not conjugate"
}
printf "\n"
next
}
</syntaxhighlight>
Run, assuming the code is in the <tt>clv.awk</tt>
<syntaxhighlight lang="shell">
#!/bin/sh
 
printf '
# "āre" Verbs (1st Conjugation):
amare (to love)
laudare (to praise)
vocare (to call)
 
# "ēre" Verbs (2nd Conjugation):
vidēre (to see)
docēre (to teach)
legere (to read)
 
# "ere" Verbs (3rd Conjugation):
ducere (to lead)
capere (to take)
facere (to do/make)
 
# "īre" Verbs (4th Conjugation):
audire (to hear)
venire (to come)
ire (to go)
 
# incorrect verbs
qwerty
 
' '' | LANG=en_US.UTF-8 gawk -f ./clv.awk
</syntaxhighlight>
{{out}}
<pre>
infinitive│ ╭─person─╮ ╭─person─╮
│╭─────────── singular ──────────╮╭────────── plural ────────────╮
││ 1st 2nd 3rd ││ 1st 2nd 3rd │
amare amō amās amat amāmus amātis amant
laudare laudō laudās laudat laudāmus laudātis laudant
vocare vocō vocās vocat vocāmus vocātis vocant
vidēre videō vidēs videt vidēmus vidētis vident
docēre doceō docēs docet docēmus docētis docent
legere legō legis legit legimus legitis legunt
ducere ducō ducis ducit ducimus ducitis ducunt
capere capō capis capit capimus capitis capunt
facere facō facis facit facimus facitis facunt
audire audiō audīs audit audīmus audītis audiunt
venire veniō venīs venit venīmus venītis veniunt
ire * Can not conjugate
qwerty * Can not conjugate
</pre>
=={{header|BQN}}==
{{trans|Nim}}
Anonymous user