Conjugate a Turkish verb

10

1

Input

  • verb, a string that matches the regular expression ([a-pr-vyzıöüçğş]*[aeıioöuü][bcçdfgğhj-nprsştvyz]+|([a-pr-vyzıöüçğş]*[aeıioöuü]){2})(mak|mek)
  • plural, a truthy or falsy value
  • person, an integer having value either 1, 2, or 3
  • tense, an integer having value either 1, 2, or 3

Output

The conjugated form of the Turkish verb verb, in personst/nd/rd person, plural if plural is TRUE and singular if it is not, in

  • If tense is 1, the simple present;
  • If tense is 2, the continuing present;
  • If tense is 3, the future.

Rules

Turkish verbs are conjugated in three elements, which are in order:

  • The stem, formed by removing mak or mek from the end of the infinitive;
  • The sign of the tense, which is:

    • For the simple present:

      • -r if the stem ends in a vowel;
      • -ir according to vowel harmony rules (see below) if the stem contains more than one syllable (i.e. vowel), or is from one of the following irregular verbs: almak, bilmek, bulmak, durmak, gelmek, görmek, kalmak, olmak, ölmek, sanmak, vermek, varmak, vurmak;
      • -er according to vowel harmony rules if the stem contains one syllable and is not listed in the irregular verbs above.
    • For the continuing present, -iyor, where the i changes according to vowel harmony rules. Stems that end in a vowel drop this vowel before adding this suffix, whereupon the suffix harmonizes with the next-to-last vowel in the word (guaranteed to exist by the regular expression).

    • For the future:
      • -ecek according to vowel harmony rules if the stem ends in a consonant;
      • -yecek according to vowel harmony rules if the stem ends in a vowel.
  • The personal suffix to indicate the performer of the action, in all cases according to vowel harmony rules:

        |Singular|Plural|
    |---|--------|------|
    |1st|    -im |   -iz|
    |2nd|   -sin |-siniz|
    |3rd| (none) |  -ler|
    

    The final k of the future tense becomes ğ before -im and -iz, so for example (almak, TRUE, 1, 3) would yield alacağız.

Vowel harmony rules

Turkish vowels are divided into two groups: back (a ı o u) and front (e i ö ü) by where in the mouth they are pronounced. The suffixes of a word change vowels according to the vowels of the root.

