Conjugate a Latin verb: Difference between revisions

From Rosetta Code
Content added Content deleted
m (note required -> optional)
Line 17: Line 17:
* Have at least one example from each of the 4 conjugations.
* Have at least one example from each of the 4 conjugations.
* Irregular verbs are not required.
* Irregular verbs are not required.
* Translation into English is not required.
* Translation into English is optional.





Revision as of 01:39, 18 September 2021

Conjugate a Latin verb is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.

You may see other such operations in the Basic Data Operations category, or:

Integer Operations
Arithmetic | Comparison

Boolean Operations
Bitwise | Logical

String Operations
Concatenation | Interpolation | Comparison | Matching

Memory Operations
Pointers & references | Addresses

Task
Create a program that can take a Latin verb and conjugate it, displaying in the following order:
1st person singular
2nd person singular
3rd person singular
1st person plural
2nd person plural
3rd person plural
  • Each should be on its own line.
  • Have at least one example from each of the 4 conjugations.
  • Irregular verbs are not required.
  • Translation into English is optional.


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


See also



ALGOL 68

<lang algol68>BEGIN # print some Latin verb conjugations #

   # prints the cojugations of lv or an error message if we don't know how to conjugate lv #
   PROC print conjugations = ( STRING lv )VOID:
        IF   INT length = ( UPB lv + 1 ) - LWB lv;
             length < 4
        THEN
            print( ( """", lv, """ is too short to conjugate", newline ) )
        ELIF lv[ UPB lv - 2 : ] /= "are"
        THEN
            print( ( "Don't know how to conjugate """, lv, """", newline ) )
        ELSE
            []STRING suffix = ( "o", "as", "at", "amus", "atis", "ant" );
            STRING prefix = lv[ : UPB lv - 2 ];
            print( ( "Conjugations of """, lv, """:", newline ) );
            FOR i FROM LWB suffix TO UPB suffix DO
                print( ( "    ", prefix, suffix[ i ], newline ) )
            OD
        FI # print confugations # ;
   print conjugations( "amare" );
   print conjugations( "veni" );
   print conjugations( "dare" );
   print conjugations( "are" )

END</lang>

Output:
Conjugations of "amare":
    amao
    amaas
    amaat
    amaamus
    amaatis
    amaant
Don't know how to conjugate "veni"
Conjugations of "dare":
    dao
    daas
    daat
    daamus
    daatis
    daant
"are" is too short to conjugate

F#

<lang fsharp> // Conjugate a Latin Verb. Nigel Galloway: September 17th., 2021 let myLatin (n:string)=printfn "Rogatus sum iungere verbum %s" n

                      match n.Length>3,n.[-3..]="are" with 
                       (false,_)|(_,false)->printfn "    facis quod"
                      |_->["o";"as";"at";"amus";"atis";"ant"]|>List.iter(fun g->printfn "    %s%s" n.[0.. -4] g)

myLatin "amare" myLatin "creo" </lang>

Output:
Rogatus sum iungere verbum amare
    amo
    amas
    amat
    amamus
    amatis
    amant
Rogatus sum iungere verbum creo
    facis quod

Factor

Works with: Factor version 0.99 2021-06-02

<lang factor>USING: formatting io kernel math qw sequences ;

CONSTANT: pronouns {

   "I"
   "you"
   "he, she, it"
   "we"
   "you all"
   "they"

}

CONSTANT: endings qw{ ō ās at āmus ātis ant }

first-conjugation? ( str -- ? )
   qw{ are āre } [ tail? ] with any? ;
check-first-conjugation ( str -- )
   first-conjugation?
   [ "Input must end with 'are' or 'āre'." throw ] unless ;
check-length ( str -- )
   length 3 >
   [ "Input too short to conjugate." throw ] unless ;
check-input ( str -- )
   [ check-first-conjugation ] [ check-length ] bi ;
conjugate ( str -- seq )
   dup check-input 3 head* endings [ append ] with map ;
he/she/it ( str -- newstr )
   "s" append dup dup "he %s, she %s, it %s" sprintf ;
english ( str -- seq )
   pronouns [ 2 = [ nip he/she/it ] [ " " glue ] if ] with
   map-index ;
conjugate. ( la en -- )
   la en "Present active indicative conjugations of %s (%s):\n"
   printf la conjugate en english [ "  %-10s%s\n" printf ] 2each ;

"amāre" "love" conjugate. nl "dāre" "give" conjugate.</lang>

Output:
Present active indicative conjugations of amāre (love):
  amō       I love
  amās      you love
  amat      he loves, she loves, it loves
  amāmus    we love
  amātis    you all love
  amant     they love

Present active indicative conjugations of dāre (give):
  dō        I give
  dās       you give
  dat       he gives, she gives, it gives
  dāmus     we give
  dātis     you all give
  dant      they give

Julia

<lang julia>const conjugators = ["ō", "ās", "at", "āmus", "ātis", "ant"] conjugate(w, gregex = r"[aā]re$") = (r = replace(w, gregex => ""); [r * s for s in conjugators])

function testregularconjugation(verbvector)

   for verb in verbvector
       println("\nPresent active indicative conjugation of $verb:")
       for result in conjugate(verb)
           println(result)
       end
   end

end

testregularconjugation(["amāre", "dāre"])

</lang>

Output:
Present active indicative conjugation of amāre:
amō
amās
amat
amāmus
amātis
amant

Present active indicative conjugation of dāre:
dō
dās
dat
dāmus
dātis
dant

Nim

Translation of: Wren

<lang Nim>import strutils

proc conjugate(infinitive: string) =

 if not infinitive.endsWith("are"):
   raise newException(ValueError, "not a first conjugation verb.")
 let stem = infinitive[0..^4]
 if stem.len == 0:
   raise newException(ValueError, "stem cannot be empty.")
 echo "Present indicative tense of '$#':" % infinitive
 for ending in ["o", "as", "at", "amus", "atis", "ant"]:
   echo "  ", stem, ending
 echo()

for infinitive in ["amare", "dare"]:

 conjugate(infinitive)</lang>
Output:
Present indicative tense of 'amare':
  amo
  amas
  amat
  amamus
  amatis
  amant

Present indicative tense of 'dare':
  do
  das
  dat
  damus
  datis
  dant

Perl

Translation of: Raku

<lang perl>use strict; use warnings; use feature 'say'; use utf8; binmode STDOUT, ':utf8';

sub conjugate {

   my($verb) = shift;
   join "\n", map { $verb . $_ } qw<ō ās at āmus ātis ant>;

}

for my $infinitive ('amāre', 'dare') {

   say "\nPresent active indicative conjugation of infinitive $infinitive.";
   my($verb) = $infinitive =~ /^ (\w+) [aā] re $/x;
   say $verb ? conjugate $verb : "Sorry, don't know how to conjugate $infinitive"

</lang>

Output:
Present active indicative conjugation of infinitive amāre.
amō
amās
amat
amāmus
amātis
amant

Present active indicative conjugation of infinitive dare.
dō
dās
dat
dāmus
dātis
dant

Phix

TL; DR: Did just one term of Latin, right before posting this realised 'dāre' should probably be 'dare', left as an exercise...

with javascript_semantics
constant {ending,endings} = columnize({{"āre",split("ō ās at āmus ātis ant")},
                                       {"ēre",split("eō ēs et ēmus ētis ent")},
                                       {"ere",split("ō is it imus itis unt")},
                                       {"īre",split("iō īs it īmus ītis iunt")}}),
         pronouns = {"I %s", "you %s", "he %ss, she %ss, it %ss", "we %s", "you all %s", "they %s"}

procedure conjugate(sequence ie)
    string {infinitive,english} = ie
    sequence utf32 = utf8_to_utf32(infinitive)
    assert(length(utf32)>3,"Infinitive is too short for a regular verb.")
    string stem = utf32_to_utf8(utf32[1..-4]),
           last3 = utf32_to_utf8(utf32[-3..-1])
    integer edx = find(last3,ending)
    assert(edx!=0,"Infinitive ending -%s not recognized.",{last3}) 
    printf(1,"Present active indicative conjugations of '%s' (%s):\n",ie)
    for i=1 to length(endings[edx]) do
        string c = sprintf("%s%s",{stem,endings[edx][i]}),
               e = substitute(pronouns[i],"%s",english)
        printf(1,"  %-7s  %s\n",{c,e})
    end for
    printf(1,"\n")
end procedure
 
printf(0,"",{"unicode_align",true})
papply({{"amāre","love"},{"dāre","give"},{"vidēre","see"},{"dūcere","lead"},{"audīre","hear"}},conjugate)
Output:
Present active indicative conjugations of 'amāre' (love):
  amō      I love
  amās     you love
  amat     he loves, she loves, it loves
  amāmus   we love
  amātis   you all love
  amant    they love

Present active indicative conjugations of 'dāre' (give):
  dō       I give
  dās      you give
  dat      he gives, she gives, it gives
  dāmus    we give
  dātis    you all give
  dant     they give

Present active indicative conjugations of 'vidēre' (see):
  videō    I see
  vidēs    you see
  videt    he sees, she sees, it sees
  vidēmus  we see
  vidētis  you all see
  vident   they see

Present active indicative conjugations of 'dūcere' (lead):
  dūcō     I lead
  dūcis    you lead
  dūcit    he leads, she leads, it leads
  dūcimus  we lead
  dūcitis  you all lead
  dūcunt   they lead

Present active indicative conjugations of 'audīre' (hear):
  audiō    I hear
  audīs    you hear
  audit    he hears, she hears, it hears
  audīmus  we hear
  audītis  you all hear
  audiunt  they hear

Raku

Translation of Julia.

<lang perl6>for <amāre dare> -> $infinitive {

   say "\nPresent active indicative conjugation of infinitive $infinitive.";
   my $verb = ($infinitive ~~ /^ (\w+) ['a'|'ā'] 're' $/)[0];
   say $verb ?? (conjugate $verb) !! "Sorry, don't know how to conjugate $infinitive"

}

sub conjugate ($verb) { ($verb X~ <ō ās at āmus ātis ant>).join: "\n" }</lang>

Output:
Present active indicative conjugation of infinitive amāre.
amō
amās
amat
amāmus
amātis
amant

Present active indicative conjugation of infinitive dare.
dō
dās
dat
dāmus
dātis
dant

REXX

Checks were also made to ensure the Latin verb has only Latin letters (upper and/or lower case). <lang rexx>/*REXX pgm conjugates (to the terminal) a Latin verb when given a first conjugation verb*/ parse arg verbs if verbs= | verbs="," then verbs= 'amare dare' suffix= 'o as at amus atis ant' /*a list of six Latin verb suffixes. */

  1. = words(verbs) /*obtain the # of Latin verbs specified*/
     do j=1  for #;                  say        /*process each      "     "       "    */
     $= word(verbs, j);  $$= $;      upper $$   /*obtain one of the "     "       "    */
     if \datatype($, 'M')  then call ser "the following isn't a Latin verb: "      $
     L= length($)                               /*obtain the length of a Latin verb.   */
     if L<4  then call ser 'length of Latin verb is too short: '     $
     if right($$, 3)\=='ARE'  then call ser "the following isn't a Latin verb: "   $
     stem= left($, length($) - 3)               /*obtain the stem of the Latin verb.   */
     say center(' present indicative tense of "'$'"', 50, "─")
        do k=1  for words(suffix)               /*display each of the verb suffixes.   */
        say left(,21) stem || word(suffix, k) /*display a Latin verb stem with auffix*/
        end   /*k*/
     say
     end      /*j*/

exit 0 /*stick a fork in it, we're all done. */ /*──────────────────────────────────────────────────────────────────────────────────────*/ ser: say; say '***error*** ' arg(1); say; exit 13</lang>

output   when using the default inputs:
─────── present indicative tense of "amare"───────
                      amo
                      amas
                      amat
                      amamus
                      amatis
                      amant


─────── present indicative tense of "dare"────────
                      do
                      das
                      dat
                      damus
                      datis
                      dant

Wren

<lang ecmascript>var conjugate = Fn.new { |infinitive|

   if (!infinitive.endsWith("are")) Fiber.abort("Not a first conjugation verb.")
   var stem = infinitive[0...-3]
   if (stem.count == 0) Fiber.abort("Stem cannot be empty.")
   System.print("Present indicative tense of '%(infinitive)':")
   for (ending in ["o", "as", "at", "amus", "atis", "ant"]) {
       System.print("  " + stem + ending)
   }
   System.print()

}

for (infinitive in ["amare", "dare"]) conjugate.call(infinitive)</lang>

Output:
Present indicative tense of 'amare':
  amo
  amas
  amat
  amamus
  amatis
  amant

Present indicative tense of 'dare':
  do
  das
  dat
  damus
  datis
  dant


The following extended version can deal with regular verbs of all four conjugations. To distinguish 2nd and 3rd conjugations, an over-bar is placed above the penultimate 'e' in a second conjugation infinitive but accents are otherwise ignored. <lang ecmascript>var endings = [

   [ "o", "as", "at", "amus", "atis",  "ant"],
   ["eo", "es", "et", "emus", "etis",  "ent"],
   [ "o", "is", "it", "imus", "itis",  "unt"],
   ["io", "is", "it", "imus", "itis", "iunt"]

]

var infinEndings = ["are", "ēre", "ere", "ire"]

var conjugate = Fn.new { |infinitive|

   var letters = infinitive.toList
   if (letters.count < 4) Fiber.abort("Infinitive is too short for a regular verb.")
   var infinEnding = letters[-3..-1].join()
   var conj = infinEndings.indexOf(infinEnding)
   if (conj == -1) Fiber.abort("Infinitive ending -%(infinEnding) not recognized.") 
   var stem = letters[0..-4].join()
   System.print("Present indicative tense, active voice, of '%(infinitive)':")
   for (ending in endings[conj]) System.print("  " + stem + ending)
   System.print()

}

for (infinitive in ["amare", "vidēre", "ducere", "audire"]) conjugate.call(infinitive)</lang>

Output:
Present indicative tense, active voice, of 'amare':
  amo
  amas
  amat
  amamus
  amatis
  amant

Present indicative tense, active voice, of 'vidēre':
  video
  vides
  videt
  videmus
  videtis
  vident

Present indicative tense, active voice, of 'ducere':
  duco
  ducis
  ducit
  ducimus
  ducitis
  ducunt

Present indicative tense, active voice, of 'audire':
  audio
  audis
  audit
  audimus
  auditis
  audiunt