All suffixes listed above that have i as a vowel instead use:

  • if the last vowel before the suffix is ı or a (both these vowels are back and unrounded);
  • -i if the last vowel before the suffix is i or e (both these vowels are front and unrounded; note here Turkish's distinction between dotted and dotless I);
  • -u if the last vowel before the suffix is u or o (both these vowels are back and rounded); or
  • if the last vowel before the suffix is ü or ö (both these vowels are front and rounded).

Take careful note of the present continuous suffix -iyor. The i harmonizes, but the o does not change. The personal suffixes will thus harmonize with the o.

All the suffixes listed above that have e as a vowel instead use:

  • -e if the last vowel before the suffix is a front vowel; or
  • -a if the last vowel before the suffix is a back vowel.

Irregular verbs

The verbs gitmek, tatmak, ditmek, gütmek, and etmek change the final t to a d before any endings that begin with a vowel (which includes all the endings in this challenge). Any verb that ends in -etmek likewise changes the t to a d, and appends -er for the simple present (though this is not so for the other verbs).

Test cases

gütmek, FALSE, 1, 2 -> güdüyorum
almak, TRUE, 3, 3 -> alacaklar
boğmak, TRUE, 2, 1 -> boğarsınız
ölmek, FALSE, 3, 1 -> ölür
boyamak, TRUE, 1, 2 -> boyuyoruz
affetmek, FALSE, 2, 1 -> affedersin
söylemek, TRUE, 3, 1 -> söylerler
söylemek, FALSE, 3, 2 -> söylüyor
söylemek, FALSE, 1, 3 -> söyleyeceğim

EMBLEM

Posted 2016-09-08T08:28:11.377

Reputation: 2 179

Could you provide a test case for the -etmek rule? – Arnauld – 2016-09-08T17:10:54.577

@Arnauld Done. In doing so I discovered I made an error in the specification, which I have appended to the "irregular verbs" section. – EMBLEM – 2016-09-08T17:27:23.400

This could do with a lot more test cases, since the spec is quite complex. – Dave – 2016-09-08T20:15:54.980

@Dave I added 3 more, which took me long enough on mobile. I'll add even more later. – EMBLEM – 2016-09-08T20:44:17.103

Answers

3

Javascript (ES6), 466 456 451 446 bytes

(v,p,w,t)=>(R=g=>g.exec(s),T=r=>s=s.slice(0,-1)+r,Z=s=>s.replace(/\d/g,c=>l=['ıuiü'[(n='aıoueiöü'.search(l))>>1],'ae'[n>>2]][c]),(s=v.slice(k=l=0,-3)).replace(/[aıoueiöü]/g,c=>(L=l,l=c,k++)),(R(/^(gi|ta|di|gü)t$/)||(R(/et$/)&&(k=1)))&&T`d`,((E=R(/[aıoueiöü]$/))&&t==2?(l=L,T``):s)+Z([(E?'':k<2&!R(/^((k?a|bi|bu|ge|o|ö)l)|dur|gör|san|v[aeu]r$/))+'r','0yor',(E?'y1c1':'1c1')+'ğkk'[--w]][t-1])+Z('0m|0z|s0n|s0n0z||l1r'.split`|`[w+w+p],t-2||(l='o')))

Ungofled and commented

// Parameters:
//   - 'v' = verb
//   - 'p' = plural flag
//   - 'w' = person
//   - 't' = tense
(v, p, w, t) => (
  // R() - Helper function to execute a regular expression on the stem.
  R = g => g.exec(s),

  // T() - Helper function to replace the last character of the stem with 'r'.
  T = r => s = s.slice(0, -1) + r,

  // Z() - Function that applies vowel harmony to the string 's', assuming
  //       '0' = 'i' and '1' = 'e' and using the last encountered vowel 'l'.
  Z = s => s.replace(
    /\d/g,
    c => l = [
      'ıuiü' [(n = 'aıoueiöü'.search(l)) >> 1],
      'ae' [n >> 2]
    ][c]
  ),

  // Computes:
  //   - 's' = stem
  //   - 'k' = number of vowels in stem
  //   - 'l' = last vowel in stem
  //   - 'L' = penultimate vowel in stem
  (s = v.slice(k = l = 0, -3)).replace(/[aıoueiöü]/g, c => (L = l, l = c, k++)),

  // Applies ending 't' => 'd' for irregular verbs and those ending in -et(mek).
  (R(/^(gi|ta|di|gü)t$/) || (R(/et$/) && (k = 1))) && T `d`,

  // Computes 'E' = truthy value if the stem ends in a vowel.
  // If 'E' is truthy and the tense is the continuing present, drops this vowel.
  ((E = R(/[aıoueiöü]$/)) && t == 2 ? (l = L, T ``) : s) +

  // Appends sign of tense with vowel harmony.
  Z([
    // t = 1: simple present -> either '-er', '-ir' or '-r'
    (E ? '' : k < 2 & !R(/^((k?a|bi|bu|ge|o|ö)l)|dur|gör|san|v[aeu]r$/) + 'r',

    // t = 2: continuing present -> always '-iyor'
    '0yor',

    // t = 3: future -> either '-yecek', '-ecek', '-yeceğ' or '-eceğ'
    (E ? 'y1c1' : '1c1') + 'ğkk' [--w]
  ][t - 1]) +

  // Appends personal suffix with vowel harmony,
  // forcing last vowel to 'o' for continuing present.
  Z(
    '0m|0z|s0n|s0n0z||l1r'.split `|` [w + w + p],
    t - 2 || (l = 'o')
  )
)

Test cases

let f =
(v,p,w,t)=>(R=g=>g.exec(s),T=r=>s=s.slice(0,-1)+r,Z=s=>s.replace(/\d/g,c=>l=['ıuiü'[(n='aıoueiöü'.search(l))>>1],'ae'[n>>2]][c]),(s=v.slice(k=l=0,-3)).replace(/[aıoueiöü]/g,c=>(L=l,l=c,k++)),(R(/^(gi|ta|di|gü)t$/)||(R(/et$/)&&(k=1)))&&T`d`,((E=R(/[aıoueiöü]$/))&&t==2?(l=L,T``):s)+Z([(E?'':k<2&!R(/^((k?a|bi|bu|ge|o|ö)l)|dur|gör|san|v[aeu]r$/))+'r','0yor',(E?'y1c1':'1c1')+'ğkk'[--w]][t-1])+Z('0m|0z|s0n|s0n0z||l1r'.split`|`[w+w+p],t-2||(l='o')))

console.log(f("gütmek", false, 1, 2));    // -> güdüyorum
console.log(f("almak", true, 3, 3));      // -> alacaklar
console.log(f("boğmak", true, 2, 1));     // -> boğarsınız
console.log(f("ölmek", false, 3, 1));     // -> ölür
console.log(f("boyamak", true, 1, 2));    // -> boyuyoruz
console.log(f("affetmek", false, 2, 1));  // -> affedersin
console.log(f("söylemek", true, 3, 1));   // -> söylerler
console.log(f("söylemek", false, 3, 2));  // -> söylüyor
console.log(f("söylemek", false, 1, 3));  // -> söyleyeceğim

Arnauld

Posted 2016-09-08T08:28:11.377

Reputation: 111 334

Does this account for the d-mutation on all verbs ending in -etmek? I don't know JavaScript but from what I can gather it looks like it's just lumped in with the others. – EMBLEM – 2016-09-08T16:31:23.663

@EMBLEM - This should be fixed. – Arnauld – 2016-09-08T23:54:49.577

3

sed, 583 bytes

sed -E 's/^((bul|dur|k?al|ol|san|v[au]r)ma|(bil|gel|gör|öl|ver)me)k( . .) 1/\2\3Ir\4/;s/etmek( . .) 1/edEr\1/;s/etmek /ed /;s/^((ta)tma|([dg]i|gü)tme)k /\2\3d /;s/m[ae]k / /;s/([aıoueiöüEI])/V\1/g;s/(V.)( . .) 1/\1r\2/;s/(V.+V.+)( . .) 1/\1VIr\2/;s/( . .) 1/VEr\1/;s/(V.)?( . .) 2/VIyVor\2/;s/(V.)( . . 3)/\1y\2/;s/( . .) 3/VEcVEk\1/;s/k( . 1)/ğ\1/;s/ 0 1/VIm/;s/ 1 1/VIz/;s/ 0 2/sVIn/;s/ 1 2/sVInVIz/;s/ 0 3//;s/ 1 3/lVEr/;:l
s/([ıa][^V]*V)I/\1ı/;s/([ie][^V]*V)I/\1i/;s/([uo][^V]*V)I/\1u/;s/([üö][^V]*V)I/\1ü/;s/([aıou][^V]*V)E/\1a/;s/(V[^aEI][^V]*V)E/\1e/;t l
s/V//g'

Like my answer to the closely-related Dactylic Hexameter question, this is really just translating the rules as given into regular expressions.

Usage:

Takes input in the form:

word [01] [123] [123]

So the test cases are:

printf 'gütmek 0 1 2
almak 1 3 3
boğmak 1 2 1
ölmek 0 3 1
boyamak 1 1 2
affetmek 0 2 1
söylemek 1 3 1
söylemek 0 3 2
söylemek 0 1 3' | sed -E '<...>';

Breakdown:

sed -E "
# special cases for simple present tense
 s/^((bul|dur|k?al|ol|san|v[au]r)ma|(bil|gel|gör|öl|ver)me)k( . .) 1/\2\3Ir\4/;

# stemming
# always uses -er rule if simple present
 s/etmek( . .) 1/edEr\1/;
 s/etmek /ed /;
 s/^((ta)tma|([dg]i|gü)tme)k /\2\3d /;
 s/m[ae]k / /;

# mark vowels for easier expressions later
 s/([aıoueiöüEI])/V\1/g;

# simple present
 s/(V.)( . .) 1/\1r\2/;
 s/(V.+V.+)( . .) 1/\1VIr\2/;
 s/( . .) 1/VEr\1/;

# continuing present
 s/(V.)?( . .) 2/VIyVor\2/;

# future
 s/(V.)( . . 3)/\1y\2/;
 s/( . .) 3/VEcVEk\1/;

# personal suffix
 s/k( . 1)/ğ\1/;
 s/ 0 1/VIm/;
 s/ 1 1/VIz/;
 s/ 0 2/sVIn/;
 s/ 1 2/sVInVIz/;
 s/ 0 3//;
 s/ 1 3/lVEr/;

# vowel harmony
 :l
 s/([ıa][^V]*V)I/\1ı/;
 s/([ie][^V]*V)I/\1i/;
 s/([uo][^V]*V)I/\1u/;
 s/([üö][^V]*V)I/\1ü/;

 s/([aıou][^V]*V)E/\1a/;
 s/(V[^aEI][^V]*V)E/\1e/;
# keep looping until all vowels are known
 t l

# unmark vowels
 s/V//g
"

Results for test cases:

güdüyorum
alacaklar
boğarsınız
ölür
boyuyoruz
affedersin
söylerler
söylüyor
söyleyeceğim

Dave

Posted 2016-09-08T08:28:11.377

Reputation: 7 519

You are correct about affedersin. I switched pronouns several times while writing that – EMBLEM – 2016-09-08T22:18:47.000

Take note of case 2; it should be alacaklar, not ler. – EMBLEM – 2016-09-08T22:22:49.507

@EMBLEM fixed; cost me 2 more bytes though (but what's 2 bytes in 600?) – Dave – 2016-09-08T22:28:50.900

You can remove sed -E '', since you specified sed as being the language and not bash, so consider the script as sed source code. You could then run it like: printf ...|sed -Ef filename, adding 1 byte more for the E flag, saving 8 bytes in the end. Btw, never knew until today that -E is equivalent to -r! – seshoumara – 2016-09-09T05:12:57.497