verbs.ml 231 KB
Newer Older
huet's avatar
huet committed
1 2 3 4 5 6
(**************************************************************************)
(*                                                                        *)
(*                     The Sanskrit Heritage Platform                     *)
(*                                                                        *)
(*                       Gérard Huet & Pawan Goyal                        *)
(*                                                                        *)
7
(* ©2019 Institut National de Recherche en Informatique et en Automatique *)
huet's avatar
huet committed
8 9 10 11 12 13 14 15
(**************************************************************************)

(* Verbs defines the conjugation paradigms, and computes conjugated forms *)
(* Computed forms comprise finite verbal forms of roots, but also derived
   nominal forms (participles), infinitives and absolutives *)
(* Terminology. record functions will build the forms needed by Conjugation
and Stemming. After change of this file, and "make releasecgi", these tables
are updated. But the Reader/Parser needs a full pass of generation, with 
Gérard Huet's avatar
Gérard Huet committed
16
"make scratch" from Dictionary, in order to rebuild the full automata. *)
huet's avatar
huet committed
17 18 19 20 21 22 23

(*i module Verbs = struct i*)

open List; (* map, length, rev *)
open Phonetics; (* [vowel, homonasal, duhify, mrijify, nahify, light, nasal, 
                    gana, mult, aug, trunc_a, trunc_u, trunc_aa] *)
open Skt_morph;
Gérard Huet's avatar
Gérard Huet committed
24
open Inflected; (* [Conju, Invar, Inftu, roots, enter1, morpho_gen, admits_aa] *)
huet's avatar
huet committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
open Parts; (* [memo_part, record_part, cau_gana, fix, fix_augment, rfix,
                compute_participles] *)
(* This module also uses modules [List2 Word Control Canon Encode Int_sandhi] 
   and interface [Conj_infos] *)
open Pada; (* [voices_of_gana] *)

(* In the grinding phase, we record for each root entry its class and its stem
   for 3rd present. In the declination phase, we compute the inflected forms and
   we record them with a pair [(entry,conjugs)] in verbs.rem, parts.rem, etc. *)

exception Not_attested (* No attested form *)
;
(* Present system - we give [vmorph] info [Prim root_class pada third_conjug] 
   where [third_conjug] is a word, used for checking the 3rd sg Para *)
value present  = Present 
and imperfect  = Imperfect
and optative   = Optative
and imperative = Imperative
;
(* Paradigms *)
value vpa cl = Presenta cl Present
and vpm cl =   Presentm cl Present
and vpp =      Presentp Present
and via cl =   Presenta cl Imperfect
and vim cl =   Presentm cl Imperfect
and vip =      Presentp Imperfect
and voa cl =   Presenta cl Optative
and vom cl =   Presentm cl Optative
and vop =      Presentp Optative
and vma cl =   Presenta cl Imperative
and vmm cl =   Presentm cl Imperative
and vmp =      Presentp Imperative
and vfa =    Conjug Future Active
and vfm =    Conjug Future Middle
and vca =    Conjug Conditional Active
and vcm =    Conjug Conditional Middle
and vfp =    Conjug Future Passive
and vpfa =   Conjug Perfect Active
and vpfm =   Conjug Perfect Middle
and vpfp =   Conjug Perfect Passive
and vbena =  Conjug Benedictive Active
and vbenm =  Conjug Benedictive Middle
and vaa cl = Conjug (Aorist cl) Active
and vam cl = Conjug (Aorist cl) Middle
and vja cl = Conjug (Injunctive cl) Active
and vjm cl = Conjug (Injunctive cl) Middle
and vap1 =   Conjug (Aorist 1) Passive     (* passive of root aorist *)
and vjp1 =   Conjug (Injunctive 1) Passive (* passive of root injunctive *)
;
(* Finite verbal forms of roots *)
value fpresa cl conj = (conj,vpa cl)
and fpresm cl conj =   (conj,vpm cl)
and fpresp conj =      (conj,vpp)
and fimpfta cl conj =  (conj,via cl)
and fimpftm cl conj =  (conj,vim cl)
and fimpftp conj =     (conj,vip)
and fopta cl conj =    (conj,voa cl)
and foptm cl conj =    (conj,vom cl)
and foptp conj =       (conj,vop)
and fimpera cl conj =  (conj,vma cl)
and fimperm cl conj =  (conj,vmm cl)
and fimperp conj =     (conj,vmp) 
and ffutura conj =     (conj,vfa)
and ffuturm conj =     (conj,vfm)
and fconda conj =      (conj,vca)
and fcondm conj =      (conj,vcm)
and fperfa conj =      (conj,vpfa)
and fperfm conj =      (conj,vpfm)
and fbenea conj =      (conj,vbena)
and fbenem conj =      (conj,vbenm)
and faora cl conj =    (conj,vaa cl)
and faorm cl conj =    (conj,vam cl)
and finja cl conj =    (conj,vja cl)
and finjm cl conj =    (conj,vjm cl)
and faorp1 conj =      (conj,vap1)
and finjp1 conj =      (conj,vjp1)
;
(* Primary finite verbal forms of roots *)
value presa cl = fpresa cl Primary
and presm cl   = fpresm cl Primary
and impfta cl  = fimpfta cl Primary
and impftm cl  = fimpftm cl Primary
and opta cl    = fopta cl Primary
and optm cl    = foptm cl Primary
and impera cl  = fimpera cl Primary
and imperm cl  = fimperm cl Primary
and futura  = ffutura Primary
and futurm  = ffuturm Primary
and perfa   = fperfa Primary
and perfm   = fperfm Primary
and aora cl = faora cl Primary
and aorm cl = faorm cl Primary
and aorp1   = faorp1 Primary
and benea   = fbenea Primary
and benem   = fbenem Primary
and inja cl = finja cl Primary
and injm cl = finjm cl Primary
and injp1   = finjp1 Primary
;
(* Participial forms *)
value pra k = Ppra k 
and prm k = Pprm k 
and prp   = Pprp
and pfta  = Ppfta
and pftm  = Ppftm
and futa  = Pfuta
and futm  = Pfutm
(* Also in Part: Ppp, Pppa, Ger=Pfut Passive, Inf *)
;
(* Verbal forms of roots *)
value vppra k conj = (conj,pra k)
and vpprm k conj = (conj,prm k)
and vppfta conj = (conj,pfta)
and vppftm conj = (conj,pftm)
and vpfuta conj = (conj,futa)
and vpfutm conj = (conj,futm)
and vpprp  conj = (conj,prp)
(* Also in Part: Ppp, Pppa, Ger=Pfut Passive, Inf *)
;
(* Verbal forms of roots *)
value ppra k = vppra k Primary
and pprm k = vpprm k Primary
and ppfta  = vppfta Primary
and ppftm  = vppftm Primary
and pfuta  = vpfuta Primary
and pfutm  = vpfutm Primary
and pprp   = vpprp Primary
;
(* Derived verbal forms *)
value causa = fpresa cau_gana Causative
and pcausa  = vppra cau_gana Causative
and causm   = fpresm cau_gana Causative
and pcausm  = vpprm cau_gana Causative
and causp   = fpresp Causative
and causfa  = ffutura Causative
and pcausfa = vpfuta Causative
and causfm  = ffuturm Causative
and pcausfm = vpfutm Causative
and caaora cl = faora cl Causative
and caaorm cl = faorm cl Causative
and intensa = fpresa int_gana Intensive
and pinta   = vppra int_gana Intensive
and intensm = fpresm int_gana Intensive
and pintm   = vpprm int_gana Intensive
and desida  = fpresa des_gana Desiderative
and pdesa   = vppra des_gana Desiderative
and desidm  = fpresm des_gana Desiderative
and pdesm   = vpprm des_gana Desiderative
and despfa  = fperfa Desiderative
and despfm  = fperfm Desiderative
;
value intimpfta = fimpfta int_gana Intensive
and intopta     = fopta   int_gana Intensive
and intimpera   = fimpera int_gana Intensive
;
value  code = Encode.code_string (* normalized *)
and revcode = Encode.rev_code_string (* reversed *)
and revstem = Encode.rev_stem (* stripped of homo counter *)
;
184 185 186
(* Checking consistency of computed form with witness from lexicon.      *)
(* Discrepancies are noted on a warnings log, written on stderr.         *)
(* NB currently log dumped in (D)STAT/warnings.txt by "make roots.rem".  *)
huet's avatar
huet committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
value emit_warning s =
  if morpho_gen.val then output_string stderr (s ^ "\n") else ((* cgi *))
;
value report entry gana listed computed =
  let s1 = Canon.decode computed
  and s2 = Canon.decode listed in
  let message = entry ^ " [" ^ string_of_int gana ^ "] wrong 3rd pr "
                      ^ s1 ^ " for " ^ s2 in
  emit_warning message 
;
(* third is attested from Dico, form is generated by morphology *)
value check entry gana third ((_,form) as res) = do
  { if third=[] (* no checking *) || third=form then () 
    else match entry with 
         [ "a~nc" | "kalu.s" | "kram" | "grah" | "cam" | "tul" | "t.rr"
         | "manth" | "v.r#1" | "huu" | "putr" 
             -> () (* 2 forms - avoids double warning *)
         | _ -> report entry gana third form
         ]
  ; res (* Note that the computed form has priority over the listed one. *)
        (* Log inspection leads to correction of either Dico or Verbs.   *)
  }
;
value warning message = 
  failwith (message ^ "\n")
and error_empty n = 
  failwith ("empty stem " ^ string_of_int n)
and error_suffix n = 
  failwith ("empty suffix " ^ string_of_int n)
and error_vowel n = 
  failwith ("no vowel in root " ^ string_of_int n)
;

(*****  Conjugation of verbal stems *****)

(* Suffixing uses [Int_sandhi.sandhi] (through Parts.fix) for thematic
   conjugation and conjugation of roots of ganas 5,7,8 and 9, and the following 
   sandhi function for athematic conjugation of roots of ganas 2 and 3 (through
   respectively fix2 and fix3w). *)

(* This sandhi restores initial aspiration if final one is lost -- Gonda§4 note.
   This concerns root syllables with initial g- d- b- and final -gh -dh -bh -h
   where aspiration is shifted forwards. The corresponding problem is dealt in 
   [Nouns.build_root] by [Phonetics.finalize], so there is some redundancy. 
   It is related to Grassmann's law and Bartholomae's law in IE linguistics. *)
value sandhi revstem wsuff = 
  let aspirate w = match w with
    [ [] -> w
    | [ c :: rest ] -> match c with (* uses arithmetic encoding for aspiration *)
       [ 19 | 34 | 39 (* g d b *) -> [ c+1 :: rest ] (* aspiration *)
       | _ -> w
       ]
    ] 
  and lost = match wsuff with 
    [ [] -> False
    | [ c :: _ ] -> match c with (* Gonda§4 note *)
      [ 48 (* s *) -> (* 32 | 33 | 35 | 49 (* t th dh h *) ? *) 
        match revstem with
        [ [ 20 :: _ ] | [ 35 :: _ ] | [ 40 :: _ ] | [ 49 :: _ ] 
          (* gh           dh            bh            h      *)
        | [ 149 :: _ ] | [ 249 :: _ ] 
          (* h'            h''     *) 
            -> True
        | _ -> False
        ]
      | _ -> False
      ] 
    ]
  and result = Int_sandhi.int_sandhi revstem wsuff in
  if lost then aspirate result else result
;

(* Theoretical general conjugational scheme : 
   Given the stem value, let conjug person suff = (person,fix stem suff) 
                             ([fix_augment] instead of [fix] for preterit) 
   We enter in the roots lexicon an entry:
  [ (Conju verbal 
     [ (Singular, 
        [ conjug First  suff_s1
        ; conjug Second suff_s2
        ; conjug Third  suff_s3
        ])
     ; (Dual,
        [ conjug First  suff_d1
        ; conjug Second suff_d2
        ; conjug Third  suff_d3
        ])
     ; (Plural,
        [ conjug First  suff_p1
        ; conjug Second suff_p2
        ; conjug Third  suff_p3
        ])
     ]) ]
  Remark. More general patterns such as above could have been used, in Paninian
  style, but at the price of complicating internal sandhi, for instance for
  dropping final a of the stem in [conjug First suff_s1] (Goldman§4.22).
  Here instead of st-a+e -> st-e we compute st-e with a shortened stem. 
  Similarly st-a+ete -> st-ete -> in Dual, see [compute_thematic_presentm] etc. 
*)

(* Returns the reverse of [int_sandhi] of reversed prefix and reversed stem *)
288 289 290 291 292 293 294
(* But [int_sandhi] may provoke too much retroflexion, such as *si.sarti 
   instead of sisarti for root s.r in redup3 below. 
   Same pb to avoid *pu.sphora as perfect of sphur, instead of pusphora. 
   Thus need of the boolean argument retr: *)
value revaffix retr revpref rstem = 
  let glue = if retr then Int_sandhi.int_sandhi else List2.unstack in
  rev (glue revpref (rev rstem)) (*i too many revs - ugly i*)
huet's avatar
huet committed
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
;
(* Computation of verbal stems from root *)

value  final_guna v w = List2.unstack (guna v) w
and final_vriddhi v w = List2.unstack (vriddhi v) w 
;
(* Strong form of reversed stem *)
value strong = fun (* follows Phonetics.gunify *)
  [ [] -> error_empty 1
  | [ v :: rest ] when vowel v -> final_guna v rest 
  | [ c :: [ v :: rest ] ] when short_vowel v -> [ c :: final_guna v rest ]
  | s -> s
  ]
;
(* Lengthened form of reversed stem *)
value lengthened = fun
  [ [] -> error_empty 2
  | [ v :: rest ] when vowel v -> final_vriddhi v rest 
  | [ c :: [ v :: rest ] ] when short_vowel v -> [ c :: final_vriddhi v rest ]
  | s -> s
  ]
;
value strengthen_10 rstem = fun
  [ "m.r.d" | "sp.rh" -> rstem (* exceptions with weak stem *)
  | "k.sal" -> lengthened rstem (* v.rddhi *)     
  | _ -> strong rstem  (* guna *) 
  ] 
;
(* .r -> raa (Whitney§882a, Macdonell§144.4) *)
value long_metathesis = fun (* .r penultimate -> raa *)
  [ [ c :: [ 7 (* .r *) :: rest ] ] -> [ c :: [ 2 :: [ 43 :: rest ] ] ]
  | _ -> failwith "long_metathesis"
  ]
;
(* truncates an rstem eg bh.rjj -> bh.rj *)
value truncate = fun 
  [ [] -> error_empty 3
  | [ _ :: r ] -> r
  ]
;
value strong_stem entry rstem = (* rstem = revstem entry *)
  match entry with 
    [ "am" -> revcode "amii" (* amiiti *)
    | "dah#1" | "dih" | "duh#1" | "druh#1" | "muh" | "snih#1" | "snuh#1"
               -> duhify (strong rstem)
    | "nah"    -> nahify (strong rstem)
    | "m.rj"   -> mrijify (revcode "maarj") (* maar.s.ti [long_metathesis] *)
    | "yaj#1" | "vraj" | "raaj#1" | "bhraaj" | "s.rj#1" 
               -> mrijify (strong rstem)
344 345
    | "bh.rjj" -> mrijify (strong (truncate rstem)) (* bh.rsj Pan{8,2,29} *)
    | "nij"    -> revcode "ni~nj" (* nasalisation for gana 2 *) 
huet's avatar
huet committed
346
    | "zrath"  -> revcode "zranth"
347
    | "diiv#1" -> revcode "dev"
huet's avatar
huet committed
348 349 350 351 352 353 354 355 356 357 358 359 360 361
    | _ -> strong rstem
    ]
;
value weak_stem entry rstem = (* rstem = revstem entry *)
  match entry with 
    [ "dah#1" | "dih" | "duh#1" | "druh#1" | "muh" | "snih#1" | "snuh#1"
               -> duhify rstem
    | "nah"    -> nahify rstem
    | "m.rj" | "yaj#1" | "vraj" | "raaj#1" | "bhraaj" | "s.rj#1" 
               -> mrijify rstem
    | "bh.rjj" -> mrijify (truncate rstem)
    | "nij"    -> revcode "ni~nj" (* nasalisation *)
    | "vaz"    -> revcode "uz" (* but not vac ! *)
    | "zaas"   -> revcode "zi.s" 
362
    | "myak.s" -> revcode "mik.s" 
huet's avatar
huet committed
363 364 365 366 367 368 369 370 371 372 373 374 375
    | _ -> rstem
    ]
;
(* samprasaara.na correction - weak strong and long rev stem words of root.    *)
(* Concerns 4 roots, lexicalized under their strong rather than weak stem.     *)
(* Beware. The sampra correction must be effected separately when [weak_stem]
   and [strong_stem] are invoked directly, rather than as components of stems. *)
value stems root = 
  let rstem = revstem root in
  let sampra substitute = 
      let lstem = lengthened rstem in
      (revstem substitute,rstem,lstem) in
  match root with (* This shows what ought to be the root name, its weak form *)
Gérard Huet's avatar
Gérard Huet committed
376 377
     [ "grah"   -> sampra "g.rh" (* \Pan{6,1,15} *) 
     | "vyadh"  -> sampra "vidh" (* \Pan{6,1,15} *) 
huet's avatar
huet committed
378
     | "spardh" -> sampra "sp.rdh"
Gérard Huet's avatar
Gérard Huet committed
379
     | "svap"   -> sampra "sup" (* \Pan{6,1,15} *) 
huet's avatar
huet committed
380
     (*  note "vac", "yaj" etc not concerned although having samprasaara.na *)
Gérard Huet's avatar
Gérard Huet committed
381
     | _ -> let weak   = weak_stem root rstem 
huet's avatar
huet committed
382 383 384 385 386 387 388 389 390 391 392 393
            and strong = strong_stem root rstem in
            let long = lengthened weak in
            (weak,strong,long)
     ]
;
value drop_penultimate_nasal = fun
  [ [ c :: [ n :: s ] ] -> if nasal n then [ c :: s ] 
                           else failwith "No penultimate nasal"
  | _ -> failwith "No penultimate nasal"
  ]
;
value passive_stem entry rstem = (* Panini -yak (k means no guna) *)
Gérard Huet's avatar
Gérard Huet committed
394
                                 (* k also means samprasaara.na *)
huet's avatar
huet committed
395 396 397 398 399 400 401
  let weak = match entry with 
  (* [weak] same as first component of [stems], except praz vac etc and bh.rjj *)
    [ "dah#1" | "dih" | "duh#1" | "druh#1" | "muh" | "snih#1" | "snuh#1"
              -> duhify rstem
    | "nah"   -> nahify rstem
    | "m.rj" | "vraj" | "raaj#1" | "bhraaj" | "s.rj#1" | "bh.rjj" 
              -> mrijify rstem
Gérard Huet's avatar
Gérard Huet committed
402
    | "yaj#1" -> mrijify (revcode "ij") (* samprasaara.na ya-x \R i-x \Pan{6,1,15} *)
huet's avatar
huet committed
403
    | "vyadh" -> revcode "vidh"  (* id *)
Gérard Huet's avatar
Gérard Huet committed
404
    | "grah"  -> revcode "g.rh"  (* samprasaara.na ra-x \R .r-x  \Pan{6,1,16} *) 
huet's avatar
huet committed
405
    | "vrazc" -> revcode "v.rzc" (* id *)
Gérard Huet's avatar
Gérard Huet committed
406 407
    | "praz"  -> revcode "p.rcch" (* id *)
    | "svap"  -> revcode "sup"   (* samprasaara.na va-x \R u-x \Pan{6,1,15} *) 
huet's avatar
huet committed
408 409 410 411 412 413 414
    | "vaz" | "vac" | "vap" | "vap#1" | "vap#2" | "vad" | "vas#1" | "vas#4" 
    | "vah#1" (* idem - specific code for va-x roots *)
              -> match rstem with 
                 [ [ 48 :: _ ] -> [ 47 ; 5 (* u *) ] (* vas \R u.s *)
                 | [ c :: _ ] -> [ c ; 5 (* u *) ] (* va-x \R u-x *)
                 | [] -> failwith "Anomalous passive_stem"
                 ]
Gérard Huet's avatar
Gérard Huet committed
415
    | "vaa#3" -> revcode "uu" (* \Pan{6,1,15} *) 
huet's avatar
huet committed
416 417 418 419 420
    | "zaas"  -> revcode "zi.s" (* ambiguous zi.s.ta, zi.syate *)
    | "zii#1" -> revcode "zay" (* \Pan{7,4,22} *) 
    | "pyaa"  -> revcode "pyaay" (* pyaa=pyai *)
    | "indh" | "und" | "umbh" | "gumph" | "granth" | "da.mz" | "dhva.ms"  
    | "bandh" | "bhra.mz" | "za.ms" | "zrambh" 
421
      (* above roots have penultimate nasal and do not have [i_it] marker *)
huet's avatar
huet committed
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
    | "ba.mh" | "ma.mh" | "manth" | "stambh" 
      (* these four roots are listed in dhatupathas as bahi, mahi, mathi, stabhi
         and thus appear here even though they admit [i_it] marker *)
              -> drop_penultimate_nasal rstem
    | _ -> match rstem with 
         (* -a~nc -aa~nc va~nc a~nj sa~nj [drop_penultimate_nasal] *)
         (* doubt for pi~nj and gu~nj since they admit [i_it] marker *)
         [ [ 22 :: [ 26 :: r ] ] (* -~nc *) -> [ 22 :: r ] (* -ac *)
         | [ 24 :: [ 26 :: r ] ] (* -~nj *) -> [ 24 :: r ] (* -aj *)
         | w -> w
         ]
    ] in 
  match weak with
    [ [ c :: rst ] -> match c with
        [ 2 (* aa *) -> match rst with
            [ [ 42 (* y *) :: r ] -> [ 4 (* ii *) :: r ] (* ziiyate stiiyate *)
            | _ -> match entry with
               [ "j~naa#1" | "dhyaa" | "bhaa#1" | "mnaa" | "yaa#1" | "laa"  
               | "zaa" | "haa#2" 
                   -> weak
               | _ -> [ 4 (* ii *) :: rst ]
               ]
            ]
        | 3 (* i *) -> [ 4 (* ii *) :: rst ]
        | 5 (* u *) -> match entry with
447
            [ "k.su" | "k.s.nu" | "plu" | "sru" -> weak
huet's avatar
huet committed
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
            | _ -> [ 6 (* uu *) :: rst ]
            ]
        | 7 (* .r *) -> match rst with
            [ [ _ ] -> [ 3 :: [ 43 :: rst ] ] (* ri- *)
            | _ (* 0 or 2 consonants *) -> [ 43 :: [ 1 :: rst ] ] (* ar- *)
            ]
        | 8 (* .rr *) -> match rst with
            [ [ d :: _ ] -> 
              if labial d then [ 43 :: [ 6 :: rst ] ] (* puuryate *)
                          else [ 43 :: [ 4 :: rst ] ] (* kiiryate ziiryate *)
            | _ -> error_empty 4
            ] 
        | _ -> if c>9 && c<14 (* e ai o au *) then match entry with
            [ "dhyai" -> [ 2 :: rst ] (* dhyaa in Dico *)
            | "hve" -> revcode "huu" (* huu in Dico, just for convenience *)
            | _ -> [ 4 (* ii *) :: rst ]
            ]
               else weak
        ]
    | [] -> error_empty 5 
    ] 
;
(* Reduplication for third class present: redup3 takes the root string  
   and its (reversed) stem word, and returns a triple [(s,w,b)] 
   where [s] is the (reversed) strong stem word, 
         [w] is the (reversed) weak stem word, 
         [b] is a boolean flag for special aa roots *)
value redup3 entry rstem = 
  match mirror rstem with 
    [ [] -> failwith "Empty root"
    | [ 7 (* .r *) ] -> (* Whitney§643d *) (revstem "iyar",revstem "iy.r",False)
    | [ c1 :: r ] -> if vowel c1 then failwith "Attempt reduplicating vowel root"
                     else 
      let v = lookvoy r
         where rec lookvoy = fun
           [ [] -> failwith "Attempt to reduplicate root with no vowel"
           | [ c2 :: r2 ] -> if vowel c2 then c2 else lookvoy r2
           ] 
      and iflag = match entry with (* special flag for some aa roots *)
           [ "gaa#1" | "ghraa" | "maa#1" | "zaa" | "haa#2" -> True
           | _ -> False 
           ] 
      and iflag2 = match entry with (* special flag for some other roots *)
           [ "maa#3" | "vac" | "vyac" -> True
           | _ -> False 
           ] in 
      let c = if sibilant c1 then match r with 
       (* c is reduplicating consonant candidate *)
                 [ [] -> failwith "Reduplicated root with no vowel"
                 | [ c2 :: _ ] -> if vowel c2 || nasal c2 then c1
                                  else if stop c2 then c2
                                  else (* semivowel c2 *) c1
                 ] 
              else c1 in
      let rv = (* rv is reduplicating vowel *)
        if entry="v.rt#1" then 1 (* a *) else
        if rivarna v || iflag || iflag2 then 3 (* i *)
        else if entry="nij" then 10 (* e *) (* Whitney says intensive! *)
        else short v (* reduplicated vowel is short *)
      and rc = match c with (* rc is reduplicating consonant *)
        [ 17 | 18 (* k kh *) -> 22 (* c *)
        | 19 | 20 | 49 (* g gh h *) -> 24 (* j *) 
        | 149 | 249 (* h' h2 *) -> failwith "Weird root of class 3"
        | 23 | 25 | 28 | 30 | 33 | 35 | 38 | 40 -> c-1 (* aspiration loss *)
        | _ -> c
        ] 
      and iiflag = iflag || entry = "haa#1" in 
      let (strong,weak) = 
           if iiflag then match rstem with
              [ [ 2 :: rest ] -> (rstem,[ 4 :: rest ]) (* aa \R ii *)
              | _ -> failwith "Anomaly Verbs"
              ]
           else let wstem = match entry with
                [ "daa#1" | "dhaa#1"  -> match rstem with
                   [ [ 2 :: rest ] -> rest (* drop final aa *)
                   | _ -> failwith "Anomaly Verbs"
                   ]
525
                | _ -> rstem 
huet's avatar
huet committed
526 527
                ] in 
      (strong rstem,wstem)
528 529 530 531 532
      and glue = match entry with
          [ "s.r" -> revaffix False [ rv; rc ] (* no retroflexion: sisarti *)
          | _ -> revaffix True [ rv; rc ] 
          ] in (glue strong,glue weak,iiflag) 
 (*        if entry="s.r" then (*i ad-hoc nonsense to avoid si.sarti ? i*)
Gérard Huet's avatar
Gérard Huet committed
533
             (revcode "sisar",revcode "sis.r",iiflag) 
534
        else (glue strong,glue weak,iiflag) *)
huet's avatar
huet committed
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
    ]
;

(* Dhatupatha markers (from AK's listing) *)
value aa_it = fun
  [ (* "muurch" | WRONG ? *) 
    "phal" | "zvit" | "svid#2" | "tvar" | "dh.r.s" -> True
  | _ -> False
  ]
and i_it = fun (* unused but subset of set in intercalates *)
  [ "vand" | "bhand" | "mand#1" | "spand" | "indh" | "nind" 
  | "nand" | "cand" | "zafk" | "iifkh" | "lafg" | "afg" | "ifg" 
  | "gu~nj" | "laa~nch" | "vaa~nch" | "u~nch" | "ku.n.d" | "ma.n.d" | "ku.n.th" 
  | "lu.n.th" | "kamp" | "lamb" | "stambh" | "j.rmbh" | "cumb" | "inv" | "jinv"
  | "ba.mh" | "ma.mh" | "ghu.s" | "kaafk.s" | "ra.mh" | "tvar" 
  | "pi~nj" | "rud#1" | "hi.ms" | "chand" | "lafgh" -> True
551
(* NB. other roots admitting set:
huet's avatar
huet committed
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
[ "a~nc" | "an#2" | "arh" | "av" | "az#1" | "az#2" | "as#2" | "aas#2"
| "i.s#1" | "i.s#2" | "iik.s" | "ii.d" | "iiz#1" | "uc" | "umbh" | "uuh" 
| ".rc#1" | ".rj" | ".rdh" | "edh" | "kafk" | "kam" | "ka.s" |  "kup" | "krand"
| "krii.d" | "khan" | "khaad" | "gam" | "ghaat" | "ghuur.n" | "cit#1" 
| "jak.s" | "jap" | "jalp" | "tak" | "tan#1" | "tan#2" | "tark" | "dagh" 
| "dabh" | "dham" | "dhva.ms" | "dhvan" | "pa.th" | "pat#1" | "piz" 
| "bhaa.s" | "bhraaj" | "mad#1" | "mlecch" | "yat#1" | "yaac" | "rak.s" 
| "raaj#1" | "ruc#1" | "lag" | "lap" | "la.s" | "lok" | "loc" | "vad" 
| "vam" | "vaz" | "vaaz" | "vip" | "ven" | "vyath" | "vraj" | "vrii.d"
| "za.ms" | "zas" | "zaas" | "zuc#1" | "san#1" | "skhal" | "spardh" | "sp.rh" 
| "sphu.t" | "svan" | "has" ] *) 
  | _ -> False
  ]
and ii_it = fun
  [ "hlaad" | "yat#1" | "cit#1" | "vas#4" | "jabh#1" | "kan" | "puuy" | "sphaa"
  | "pyaa" | "jan" | "n.rt" | "tras" | "diip" | "mad#1" | ".r.s" | "ju.s#1" 
  | "vij" | "d.rbh" | "gur" | "k.rt#1" | "indh" | "und" | "v.rj" | "p.rc" 
      -> True
  | _ -> False
  ]
and u_it = fun
573
  [ "sidh#2" | "a~nc" | "va~nc" | "zrambh" | "stubh" | "kam" | "cam" | "jam"
huet's avatar
huet committed
574 575 576 577 578 579 580 581
  | "kram" | ".s.thiiv" | "dhaav#1" | "gras" | "mi.s" | "p.r.s" | "v.r.s" 
  | "gh.r.s" | "zas" | "za.ms" | "sra.ms" | "dhva.ms" | "v.rt" | "v.rdh#1" 
  | "bhram" | "ram" | "m.rdh" | "khan" | "zaas" | "diiv#1" | "siiv" | "sidh#1"
  | "zam#1" | "tam" | "dam#1" | "zram" | "as#2" | "yas" | "jas" | "das" 
  | "bhra.mz" | ".rdh" | "g.rdh" | "dambh" | "i.s#1" | "t.rd" | "tan#1"
  | "k.san" -> True
  | _ -> False
  ]
582
and uu_it = fun (* perstems \Pan{7,2,44} *)
huet's avatar
huet committed
583 584
  [ "trap" | "k.sam" | "gaah" | "ak.s" | "tak.s" | "tvak.s" | "syand" | "k.rp" 
  | "guh" | "m.rj" | "klid" | "az#1" | "vrazc" | "b.rh#2" | "v.rh" | "a~nj"
585
  | "kli.s" | "ta~nc" -> True 
huet's avatar
huet committed
586 587
  | _ -> False
  ]
588
and o_it = fun (* these roots have ppp in -na \Pan{8,2,45} - unused here *)
huet's avatar
huet committed
589
  [ "zuu" | "haa#1" | "haa#2" | "vij" | "vrazc" | "bhuj#1" | "bha~nj" | "lag" 
590 591 592 593 594 595
 (* | "iir" | "und" | "k.rr" | "klid" | "k.sii" | "k.sud" | "k.svid" | "khid"
    | "g.rr#1" | "glai" | "chad#1" | "chid#1" | "ch.rd" | "j.rr" | ".dii"
    | "tud#1" | "t.rd" | "t.rr" | "dagh" | "d.rr" | "dev" | "draa#1" | "draa#2"
    | "nud" | "pad#1" | "pi#2" | "p.rr" | "pyaa" | "bhid#1" | "majj" | "man"
    | "mid" | "mlaa" | "ri" | "lii" | "luu#1" | "vid#2" | "vlii" | "zad" | "z.rr"
    | "sad#1" | "skand" | "st.rr" | "styaa" | "syand" | "svid#2" | "had" *)
596 597
 (* aussi "suu#2" suuna *)
      -> True 
huet's avatar
huet committed
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
  | _ -> False
  ]
;
(******************)
(* Present system *)
(******************)

(* In all such functions, [(stem : word)] is the code of the reversed stem. *)
(* Exemple pour cyu: stem=strong=guna=cyo et cyo+ati=cyavati par [int_sandhi] *)
value compute_thematic_presenta cl conj stem entry third = 
  let conjug person suff = (person,fix stem suff) in do
  { enter1 entry (Conju (fpresa cl conj)
   [ (Singular, 
        [ conjug First  "aami"
        ; conjug Second "asi"
        ; check entry cl third (conjug Third "ati") 
        ])
   ; (Dual,
        [ conjug First  "aavas"
        ; conjug Second "athas"
        ; conjug Third  "atas"
        ])
   ; (Plural,
        [ conjug First  "aamas"
        ; conjug Second "atha"
        ; conjug Third  "anti"
        ])
   ])
  ; let m_stem = match entry with (* Whitney§450 *)
        [ "b.rh#1" -> revcode "b.rh" (* not b.r.mh *)
        | _ -> stem 
        ] in
    let f_stem = match entry with (* Whitney§450f *)
        [ "j.rr" | "p.r.s" | "b.rh#1" (* | "mah" *) | "v.rh" -> rfix m_stem "at" 
        | _ -> rfix m_stem "ant" 
        ] in 
    if cl=4 && entry="daa#2" || entry="mah" then () (* to avoid dyat mahat *)
    else record_part (Ppra_ cl conj m_stem f_stem entry)
  }
;
value compute_thematic_presentm cl conj stem entry third = 
  let conjug person suff = (person,fix stem suff) in
  enter1 entry (Conju (fpresm cl conj)
   [ (Singular, 
        [ conjug First  "e"
        ; conjug Second "ase"
        ; check entry cl third (conjug Third "ate")
        ])
   ; (Dual,
        [ conjug First  "aavahe"
        ; conjug Second "ethe"
        ; conjug Third  "ete"
        ])
   ; (Plural,
        [ conjug First  "aamahe"
        ; conjug Second "adhve"
        ; conjug Third  "ante"
        ])
   ])
;
658
value thematic_preterit_a conjug = 
huet's avatar
huet committed
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
   [ (Singular, 
        [ conjug First  "am"
        ; conjug Second "as"
        ; conjug Third  "at"
        ])
   ; (Dual,
        [ conjug First  "aava"
        ; conjug Second "atam"
        ; conjug Third  "ataam"
        ])
   ; (Plural, 
        [ conjug First  "aama"
        ; conjug Second "ata"
        ; conjug Third  "an"
        ])
   ]
;
676
value compute_thematic_impfta cl conj stem entry =  
huet's avatar
huet committed
677 678 679
  let conjug person suff = (person,fix_augment stem suff) in
  enter1 entry (Conju (fimpfta cl conj) (thematic_preterit_a conjug))
;
680
value thematic_preterit_m conjug = 
huet's avatar
huet committed
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
   [ (Singular, 
        [ conjug First  "e"
        ; conjug Second "athaas"
        ; conjug Third  "ata"
        ])
   ; (Dual,
        [ conjug First  "aavahi"
        ; conjug Second "ethaam"
        ; conjug Third  "etaam"
        ])
   ; (Plural,
        [ conjug First  "aamahi"
        ; conjug Second "adhvam"
        ; conjug Third  "anta"
        ])
   ]
;
698
value compute_thematic_impftm cl conj stem entry =  
huet's avatar
huet committed
699 700 701
  let conjug person suff = (person,fix_augment stem suff) in
  enter1 entry (Conju (fimpftm cl conj) (thematic_preterit_m conjug))
;
702
value compute_thematic_optativea cl conj stem entry = 
huet's avatar
huet committed
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
  let conjug person suff = (person,fix stem suff) in
  enter1 entry (Conju (fopta cl conj)
   [ (Singular, 
        [ conjug First  "eyam"
        ; conjug Second "es"
        ; conjug Third  "et"
        ])
   ; (Dual,
        [ conjug First  "eva"
        ; conjug Second "etam"
        ; conjug Third  "etaam"
        ])
   ; (Plural,
        [ conjug First  "ema"
        ; conjug Second "eta"
        ; conjug Third  "eyur"
        ])
   ])
;
value compute_thematic_optativem cl conj stem entry =
  let conjug person suff = (person,fix stem suff) in
  enter1 entry (Conju (foptm cl conj)
   [ (Singular, 
        [ conjug First  "eya"
        ; conjug Second "ethaas"
        ; conjug Third  "eta"
        ])
   ; (Dual,
        [ conjug First  "evahi"
        ; conjug Second "eyaathaam"
        ; conjug Third  "eyaataam"
        ])
   ; (Plural,
        [ conjug First  "emahi"
        ; conjug Second "edhvam"
        ; conjug Third  "eran"
        ])
   ])
;
value compute_thematic_imperativea cl conj stem entry =
  let conjug person suff = (person,fix stem suff) in
  enter1 entry (Conju (fimpera cl conj)
   [ (Singular, 
        [ conjug First  "aani"
        ; conjug Second "a"
        ; conjug Third  "atu"
        ])
   ; (Dual,
        [ conjug First  "aava"
        ; conjug Second "atam"
        ; conjug Third  "ataam"
        ])
   ; (Plural,
        [ conjug First  "aama"
        ; conjug Second "ata"
        ; conjug Third  "antu"
        ])
   ])
;
762
value compute_thematic_imperativem cl conj stem entry = 
huet's avatar
huet committed
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781
  let conjug person suff = (person,fix stem suff) in
  enter1 entry (Conju (fimperm cl conj)
   [ (Singular, 
        [ conjug First  "ai"
        ; conjug Second "asva"
        ; conjug Third  "ataam"
        ])
   ; (Dual,
        [ conjug First  "aavahai"
        ; conjug Second "ethaam"
        ; conjug Third  "etaam"
        ])
   ; (Plural,
        [ conjug First  "aamahai"
        ; conjug Second "adhvam"
        ; conjug Third  "antaam"
        ])
   ])
; 
782
value record_part_m (conj,part_kind) stem entry = match part_kind with 
huet's avatar
huet committed
783 784 785 786 787 788 789 790
  [ Pprm k -> record_part (Pprm_ k conj stem entry)
  | Pprp   -> record_part (Pprp_ conj stem entry)
  | Ppfta  -> record_part (Ppfta_ conj stem entry)
  | Ppftm  -> record_part (Ppftm_ conj stem entry)
  | Pfutm  -> record_part (Pfutm_ conj stem entry)
  | _ -> failwith "Unexpected participle"
  ]
;
791
value record_part_m_th verbal stem entry =  
huet's avatar
huet committed
792 793 794
  match entry with
  [ "cint" -> let pprm = Pprm_ 10 Primary (revcode "cintayaan") entry in
              record_part pprm (* irregular *)
Gérard Huet's avatar
Gérard Huet committed
795 796 797
  | "muc#1" | "sp.rz#1" -> 
         let mid_stem = rfix stem "aana" in (* Whitney§752 *)
         record_part_m verbal mid_stem entry 
huet's avatar
huet committed
798 799 800 801
  | _ -> let mid_stem = trunc_a (rfix stem "amaana") (* -maana *) in
         (* [trunc_a] needed because possible retroflexion in amaa.na *)
         record_part_m verbal mid_stem entry 
  ]
802
and record_part_m_ath verbal stem entry =  
huet's avatar
huet committed
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
  let suff = if entry = "aas#2" then "iina" (* McDonell§158a *)
             else "aana" (* -aana *) in
  let mid_stem = match rfix stem suff  with
                 [ [ 1 :: r ] -> r | _ -> failwith "Anomaly Verbs" ] in
  (* rare (Whitney). Creates bizarre forms such as plu -> puplvaana *)
  record_part_m verbal mid_stem entry 
;
(* Thematic present system - gana is root's present class *)
value compute_thematic_active gana conj stem entry third = do 
  { compute_thematic_presenta gana conj stem entry third
  ; compute_thematic_impfta gana conj stem entry 
  ; compute_thematic_optativea gana conj stem entry 
  ; compute_thematic_imperativea gana conj stem entry 
  } 
and compute_thematic_middle gana conj stem entry third = do 
  { compute_thematic_presentm gana conj stem entry third
  ; compute_thematic_impftm gana conj stem entry 
  ; compute_thematic_optativem gana conj stem entry 
  ; compute_thematic_imperativem gana conj stem entry 
  ; record_part_m_th (vpprm gana conj) stem entry
  }
;
value compute_causativea  = compute_thematic_active cau_gana Causative
and compute_causativem    = compute_thematic_middle cau_gana Causative
and compute_desiderativea = compute_thematic_active des_gana Desiderative
and compute_desiderativem = compute_thematic_middle des_gana Desiderative
;

(*** Gana 2 (root conjugation) ***)

(* [fix2: Word.word -> string -> string -> Word.word] *)
(* set indicates connecting vowel string of se.t root *)
value fix2 stem suff set = 
  let codesf = code suff in 
  let wsfx = match codesf with 
      [ [] -> error_suffix 1
      | [ c :: _ ] -> if vowel c || c=42 (* y *) then codesf
                      else if set then [ 3 :: codesf ] (* pad with initial i *)
                      else codesf
      ] in 
  sandhi stem wsfx
;
(* correction for i, ii, u, uu roots of gana 2 *)
value correct2 weak = match weak with
    [ [ 3 ] (* i *)           -> weak (* eg ppr yat \Pan{6,4,81} *)
    | [ 3 (* i *) ::  rest ]  -> [ 42 :: weak ]
    | [ 4; 46 ] (* zii *)     -> [ 42; 1; 46 ] (* zay *)  
    | [ 4 (* ii *) ::  rest ] -> [ 42 :: [ 3 :: rest ] ] (* iy *)
    | [ 5 (* u *) ::  rest ]  -> [ 45 :: weak ]
    | [ 6 (* uu *) ::  rest ] -> [ 45 :: [ 5 :: rest ] ] (* uv *)
    | _                       -> weak 
    ] 
;
value fix2w weak suff set =
  let weakv = correct2 weak 
  and weakc = match weak with
    [ [ 4; 46 ] (* zii *) -> [ 10; 46 ] (* ze *)
    | _ -> weak 
    ] in 
  match code suff with 
    [ [ c :: _ ] -> fix2 (if vowel c then weakv else weakc) suff set
    | [] -> error_suffix 7
    ]
;
value fix2w_augment weak suff set = aug (fix2w weak suff set)
;
value fix2wi suff = (* special for root i middle *)
  match code suff with (* \Pan{6,4,77} *)
    [ [ c :: _ ] -> fix2 (if vowel c then [ 42; 3 ] else [ 3 ]) suff False
    | [] -> error_suffix 15
    ]
;
value fix2whan suff = 
  let codesf = code suff in
  let stem = match codesf with 
     [ [] -> error_suffix 2
     | [ c :: _ ] -> if vowel c then "ghn"
                     else if c=41 || c=42 || c=45  (* m y v *) then "han"
                     else "ha"
     ] in 
  sandhi (revcode stem) codesf
;
value fix2whan_augment suff =
  let codesf = code suff in
  let stem = match codesf with 
     [ [] -> error_suffix 3
     | [ c :: _ ] -> if vowel c then "aghn"
                     else if c=41 || c=42 || c=45  (* m y v *) then "ahan"
                     else "aha"
     ] in 
  sandhi (revcode stem) codesf
;
(* correction for u roots *)
value fix2s strong suff set = match strong with
  [ [ 12 (* o *) ::  rest ] -> match code suff with
      [ [ c :: _ ] -> if vowel c then fix2 strong suff set
                      else fix2 [ 13 (* au *) :: rest ] suff set
      | [] -> error_suffix 4
      ]
  | _ -> fix2 strong suff set
  ]
;
value fix2s_augment strong suff set = aug (fix2s strong suff set)
;
value fix2sbruu suff = 
  let strong = revcode "bro" in
  match code suff with
      [ [ c :: _ ] -> let suff' = if vowel c then suff else "ii" ^ suff in
                      fix2 strong suff' False
      | [] -> error_suffix 5
      ]
;
value fix2sbruu_augment suff = aug (fix2sbruu suff)
;
(* \Pan{6,1,6} reduplicated roots dropping the n of 3rd pl -anti *)
value abhyasta = fun 
  [ "jak.s" | "jaag.r" | "cakaas" -> True (* zaas has special treatment *)
  | _ -> False
  ]
;
value compute_athematic_present2a strong weak set entry third = 
  let conjugs person suff =
      (person,if entry = "bruu" then fix2sbruu suff 
              else fix2s strong suff set)
  and conjugw person suff =
      (person,if entry = "han#1" then fix2whan suff 
              else fix2w weak suff set) in do
  { enter1 entry (Conju (presa 2)
   [ (Singular, let l =
        [ conjugs First "mi"
        ; if entry = "as#1" then (Second, code "asi")
          else conjugs Second "si"
        ; check entry 2 third (conjugs Third "ti") 
        ] in if entry ="bruu" then [ conjugw First "mi" :: l ]
             else if entry ="stu" then [ (First, code "staviimi") :: l ]
             else l (* bruumi Whitney§632 staviimi Whitney§633 *))
   ; (Dual,
        [ conjugw First  "vas"
        ; conjugw Second "thas"
        ; conjugw Third  "tas"
        ])
   ; (Plural, let l =
        [ conjugw First  "mas"
        ; conjugw Second "tha"
        ; if entry = "zaas" then conjugs Third "ati" (* \Pan{7,1,4} *)
          else conjugw Third (if abhyasta entry then "ati" else "anti")
        ] in if entry = "m.rj" then [ conjugs Third "anti" :: l ]
             else l (* Whitney§627 *))
   ])
  }
;
value compute_athematic_present2m strong weak set entry third = 
  let conjugs person suff = 
      (person,if entry = "bruu" then fix2sbruu suff 
              else fix2s strong suff set)
  and conjugw person suff =
      (person,if entry = "han#1" then fix2whan suff 
              else if entry = "i" then fix2wi suff 
              else fix2w weak suff set) in
  enter1 entry (Conju (presm 2)
   [ (Singular, let l = 
        [ if entry = "as#1" then (First, code "he") else
          conjugw First "e" 
        ; conjugw Second "se"
        ; check entry 2 third (conjugw Third "te") 
        ] in if entry = "m.rj" then [ conjugs First "e" :: l ]
             else l (* Whitney§627 *))
   ; (Dual, let l =
        [ conjugw First  "vahe"
        ; conjugw Second "aathe"
        ; conjugw Third  "aate"
        ] in if entry = "m.rj" then 
                [ conjugs Second "aathe"
                ; conjugs Third  "aate"
                ] @ l
             else l (* Whitney§627 *))  
   ; (Plural, let l =
        [ conjugw First  "mahe" 
        ; if entry = "as#1" then (Second, code "dhve") else
982
          if entry = "aas#2" then (Second, code "aadhve") else (* #Whitney§612 *)
983
          conjugw Second "dhve" 
huet's avatar
huet committed
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
        ; if entry = "zii#1" then conjugw Third "rate" (* \Pan{7,1,6} *)
          else conjugw Third "ate" 
        ] in if entry = "m.rj" then [ conjugs Third "ate" :: l ]
             else l (* Whitney§627 *)) 
   ])
;
value compute_athematic_impft2a strong weak set entry = 
  let conjugs person suff = 
      (person,if entry = "bruu" then fix2sbruu_augment suff 
              else fix2s_augment strong suff set)
  and conjugw person suff =
      (person,if entry = "han#1" then fix2whan_augment suff 
              else fix2w_augment weak suff set) in
  enter1 entry (Conju (impfta 2)
   [ (Singular, let l = 
        [ conjugs First "am"
        ; if set then conjugs Second "as"
          else if entry = "as#1" then conjugs Second "iis" (* Whitney§621c *)
          else if entry = "ad#1" then conjugs Second "as"  (* Whitney§621c *)
                    else conjugs Second "s" 
        ; if set then conjugs Third "at"
          else if entry = "as#1" then conjugs Third "iit"     (* idem aasiit *)
               else if entry = "ad#1" then conjugs Third "at" (* idem aadat *)
                    else conjugs Third "t"
        ] in if set then 
        [ conjugs Second "iis"
1010
        ; conjugs Third  "iit" 
huet's avatar
huet committed
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
        ] @ l else if entry = "bruu" 
                   then [ (First, code "abruvam") (* Whitney§632 *) :: l ]
                   else l)
   ; (Dual,
        [ conjugw First  "va"
        ; conjugw Second "tam"
        ; conjugw Third  "taam"
        ])
   ; (Plural, let l = 
        [ conjugw First  "ma"
        ; conjugw Second "ta"
        ; if entry = "i" then conjugs Third "an" (* aayan *)
1023 1024 1025 1026 1027 1028
          else match entry with (* Kane§429 *)
               [ "cakaas" | "jak.s" | "jaag.r" 
            (* | "daridraa" - should concern "draa#1" TODO *)
               | "zaas" -> conjugw Third "us" 
               | _ -> conjugw Third "an" 
               ]
huet's avatar
huet committed
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
        ] in if entry = "m.rj" 
                  then [ conjugs Third "an" :: l ] (* Whitney§627 *)
             else if entry = "bruu" 
                  then [ (Third, code "abruuvan") :: l ] (* Whitney§632 *)
             else match weak with (* Kale§420 optional -us for roots in -aa *)
                  [ [ 2 :: s ] -> [ (Third, aug (sandhi s (code "us"))) :: l ] 
                  | _ ->  l
                  ]) 
   ])
;
value compute_athematic_impft2m strong weak set entry = 
  let conjugs person suff = 
      (person,if entry = "bruu" then fix2sbruu_augment suff 
              else fix2s_augment strong suff set)
  and conjugw person suff =
      (person,if entry = "han#1" then fix2whan_augment suff 
              else fix2w_augment weak suff set) in
  enter1 entry (Conju (impftm 2)
   [ (Singular, let l =
        [ if entry = "i" then conjugw First "yi" (* adhyaiyi Bucknell 128 *)
          else conjugw First "i"
        ; conjugw Second "thaas"
        ; conjugw Third  "ta"
        ] in if entry = "m.rj" then [ conjugs First "i" :: l ]
             else l (* Whitney§627 *))
   ; (Dual, let l =
        [ conjugw First  "vahi"
        ; conjugw Second "aathaam"
        ; conjugw Third  "aataam"
        ] in if entry = "m.rj" then 
                [ conjugs Second "aathaam"
                ; conjugs Third  "aataam"
                ] @ l else l (* Whitney§627 *))
    ; (Plural, let l =
        [ conjugw First  "mahi"
1064
        ; if entry = "aas#2" then (Second, code "aadhvam") (* #Whitney§620 *) 
1065 1066 1067 1068 1069 1070 1071
          else conjugw Second "dhvam"
        ; if entry = "zii#1" then conjugw Third "rata" (* \Pan{7,1,6} *) else
          if entry = "i" then conjugw Third "yata" (* Bucknell 128 *) else
          conjugw Third "ata"
        ] in if entry = "m.rj" then [ conjugs Third "ata" :: l ] else
             if entry ="duh#1" then [ conjugw Third "ra" :: l ]
             (* aduhata -> aduha-a = \Pan{7,1,41} aduha -> aduhra \Pan{7,1,8} *)
huet's avatar
huet committed
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
             else l (* Whitney§627 *))
   ]) 
;
value compute_athematic_optative2a weak set entry =
  let conjugw person suff =
      (person,if entry = "han#1" then fix2whan suff 
                                 else fix2w weak suff set) in
  enter1 entry (Conju (opta 2)
   [ (Singular, let l =
        [ conjugw First  "yaam"
        ; conjugw Second "yaas"
        ; conjugw Third  "yaat"
        ] in if entry = "bruu" 
             then [ (Third, code "bruyaat") (* Whitney§632 *) :: l ]
             else l)
   ; (Dual,
        [ conjugw First  "yaava"
        ; conjugw Second "yaatam"
        ; conjugw Third  "yaataam"
        ])
   ; (Plural,
        [ conjugw First  "yaama"
        ; conjugw Second "yaata"
        ; conjugw Third  "yur"
        ])
   ])
;
value compute_athematic_optative2m weak set entry =
  let conjugw person suff =
      (person,if entry = "han#1" then fix2whan suff 
                                 else fix2w weak suff set)
  and conjugwmrij person suff = (person, fix2 (revcode "maarj") suff set) in
  enter1 entry (Conju (optm 2)
   [ (Singular, let l =
        [ conjugw First  "iiya"
        ; conjugw Second "iithaas"
        ; conjugw Third  "iita"
        ] in if entry = "m.rj" then 
                [ conjugwmrij First  "iiya"
                ; conjugwmrij Second "iithaas"
                ; conjugwmrij Third  "iita"
                ] @ l 
             else l (* Whitney§627 *))
   ; (Dual, let l =
        [ conjugw First  "iivahi"
        ; conjugw Second "iiyaathaam"
        ; conjugw Third  "iiyaataam"
        ] in if entry = "m.rj" then 
                [ conjugwmrij First  "iivahi"
                ; conjugwmrij Second "iiyaathaam"
                ; conjugwmrij Third  "iiyaataam"
                ] @ l 
             else l (* Whitney§627 *))
   ; (Plural, let l =
        [ conjugw First  "iimahi"
        ; conjugw Second "iidhvam"
1128
        ; conjugw Third  "iiran" (* TODO: Kane§429 like impft2 above *)
huet's avatar
huet committed
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
        ] in if entry = "m.rj" then 
                [ conjugwmrij First  "iimahi"
                ; conjugwmrij Second "iidhvam"
                ; conjugwmrij Third  "iiran"
                ] @ l 
             else l (* Whitney§627 *))
   ])
;
value compute_athematic_imperative2a strong weak set entry =
  let conjugs person suff = 
      (person,if entry = "bruu" then fix2sbruu suff 
                                else fix2s strong suff set)
  and conjugw person suff =
      (person,if entry = "han#1" then fix2whan suff 
                                 else fix2w weak suff set) in
  enter1 entry (Conju (impera 2)
   [ (Singular, let l =
        [ conjugs First "aani"
        ; (Second, match entry with
          [ "as#1" -> code "edhi"
          | "zaas" -> code "zaadhi" 
 (* above leads to conflict between \Pan{6.4.35} (zaa+hi) and \Pan{6.4.101} 
    (zaas+dhi) [asiddhavat] => we operate in parallel zaa+dhi= zaadhi *)
1152
          | "cakaas" -> code "cakaadhi" (* Kane§429 *)  
huet's avatar
huet committed
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
          | _ -> let w = if entry = "han#1" then revcode "ja" else weak in
                 match w with 
            [ [ c :: _  ] -> fix2 w suff set
              where suff = if vowel c || set then "hi" else "dhi"
            | _ -> error_empty 6
            ] (* "dhi" or "hi" after vowel *)
          ])
        ; conjugs Third "tu"
        ] in if entry = "vac" then 
                [ (Second, code "voci"); (Third, code "vocatu") ] @ l
             else if entry ="bruu" then [ conjugs Second "hi" :: l ]
                  (* braviihi Whitney§632 *)
1165 1166
             else if entry ="cakaas" then [ (Second, code "cakaadvi") :: l ]
                  (* Kane§429 *)  
huet's avatar
huet committed
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
             else l)
   ; (Dual,
        [ conjugs First  "aava"
        ; conjugw Second "tam"
        ; conjugw Third  "taam"
        ])
   ; (Plural, let l =
        [ conjugs First  "aama"
        ; conjugw Second "ta"
        ; if entry = "zaas" then conjugs Third "atu" (* \Pan{7,1,4} *)
        else conjugw Third (if abhyasta entry then "atu" else "antu") 
        ] in if entry = "m.rj" then [ conjugs Third "antu" :: l ]
             else l (* Whitney§627 *))
   ])
;
value compute_athematic_imperative2m strong weak set entry =
  let conjugs person suff = 
      (person,if entry = "bruu" then fix2sbruu suff 
              else fix2s strong suff set)
  and conjugw person suff =
      (person,if entry = "han#1" then fix2whan suff 
              else fix2w weak suff set) in
  enter1 entry (Conju (imperm 2)
   [ (Singular, 
        [ conjugs First  "ai"
        ; conjugw Second "sva"
        ; conjugw Third  "taam"
        ])
   ; (Dual, let l =
        [ conjugs First  "aavahai"
        ; conjugw Second "aathaam"
        ; conjugw Third  "aataam"
        ] in if entry = "m.rj" then 
                [ conjugs Second "aathaam"
                ; conjugs Third  "aataam"
                ] @ l
             else l (* Whitney§627 *))
   ; (Plural, let l =
        [ conjugs First  "aamahai"
1206
        ; if entry = "aas#2" then (Second, code "aadhvam") (* #Whitney§617 *) 
1207
          else conjugw Second "dhvam"
huet's avatar
huet committed
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
        ; if entry = "zii#1" then conjugw Third "rataam" (* \Pan{7,1,6} *)
          else conjugw Third "ataam"
        ] in if entry = "m.rj" then [ conjugs Third "ataam" :: l ]
             else l (* Whitney§627 *))
   ])
;
value compute_active_present2 sstem wstem set entry third = do
  { compute_athematic_present2a sstem wstem set entry third
  ; let weak = if entry = "as#1" then [ 48; 1 ] else wstem in
    compute_athematic_impft2a sstem weak set entry 
  ; compute_athematic_optative2a wstem set entry 
  ; compute_athematic_imperative2a sstem wstem set entry 
  ; match wstem with 
    [ [ 2 :: _ ] -> (* Ppr of roots in -aa is complex and overgenerates *)
Gérard Huet's avatar
Gérard Huet committed
1222
      match entry with 
1223
      [ "bhaa#1" | "maa#1" | "yaa#1" -> () (* no known ppra *)
1224
      | _ -> let m_pstem = wstem and f_pstem = rev (fix2w wstem "at" set) in 
Gérard Huet's avatar
Gérard Huet committed
1225 1226
             record_part (Ppra_ 2 Primary m_pstem f_pstem entry) 
      ]
huet's avatar
huet committed
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289
    | _ -> let m_pstem = if entry = "han#1" then revstem "ghn" 
                         else correct2 wstem in
           let f_pstem = if entry = "han#1" then revstem "ghnat" 
                         else rev (fix2w wstem "at" set) in 
           record_part (Ppra_ 2 Primary m_pstem f_pstem entry)
    ]
  ; if entry = "m.rj" then let m_pstem = revstem "maarj" in
                           let f_pstem = revstem "maarjat" in
                           record_part (Ppra_ 2 Primary m_pstem f_pstem entry)
    else ()
  }
and compute_middle_present2 sstem wstem set entry third = do
  { compute_athematic_present2m sstem wstem set entry third
  ; compute_athematic_impft2m sstem wstem set entry 
  ; compute_athematic_optative2m wstem set entry 
  ; compute_athematic_imperative2m sstem wstem set entry 
  ; match entry with
    [ "maa#1" -> () (* no pprm *)
    | "i" -> record_part_m_ath (pprm 2) [ 42; 3 ] entry (* iyaana *)
    | _ -> record_part_m_ath (pprm 2) (correct2 wstem) entry
    ]
  }
;

(*** Gana 3  ***)

value strip_ii = fun 
  [ [ 4 :: w ] -> w (* ii disappears before vowels in special roots *)
  | _ -> failwith "Wrong weak stem of special 3rd class root"
  ] 
;
value fix3w wstem iiflag dadh suff = 
  let codesf = code suff in 
  let short = if iiflag then strip_ii wstem else wstem in
  let stem = match codesf with 
     [ [] -> error_suffix 8
     | [ 5; 43 ] (* ur *) -> if iiflag then short else strong wstem (* guna *)
     | [ c :: _ ] -> if dadh then match c with (* Gonda§66 *)
            [ 32 | 33 | 35 | 48 | 49 (* t th dh s h *) -> revstem "dhad" 
               (* aspirate correction of sandhi not enough : dh+t=ddh not tt *)
            | _ -> short
            ]        else if vowel c then short else wstem
     ] in
  sandhi stem codesf
;
value fix3w_augment wstem iiflag dadh suff = aug (fix3w wstem iiflag dadh suff)
;
value compute_athematic_present3a strong weak iiflag entry third = 
  let dadh_flag = (entry="dhaa#1") in 
  let conjugs person suff = (person,fix strong suff) 
  and conjugw person suff = (person,fix3w weak iiflag dadh_flag suff)
  and conjughaa person suff = (person,fix (revstem "jahi") suff) 
                              (* weak = jahii but optionally jahi *)
  and haa_flag = (entry="haa#1") in do
  { enter1 entry (Conju (presa 3)
   [ (Singular, 
        [ conjugs First  "mi"
        ; conjugs Second "si"
        ; check entry 3 third (conjugs Third "ti") 
        ])
   ; (Dual, let l =
        [ conjugw First  "vas"
        ; conjugw Second "thas"
1290
        ; conjugw Third  "tas" 
huet's avatar
huet committed
1291 1292 1293 1294
        ] in if haa_flag then l @
                [ conjughaa First  "vas"
                ; conjughaa Second "thas"
                ; conjughaa Third  "tas"
1295
                ]
huet's avatar
huet committed
1296 1297 1298
             else l)
   ; (Plural, let l =
        [ conjugw First  "mas"
1299 1300 1301 1302
        ; conjugw Second "tha" 
        ; if entry="bhas" then (Third, code "bapsati") (* Whitney§678 MW§340 *) 
          else conjugw Third  "ati" 
        ] in if haa_flag then l @ 
huet's avatar
huet committed
1303 1304 1305 1306 1307
                [ conjughaa First  "mas"
                ; conjughaa Second "tha"
                ]    
             else l)
   ])
1308 1309 1310
  ; let wstem = if iiflag then strip_ii weak else 
                if entry="bhas" then revcode "baps" (* Whitney§678 *) 
                else weak in (* 3rd pl weak stem *)
huet's avatar
huet committed
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480
    record_part (Pprared_ Primary wstem entry) 
  }
;
value compute_athematic_present3m conj gana weak iiflag entry third = 
  let dadh_flag = (entry="dhaa#1") in
  let conjugw person suff = (person,fix3w weak iiflag dadh_flag suff) in
  enter1 entry (Conju (fpresm gana conj)
   [ (Singular, 
        [ conjugw First  "e" 
        ; conjugw Second "se"
        ; check entry 3 third (conjugw Third "te") 
        ])
   ; (Dual, 
        [ conjugw First  "vahe"
        ; conjugw Second "aathe"
        ; conjugw Third  "aate"
        ])
   ; (Plural,
        [ conjugw First  "mahe"
        ; conjugw Second "dhve"
        ; conjugw Third  "ate"
        ])
   ])
;
value compute_athematic_impft3a strong weak iiflag entry = 
  let dadh_flag = (entry="dhaa#1") in
  let conjugs person suff = (person,fix_augment strong suff)
  and conjugw person suff = (person,fix3w_augment weak iiflag dadh_flag suff)
  and conjughaa person suff = (person,fix_augment (revstem "jahi") suff) 
  and haa_flag = (entry="haa#1") in 
  enter1 entry (Conju (impfta 3)
   [ (Singular, let l = 
        [ conjugs First  "am"
        ; conjugs Second "s" 
        ; conjugs Third  "t"
        ] in if haa_flag then l @
                [ conjughaa Second "s"
                ; conjughaa Third "t"
                ]
             else l)
   ; (Dual, let l = 
        [ conjugw First  "va"
        ; conjugw Second "tam"
        ; conjugw Third  "taam"
        ] in if haa_flag then l @
                [ conjughaa First  "va"
                ; conjughaa Second "tam"
                ; conjughaa Third  "taam"
                ]    
             else l)
   ; (Plural, let l = 
        [ conjugw First  "ma"
        ; conjugw Second "ta"
        ; conjugw Third  "ur"
        ] in if haa_flag then l @
                [ conjughaa First  "ma"
                ; conjughaa Second "ta"
                ]
             else l)
   ])
;
(* common to [impft_m]  and [root_aoristm] *)
value conjugs_past_m conjug =
   [ (Singular, 
        [ conjug First  "i"
        ; conjug Second "thaas"
        ; conjug Third  "ta"
        ])
   ; (Dual,
        [ conjug First  "vahi"
        ; conjug Second "aathaam"
        ; conjug Third  "aataam"
        ])
   ; (Plural, 
        [ conjug First  "mahi"
        ; conjug Second "dhvam"
        ; conjug Third  "ata"
        ])
   ]
;
value conjug_impft_m gana conjugw = (* used by classes 3 and 9 *)
  Conju (impftm gana) (conjugs_past_m conjugw)
;
value compute_athematic_impft3m weak iiflag entry = 
  let dadh_flag = (entry="dhaa#1") in
  let conjugw person suff = (person,fix3w_augment weak iiflag dadh_flag suff) in
  enter1 entry (conjug_impft_m 3 conjugw)
;
(* Like [compute_athematic_optative2a] except for [yan#1] et [bruu] *)
value conjug_optativea gana conj conjugw =
  Conju (fopta gana conj)
   [ (Singular, 
        [ conjugw First  "yaam"
        ; conjugw Second "yaas"
        ; conjugw Third  "yaat"
        ])
   ; (Dual,
        [ conjugw First  "yaava"
        ; conjugw Second "yaatam"
        ; conjugw Third  "yaataam"
        ])
   ; (Plural,
        [ conjugw First  "yaama"
        ; conjugw Second "yaata"
        ; conjugw Third  "yur"
        ])
   ]
;
value conjug_opt_ath_a gana = conjug_optativea gana Primary
;
value compute_athematic_optative3a weak iiflag entry =
  let dadh_flag = (entry="dhaa#1") in 
  let conjugw person suff = (person,
      if entry="haa#1" then fix (revstem "jah") suff
      else fix3w weak iiflag dadh_flag suff) in
  enter1 entry (conjug_opt_ath_a 3 conjugw)
;
value conjug_opt_ath_m gana conjugw =
  Conju (optm gana)
   [ (Singular, 
        [ conjugw First  "iiya"
        ; conjugw Second "iithaas"
        ; conjugw Third  "iita"
        ])
   ; (Dual,
        [ conjugw First  "iivahi"
        ; conjugw Second "iiyaathaam"
        ; conjugw Third  "iiyaataam"
        ])
   ; (Plural,
        [ conjugw First  "iimahi"
        ; conjugw Second "iidhvam"
        ; conjugw Third  "iiran"
        ])
   ]
;
value compute_athematic_optative3m weak iiflag entry =
  let dadh_flag = (entry="dhaa#1") in 
  let conjugw person suff = (person,fix3w weak iiflag dadh_flag suff) in
  enter1 entry (conjug_opt_ath_m 3 conjugw)
;
value compute_athematic_imperative3a strong weak iiflag entry =
  let dadh_flag = (entry="dhaa#1") 
  and daa_flag  = (entry="daa#1") 
  and haa_flag  = (entry="haa#1") in 
  let conjugs person suff = (person,fix strong suff)
  and conjugw person suff = (person,fix3w weak iiflag dadh_flag suff)
  and conjughaa person suff = (person,fix (revstem "jahi") suff) in
  enter1 entry (Conju (impera 3)
   [ (Singular, let l = 
        [ conjugs First "aani"
        ; (Second, if daa_flag then code "dehi" (* \Pan{4,4,119} *)
                   else if dadh_flag then code "dhehi" (* idem ghu \Pan{1,1,20} *)
                   else match weak with 
            [ [ c :: _  ] -> fix3w weak iiflag dadh_flag suff 
              where suff = if vowel c then (* "dhi" or "hi" after vowel *)
                              if entry = "hu" then "dhi" else "hi" 
                            else "dhi"
            | _ -> error_empty 7
            ] ) 
        ; conjugs Third "tu"
        ] in if haa_flag then l @
                [ conjughaa Second "hi" (* jahihi *)
                ; conjugs Second   "hi" (* jahaahi *) 
                ; conjughaa Third  "tu" (* jahitu *)
                ]
             else l) 
   ; (Dual, let l = 
        [ conjugs First  "aava"
        ; conjugw Second "tam"
1481 1482
        ; if entry="bhas" then (Third, code "babdhaam") (* Whitney§678 MW§340 *) 
          else conjugw Third  "taam"
huet's avatar
huet committed
1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745
        ] in if haa_flag then l @
                [ conjughaa Second "tam"
                ; conjughaa Third  "taam"
                ]
             else l)
   ; (Plural, let l = 
        [ conjugs First  "aama"
        ; conjugw Second "ta"
        ; conjugw Third  "atu"
        ] in if haa_flag then l @ [ conjughaa Second "ta" ]
             else l)
   ])
;
value compute_imp_ath_m gana conjugs conjugw entry =
  enter1 entry (Conju (imperm gana)
   [ (Singular,
        [ conjugs First  "ai"
        ; conjugw Second "sva"
        ; conjugw Third  "taam"
        ])
   ; (Dual,
        [ conjugs First  "aavahai"
        ; conjugw Second "aathaam"
        ; conjugw Third  "aataam"
        ])
   ; (Plural,
        [ conjugs First  "aamahai"
        ; conjugw Second "dhvam"
        ; conjugw Third  "ataam"
        ])
   ])
;
value compute_athematic_imperative3m strong weak iiflag entry =
  let dadh_flag = (entry="dhaa#1") in
  let conjugs person suff = (person,fix strong suff)
  and conjugw person suff = (person,fix3w weak iiflag dadh_flag suff) in
  compute_imp_ath_m 3 conjugs conjugw entry 
;
value compute_active_present3 sstem wstem iiflag entry third = do
  { compute_athematic_present3a sstem wstem iiflag entry third
  ; compute_athematic_impft3a sstem wstem iiflag entry 
  ; compute_athematic_optative3a wstem iiflag entry 
  ; compute_athematic_imperative3a sstem wstem iiflag entry 
  } 
and compute_middle_present3 sstem wstem iiflag entry third = do 
  { compute_athematic_present3m Primary 3 wstem iiflag entry third
  ; compute_athematic_impft3m wstem iiflag entry 
  ; compute_athematic_optative3m wstem iiflag entry 
  ; compute_athematic_imperative3m sstem wstem iiflag entry 
  ; let short = if iiflag then strip_ii wstem else wstem in 
    record_part_m_ath (pprm 3) short entry
  }
;

(*** Gana 5  ***)

value compute_athematic_present5a gana strong weak vow entry third = 
  let conjugs person suff = (person,fix strong suff)
  and conjugw person suff = match code suff with
      [ [ c :: _ ] -> 
        if vowel c then 
           let w = if vow then weak else [ 45 (* v *) :: weak ] in
           (person,fix w suff)
        else (person,fix weak suff)
      | [] -> error_suffix 9
      ]
  and conjugw2 person suff = match weak with 
      [ [ 5 :: no_u ] -> (person,fix no_u suff)
      | _ -> failwith "5a weak ought to end in u"
      ] in do
  { enter1 entry (Conju (presa gana)
   [ (Singular, 
        [ conjugs First  "mi"
        ; conjugs Second "si"
        ; check entry gana third (conjugs Third "ti") 
        ])
   ; (Dual, let l = 
        [ conjugw First  "vas"
        ; conjugw Second "thas"
        ; conjugw Third  "tas"
        ]   in 
        if vow then [ conjugw2 First "vas" (* optional elision of u *) :: l ]
               else l)
   ; (Plural, let l = 
        [ conjugw First  "mas"
        ; conjugw Second "tha"
        ; conjugw Third  "anti"
        ] in
        if vow then [ conjugw2 First "mas" (* optional elision of u *) :: l ]
               else l)
   ])
  ; let m_pstem = if vow then weak else [ 45 (* v *) :: weak ] in
    let f_pstem = rfix m_pstem "at" in
    record_part (Ppra_ 5 Primary m_pstem f_pstem entry)
  }
;
value compute_athematic_present5m gana weak vow entry third = 
  let conjugw person suff = match code suff with
      [ [ c :: _ ] -> if vowel c then 
                         let w = if vow then weak else [ 45 (* v *) :: weak ] in
                         (person,fix w suff)
                      else (person,fix weak suff)
      | [] -> error_suffix 17
      ]
  and conjugw2 person suff = match weak with 
      [ [ 5 :: no_u ] -> (person,fix no_u suff)
      | _ -> failwith "5m weak ought to end in u"
      ] in 
  enter1 entry (Conju (presm gana)
   [ (Singular, 
        [ conjugw First  "e" 
        ; conjugw Second "se"
        ; check entry gana third (conjugw Third "te") 
        ])
   ; (Dual, let l = 
        [ conjugw First  "vahe"
        ; conjugw Second "aathe"
        ; conjugw Third  "aate"
        ] in
        if vow then [ conjugw2 First "vahe" (* optional elision of u *) :: l ]
        else l)
   ; (Plural, let l = 
        [ conjugw First  "mahe"
        ; conjugw Second "dhve"
        ; conjugw Third  "ate"
        ] in
        if vow then [ conjugw2 First "mahe" (* optional elision of u *) :: l ]
        else l)
   ])
;
value compute_athematic_impft5a gana strong weak vow entry = 
  let conjugs person suff = (person,fix_augment strong suff)
  and conjugw person suff = match code suff with
      [ [ c :: _ ] -> 
        if vowel c then 
           let w = if vow then weak else [ 45 (* v *) :: weak ] in
           (person,fix_augment w suff)
        else (person,fix_augment weak suff)
      | [] -> error_suffix 10
      ]
  and conjugw2 person suff = match weak with 
      [ [ 5 :: no_u ] -> (person,fix_augment no_u suff)
      | _ -> failwith "5a weak ought to end in u"
      ] in
  enter1 entry (Conju (impfta gana)
   [ (Singular,  
        [ conjugs First  "am"
        ; conjugs Second "s"
        ; conjugs Third  "t"
        ]) 
   ; (Dual, let l = 
        [ conjugw First  "va"
        ; conjugw Second "tam"
        ; conjugw Third  "taam"
        ] in
       if vow then [ conjugw2 First "va" (* optional elision of u *) :: l ]
              else l)
   ; (Plural, let l =
        [ conjugw First  "ma"
        ; conjugw Second "ta"
        ; conjugw Third  "an"
        ] in
       if vow then [ conjugw2 First "ma" (* optional elision of u *) :: l ]
       else l)
   ])
;
value compute_athematic_impft5m gana weak vow entry = 
  let conjugw person suff = match code suff with
      [ [ c :: _ ] -> 
        if vowel c then 
           let w = if vow then weak else [ 45 (* v *) :: weak ] in
           (person,fix_augment w suff)
        else (person,fix_augment weak suff)
      | [] -> error_suffix 14
      ]
  and conjugw2 person suff = match weak with 
      [ [ 5 :: no_u ] -> (person,fix_augment no_u suff)
      | _ -> failwith "5m weak ought to end in u"
      ] in
  enter1 entry (Conju (impftm gana)
   [ (Singular, 
        [ conjugw First  "i"
        ; conjugw Second "thaas"
        ; conjugw Third  "ta"
        ])
   ; (Dual, let l =
        [ conjugw First  "vahi"
        ; conjugw Second "aathaam"
        ; conjugw Third  "aataam"
        ] in
       if vow then [ conjugw2 First "vahi" (* optional elision of u *) :: l ]
       else l)
   ; (Plural, let l =
        [ conjugw First  "mahi"
        ; conjugw Second "dhvam"
        ; conjugw Third  "ata"
        ] in
       if vow then [ conjugw2 First "mahi" (* optional elision of u *) :: l ]
       else l)
   ])
;
value compute_athematic_optative5a gana weak vow entry = (* gana=5 or 8 *)
  let conjugw person suff = match code suff with
      [ [ c :: _ ] -> 
        if vowel c then 
           let w = if vow then weak else [ 45 (* v *) :: weak ] in
           (person,fix w suff)
        else (person,fix weak suff)
      | [] -> error_suffix 11
      ] in
  enter1 entry (conjug_opt_ath_a gana conjugw)
;
value compute_athematic_optative5m gana weak vow entry = (* gana=5 or 8 *)
  let conjugw person suff = match code suff with
      [ [ c :: _ ] -> 
        if vowel c then 
           let w = if vow then weak else [ 45 (* v *) :: weak ] in
           (person,fix w suff)
        else (person,fix weak suff)
      | [] -> error_suffix 19
      ] in
  enter1 entry (conjug_opt_ath_m gana conjugw)
;
value compute_athematic_imperative5a gana strong weak vow entry = (* gana=5 or 8 *)
  let conjugs person suff = (person,fix strong suff)
  and conjugw person suff = match code suff with
      [ [ c :: _ ] -> if vowel c then 
                         let w = if vow then weak else [ 45 (* v *) :: weak ] in
                         (person,fix w suff)
                      else (person,fix weak suff)
      | [] -> (person,fix weak "")
      ] in
  enter1 entry (Conju (impera gana)
   [ (Singular, 
        [ conjugs First "aani"
        ; conjugw Second (if vow then "" else "hi")
        ; conjugs Third "tu"
        ])
   ; (Dual,
        [ conjugs First  "aava"
        ; conjugw Second "tam"
        ; conjugw Third  "taam"
        ])
   ; (Plural,
        [ conjugs First  "aama"
        ; conjugw Second "ta"
        ; conjugw Third  "antu"
        ])
   ])
;
value compute_athematic_imperative5m gana strong weak vow entry = (* gana=5 or 8 *)
  let conjugs person suff = (person,fix strong suff)
  and conjugw person suff = match code suff with
      [ [ c :: _ ] -> 
        if vowel c then 
           let w = if vow then weak else [ 45 (* v *) :: weak ] in
              (person,fix w suff)
        else  (person,fix weak suff)
      | [] -> (person,fix weak "")
      ] in
  compute_imp_ath_m gana conjugs conjugw entry 
;
(* Used by classes 5 and 8 *)
1746
value compute_active_present5 gana sstem wstem vow entry third = do 
huet's avatar
huet committed
1747 1748 1749 1750 1751
  { compute_athematic_present5a gana sstem wstem vow entry third
  ; compute_athematic_impft5a gana sstem wstem vow entry 
  ; compute_athematic_optative5a gana wstem vow entry 
  ; compute_athematic_imperative5a gana sstem wstem vow entry 
  } 
1752
and compute_middle_present5 gana sstem wstem vow entry third = do 
huet's avatar
huet committed
1753 1754 1755 1756 1757 1758 1759 1760
  { compute_athematic_present5m gana wstem vow entry third
  ; compute_athematic_impft5m gana wstem vow entry 
  ; compute_athematic_optative5m gana wstem vow entry 
  ; compute_athematic_imperative5m gana sstem wstem vow entry 
  ; record_part_m_ath (pprm 5) wstem entry
  }
;
(* Also used by gana 8 *)
1761
value compute_present5 gana sstem wstem vow entry third pada padam =
huet's avatar
huet committed
1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778
  match voices_of_gana gana entry with
       [ Para -> if pada then
           compute_active_present5 gana sstem wstem vow entry third
           else emit_warning ("Unexpected middle form: " ^ entry)
       | Atma -> if padam then emit_warning ("Unexpected active form: " ^ entry)
           else compute_middle_present5 gana sstem wstem vow entry third
       | Ubha ->             
          let thirda = if pada then third else []
          and thirdm = if pada then [] else third in do
          { compute_active_present5 gana sstem wstem vow entry thirda
          ; compute_middle_present5 gana sstem wstem vow entry thirdm
          }
       ]
;

(*** Gana 7  ***)

1779
value compute_athematic_present7a strong weak entry third =
huet's avatar
huet committed
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871
  let conjugs person suff = (person,fix strong suff)
  and conjugw person suff = (person,fix weak suff) in do
  { enter1 entry (Conju (presa 7)
   [ (Singular, 
        [ conjugs First  "mi"
        ; conjugs Second "si"
        ; check entry 7 third (conjugs Third "ti") 
        ])
   ; (Dual,
        [ conjugw First  "vas"
        ; conjugw Second "thas"
        ; conjugw Third  "tas"
        ])
   ; (Plural,
        [ conjugw First  "mas"
        ; conjugw Second "tha"
        ; conjugw Third  "anti"
        ])
   ])
  ; let m_pstem = weak 
    and f_pstem = rfix weak "at" in
    record_part (Ppra_ 7 Primary m_pstem f_pstem entry) 
  }
;
value compute_athematic_present7m weak entry third = 
  let conjugw person suff = (person,fix weak suff) in
  enter1 entry (Conju (presm 7)
   [ (Singular, 
        [ conjugw First  "e" 
        ; conjugw Second "se"
        ; check entry 7 third (conjugw Third "te") 
        ])
   ; (Dual,
        [ conjugw First  "vahe"
        ; conjugw Second "aathe"
        ; conjugw Third  "aate"
        ])
   ; (Plural,
        [ conjugw First  "mahe"
        ; conjugw Second "dhve"
        ; conjugw Third  "ate"
        ])
   ])
;
value compute_athematic_impft7a strong weak entry = 
  let conjugs person suff = (person,fix_augment strong suff)
  and conjugw person suff = (person,fix_augment weak suff) in
  enter1 entry (Conju (impfta 7)
   [ (Singular, let l =
        [ conjugs First  "am"
        ; conjugs Second "s" 
        ; conjugs Third  "t"
        ] in match rev (fix_augment strong "s") with
             [ [ c :: r ] -> if c=32 (* t *) then 
                                [ (Second,rev [ 48 (* s *) :: r ]) :: l ]
                                (* abhinad-s -> abhinat or abhinas *)
                             else l (* horrible patch *)
             | _ -> error_empty 8
             ])
   ; (Dual,
        [ conjugw First  "va"
        ; conjugw Second "tam"
        ; conjugw Third  "taam"
        ])
   ; (Plural,
        [ conjugw First  "ma"
        ; conjugw Second "ta"
        ; conjugw Third  "an"
        ])
   ])
;
value compute_athematic_impft7m weak entry = 
  let conjugw person suff = (person,fix_augment weak suff) in
  enter1 entry (Conju (impftm 7)
   [ (Singular, 
        [ conjugw First  "i"
        ; conjugw Second "thaas"
        ; conjugw Third  "ta"
        ])
   ; (Dual,
        [ conjugw First  "vahi"
        ; conjugw Second "aathaam"
        ; conjugw Third  "aataam"
        ])
   ; (Plural,
        [ conjugw First  "mahi"
        ; conjugw Second "dhvam"
        ; conjugw Third  "ata"
        ])
   ])
;
value compute_athematic_optative7a weak entry =
1872 1873 1874 1875
  let glue = if entry = "hi.ms" then fun w s -> 
                List2.unstack w (code s) (* no retroflexion Whitney§183a *)
             else fix in 
  let conjugw person suff = (person,glue weak suff) in 
huet's avatar
huet committed
1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066
  enter1 entry (conjug_opt_ath_a 7 conjugw)
;
value compute_athematic_optative7m weak entry =
  let conjugw person suff = (person,fix weak suff) in
  enter1 entry (conjug_opt_ath_m 7 conjugw)
;
value compute_athematic_imperative7a strong weak entry =
  let conjugs person suff = (person,fix strong suff)
  and conjugw person suff = (person,fix weak suff) in
  enter1 entry (Conju (impera 7)
   [ (Singular, 
        [ conjugs First "aani"
        ; (Second, match weak with 
            [ [ c :: _ ] -> fix weak suff 
              where suff = if vowel c then "hi" else "dhi"
            | _ -> error_empty 9
            ]) (* "dhi" or "hi" after vowel *)
        ; conjugs Third "tu"
        ])
   ; (Dual,
        [ conjugs First  "aava"
        ; conjugw Second "tam"
        ; conjugw Third  "taam"
        ])
   ; (Plural,
        [ conjugs First  "aama"
        ; conjugw Second "ta"
        ; conjugw Third  "antu"
        ])
   ])
;
value compute_athematic_imperative7m strong weak entry =
  let conjugs person suff = (person,fix strong suff)
  and conjugw person suff = (person,fix weak suff) in
  compute_imp_ath_m 7 conjugs conjugw entry 
;
value compute_active_present7 sstem wstem entry third = do
  { compute_athematic_present7a sstem wstem entry third
  ; compute_athematic_impft7a sstem wstem entry 
  ; compute_athematic_optative7a wstem entry 
  ; compute_athematic_imperative7a sstem wstem entry 
  } 
and compute_middle_present7 sstem wstem entry third = do
  { compute_athematic_present7m wstem entry third
  ; compute_athematic_impft7m wstem entry 
  ; compute_athematic_optative7m wstem entry 
  ; compute_athematic_imperative7m sstem wstem entry 
  ; record_part_m_ath (pprm 7) wstem entry
  }
;
value compute_present7 sstem wstem entry third pada padam = 
  match voices_of_gana 7 entry with
  [ Para -> if pada then compute_active_present7 sstem wstem entry third
            else emit_warning ("Unexpected middle form: " ^ entry)
  | Atma -> if padam then emit_warning ("Unexpected active form: " ^ entry)
            else compute_middle_present7 sstem wstem entry third
  | Ubha -> let thirda = if pada then third else []
            and thirdm = if pada then [] else third in do
            { compute_active_present7 sstem wstem entry thirda
            ; compute_middle_present7 sstem wstem entry thirdm
            }
  ]
;

(*** Gana 8  ***)

(* Conjugation of k.r *)     (* "karo" "kuru" "kur" *)
value compute_athematic_presentk strong weak short entry third = 
  let conjugs person suff = (person,fix strong suff) 
  and conjugw person suff = (person,fix weak suff)
  and conjugwvm person suff = (person,fix short suff) (* -v -m suff *) in do
  { enter1 entry (Conju (presa 8)
   [ (Singular, 
        [ conjugs First  "mi"
        ; conjugs Second "si"
        ; check entry 8 third (conjugs Third "ti") 
        ])
   ; (Dual,
        [ conjugwvm First "vas"
        ; conjugw Second  "thas"
        ; conjugw Third   "tas"
        ])
   ; (Plural,
        [ conjugwvm First "mas"
        ; conjugw Second  "tha"
        ; conjugw Third   "anti"
        ])
   ])
  ; let f_pstem = rfix weak "at" in
    record_part (Ppra_ 8 Primary weak f_pstem entry) 
  ; record_part_m_ath (pprm 8) weak entry
  ; enter1 entry (Conju (presm 8)
   [ (Singular, 
        [ conjugw First  "e" 
        ; conjugw Second "se"
        ; conjugw Third  "te" 
        ])
   ; (Dual, 
        [ conjugwvm First "vahe"
        ; conjugw Second  "aathe"
        ; conjugw Third   "aate"
        ])
   ; (Plural,
        [ conjugwvm First "mahe"
        ; conjugw Second  "dhve"
        ; conjugw Third   "ate"
        ])
   ])
  }
;
value compute_athematic_impftk strong weak short entry = 
  let conjugs person suff = (person,fix_augment strong suff)
  and conjugw person suff = (person,fix_augment weak suff)
  and conjugwvm person suff = (person,fix_augment short suff) (* -v -m suff *) in do
  { enter1 entry (Conju (impfta 8)
   [ (Singular,  
        [ conjugs First  "am"
        ; conjugs Second "s"
        ; conjugs Third  "t"
        ]) 
   ; (Dual,
        [ conjugwvm First "va"
        ; conjugw Second  "tam"
        ; conjugw Third   "taam"
        ])
   ; (Plural,
        [ conjugwvm First "ma"
        ; conjugw Second  "ta"
        ; conjugw Third   "an"
        ])
   ])
  ; enter1 entry (Conju (impftm 8) (* similar to [conjugs_past_m] except for -v -m suff *)
   [ (Singular, 
        [ conjugw First  "i"
        ; conjugw Second "thaas"
        ; conjugw Third  "ta"
        ])
   ; (Dual,
        [ conjugwvm First "vahi"
        ; conjugw Second  "aathaam"
        ; conjugw Third   "aataam"
        ])
   ; (Plural, 
        [ conjugwvm First "mahi"
        ; conjugw Second  "dhvam"
        ; conjugw Third   "ata"
        ])
   ])
  }
;
value compute_athematic_optativek weak short entry =
  let conjugw person suff = (person,fix weak suff)
  and conjugs person suff = (person,fix short suff) in do
  { enter1 entry (conjug_opt_ath_a 8 conjugs) (* short since -y suffixes *)
  ; enter1 entry (conjug_opt_ath_m 8 conjugw)
  }
;
value compute_athematic_imperativek strong weak entry =
  let conjugs person suff = (person,fix strong suff)
  and conjugw person suff = (person,fix weak suff) in do
  { enter1 entry (Conju (impera 8)
   [ (Singular, 
        [ conjugs First  "aani"
        ; conjugw Second ""
        ; conjugs Third  "tu"
        ])
   ; (Dual,
        [ conjugs First  "aava"
        ; conjugw Second "tam"
        ; conjugw Third  "taam"
        ])
   ; (Plural,
        [ conjugs First  "aama" (* also kurma Epics *)
        ; conjugw Second "ta"
        ; conjugw Third  "antu"
        ])
   ])
  ; compute_imp_ath_m 8 conjugs conjugw entry 
  }
;
value compute_presentk sstem wstem short entry third = do
  { compute_athematic_presentk sstem wstem short entry third
  ; compute_athematic_impftk sstem wstem short entry 
  ; compute_athematic_optativek wstem short entry 
  ; compute_athematic_imperativek sstem wstem entry 
  }
;

(*** Gana 9  ***)

value compute_athematic_present9a strong weak short entry third = 
2067
  let conjugs person suff = (person,fix strong suff) 
huet's avatar
huet committed
2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331
  and conjugw_v person suff = (person,fix short suff) (* vowel suffix *)
  and conjugw_c person suff = (person,fix weak suff) (* consonant suffix *) in do
  { enter1 entry (Conju (presa 9)
   [ (Singular, 
        [ conjugs First  "mi"
        ; conjugs Second "si"
        ; check entry 9 third (conjugs Third "ti") 
        ])
   ; (Dual,
        [ conjugw_c First  "vas"
        ; conjugw_c Second "thas"
        ; conjugw_c Third  "tas"
        ])
   ; (Plural,
        [ conjugw_c First  "mas"
        ; conjugw_c Second "tha"
        ; conjugw_v Third  "anti"
        ])
   ])
  ; let f_pstem = rfix short "at" in
    record_part (Ppra_ 9 Primary short f_pstem entry) (* follows 3rd pl *) 
  }
;
value compute_athematic_present9m weak short entry third = 
  let conjugw person suff = match code suff with
      [ [ c :: _ ] -> let w = if vowel c then short else weak in
                      (person,fix w suff)
      | [] -> error_suffix 16
      ] in
  enter1 entry (Conju (presm 9)
   [ (Singular, 
        [ conjugw First  "e" 
        ; conjugw Second "se"
        ; check entry 9 third (conjugw Third "te") 
        ])
   ; (Dual,
        [ conjugw First  "vahe"
        ; conjugw Second "aathe"
        ; conjugw Third  "aate"
        ])
   ; (Plural,
        [ conjugw First  "mahe"
        ; conjugw Second "dhve"
        ; conjugw Third  "ate"
        ])
   ])
;
value compute_athematic_impft9a strong weak short entry = 
  let conjugs person suff = (person,fix_augment strong suff)
  and conjugw person suff = match code suff with
      [ [ c :: _ ] -> let w = if vowel c then short else weak in
                      (person,fix_augment w suff)
      | [] -> error_suffix 6
      ] in
  enter1 entry (Conju (impfta 9)
   [ (Singular,  
        [ conjugs First  "am"
        ; conjugs Second "s"
        ; conjugs Third  "t"
        ]) 
   ; (Dual,
        [ conjugw First  "va"
        ; conjugw Second "tam"
        ; conjugw Third  "taam"
        ])
   ; (Plural, 
        [ conjugw First  "ma"
        ; conjugw Second "ta"
        ; conjugw Third  "an"
        ])
   ])
;
value compute_athematic_impft9m weak short entry = 
  let conjugw person suff = match code suff with
      [ [ c :: _ ] -> let w = if vowel c then short else weak in
                      (person,fix_augment w suff)
      | [] -> error_suffix 13
      ] in
  enter1 entry (conjug_impft_m 9 conjugw)
;
value compute_athematic_optative9a weak short entry =
  let conjugw person suff = match code suff with
      [ [ c :: _ ] -> let w = if vowel c then short else weak in (* tjs y- *)
                      (person,fix w suff)
      | [] -> error_suffix 14
      ] in
  enter1 entry (conjug_opt_ath_a 9 conjugw)
;
value compute_athematic_optative9m short entry =
  let conjugw person suff = (person,fix short suff) in (* suff starts with ii *)
  enter1 entry (conjug_opt_ath_m 9 conjugw) 
;
value compute_athematic_imperative9a strong weak short vow root entry =
  let conjugs person suff = (person,fix strong suff)
  and conjugw person suff = match code suff with
      [ [ c :: _ ] -> let w = if vowel c then short else weak in
                      (person,fix w suff)
      | [] -> (person,fix weak "")
      ] 
  and conjugw2 person suff = (person,fix root suff) in
  enter1 entry (Conju (impera 9)
   [ (Singular, 
        [ conjugs First  "aani"
        ; if vow then conjugw Second "hi"
          else conjugw2  Second "aana" (* no nii suffix for consonant root *)
        ; conjugs Third "tu"
        ])
   ; (Dual,
        [ conjugs First  "aava"
        ; conjugw Second "tam"
        ; conjugw Third  "taam"
        ])
   ; (Plural,
        [ conjugs First  "aama"
        ; conjugw Second "ta"
        ; conjugw Third  "antu"
        ])
   ])
;
value compute_athematic_imperative9m strong weak short root entry =
  let conjugs person suff = (person,fix strong suff)
  and conjugw person suff = match code suff with
      [ [ c :: _ ] -> let w = if vowel c then short else weak in
                      (person,fix w suff)
      | [] -> (person,fix weak "")
      ] in
  compute_imp_ath_m 9 conjugs conjugw entry 
;
value compute_active_present9 sstem wstem short vow stem entry third = do
  { compute_athematic_present9a sstem wstem short entry third
  ; compute_athematic_impft9a sstem wstem short entry 
  ; compute_athematic_optative9a wstem short entry 
  ; compute_athematic_imperative9a sstem wstem short vow stem entry 
  } 
and compute_middle_present9 sstem wstem short stem entry third = do
  { compute_athematic_present9m wstem short entry third
  ; compute_athematic_impft9m wstem short entry 
  ; compute_athematic_optative9m short entry 
  ; compute_athematic_imperative9m sstem wstem short stem entry 
  ; record_part_m_ath (pprm 9) short entry (* short and not wstem *)
  }
;
value compute_present9 sstem wstem short vow stem entry third pada padam = 
  match voices_of_gana 9 entry with
  [ Para -> if pada then 
               compute_active_present9 sstem wstem short vow stem entry third
            else emit_warning ("Unexpected middle form: " ^ entry)
  | Atma -> if padam then emit_warning ("Unexpected active form: " ^ entry)
            else compute_middle_present9 sstem wstem short stem entry third
  | Ubha -> let thirda = if pada then third else []
            and thirdm = if pada then [] else third in do
            { compute_active_present9 sstem wstem short vow stem entry thirda
            ; compute_middle_present9 sstem wstem short stem entry thirdm
            }
  ]
;

(* Benedictive/precative. Formed from [conjug_optativea] *)
value conjug_benedictivea conj weak entry =
  let conjugw person suff = (person,fix weak suff) in
  enter1 entry 
  (Conju (fbenea conj)
   [ (Singular, 
        [ conjugw First  "yaasam"
        ; conjugw Second "yaas" (* ambig opt *)
        ; conjugw Third  "yaat" (* ambig opt *)
        ])
   ; (Dual,
        [ conjugw First  "yaasva"
        ; conjugw Second "yaastam"
        ; conjugw Third  "yaastaam"
        ])
   ; (Plural,
        [ conjugw First  "yaasma"
        ; conjugw Second "yaasta"
        ; conjugw Third  "yaasur"
        ])
   ])
;
value conjug_benedictivem conj sibstem entry =
  let conjug person suff = (person,fix sibstem suff) in
  enter1 entry 
  (Conju (fbenem conj)
   [ (Singular, 
        [ (* conjugw First "iiya" - ambig opt *)
          conjug Second "ii.s.thaas" 
        ; conjug Third  "ii.s.ta"  
        ])
   ; (Dual, 
        [ (* conjugw First "iivahi" - ambig opt *)
          conjug Second "iiyaasthaam"
          (* conjug Third  "iiyaastaam" *)
        ])
   ; (Plural, 
        [ (* conjugw First "iimahi" - ambig opt *)
          conjug Second "ii.dhvam"
          (* conjugw Third "iiran" - ambig opt *)
        ]) 
   ]) 
;
(*****************)
(* Future system *)
(*****************)

(* Similar to [compute_thematic_paradigm_act] *)
value compute_futurea conj stem entry = 
  let conjug person suff = (person,fix stem suff) in do
  { enter1 entry (Conju (ffutura conj)
   [ (Singular, 
        [ conjug First  "aami"
        ; conjug Second "asi"
        ; conjug Third  "ati" 
        ])
   ; (Dual,
        [ conjug First  "aavas"
        ; conjug Second "athas"
        ; conjug Third  "atas"
        ])
   ; (Plural,
        [ conjug First  "aamas"
        ; conjug Second "atha"
        ; conjug Third  "anti"
        ])
   ])
  ; record_part (Pfuta_ conj stem entry) 
  }
;
value compute_futurem conj stem entry = 
  let conjug person suff = (person,fix stem suff) in do
  { enter1 entry (Conju (ffuturm conj)
   [ (Singular, 
        [ conjug First  "e"
        ; conjug Second "ase"
        ; conjug Third  "ate"
        ])
   ; (Dual,
        [ conjug First  "aavahe"
        ; conjug Second "ethe"
        ; conjug Third  "ete"
        ])
   ; (Plural,
        [ conjug First  "aamahe"
        ; conjug Second "adhve"
        ; conjug Third  "ante"
        ])
   ])
  ; record_part_m_th pfutm stem entry
  }
;
(* Conditional - preterit of future, built from imperfect on future stem   *)
(* where non-performance of the action is implied - pluperfect conditional *)
(* used in antecedent as well as in consequent clause - Apte§216           *)
(* "si vous étiez venu, vous l'auriez vue" *)
value compute_conda conj stem entry = 
  let conjug person suff = (person,fix_augment stem suff) in 
  enter1 entry (Conju (fconda conj) (thematic_preterit_a conjug))
;
value compute_condm conj stem entry = 
  let conjug person suff = (person,fix_augment stem suff) in
  enter1 entry (Conju (fcondm conj) (thematic_preterit_m conjug))
;
value compute_future stem entry = 
  match entry with
    [ "as#1" -> () (* uses bhuu *) 
2332 2333
    | "iiz#1" | "lii" | "knuu" -> do (* Para allowed in future *)
         { compute_futurea Primary stem entry  
huet's avatar
huet committed
2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362
         ; compute_futurem Primary stem entry  
         }
    | _ -> match voices_of entry with
       [ Para -> do (* active only *) 
         { compute_futurea Primary stem entry 
         ; match entry with (* conditional on demand *)
           [ "gam" | "bhuu#1" -> compute_conda Primary stem entry
           | _ -> ()
           ]
         }
       | Atma -> (* middle only *) 
         compute_futurem Primary stem entry 
       | (* both *) _ -> do
         { compute_futurea Primary stem entry 
         ; compute_futurem Primary stem entry 
         ; match entry with (* rare conditional *)
           [ "i" | "k.r#1" | "tap" | "daa#1" -> do
              { compute_conda Primary stem entry 
              ; compute_condm Primary stem entry 
              }
           | _ -> ()
           ]
         }
       ]
    ]
;
value compute_future_ca stem entry = do
  { compute_futurea Causative stem entry 
  ; compute_futurem Causative stem entry 
2363 2364 2365 2366 2367 2368 2369
  ; match entry with (* rare conditional *)
    [ "j~naa#1" -> do
       { compute_conda Primary stem entry 
       ; compute_condm Primary stem entry 
       }
    | _ -> ()
    ]
huet's avatar
huet committed
2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393
  ; record_part_m_th pcausfm stem entry
  }
;
(* Possible intercalating vowel i for se.t and ve.t roots Whitney§935 *)
(* [intercalates] returns a set of possible intercalations.           *)
(* This information should be lexicalised with a generative lexicon.  *)
value intercalates root = 
  let anit = [ 0 ]    (* no intercalation *) 
  and set  = [ 1 ]    (* intercalate i *)
  and vet  = [ 0; 1 ] (* intercalate i optionally *)
      (* NB for likh and vij 0 means intercalate i on weak stem *)
  and setl = [ 2 ]    (* intercalate ii *)
  and serb = [ 1; 2 ] (* intercalate i or ii *) in fun (* rstem *)
   [ [] -> error_empty 10
   | [ 7; 45 (* v.r *) ] -> serb (* [v.r#1] and [v.r#2] *)
   | [ 7 (* -.r *) :: _ ] -> set
   | [ 8 (* -.rr *) :: _ ] -> serb
   | [ 6; 48 (* [suu#1] *) ] -> vet
   | [ 6 (* -uu *) :: _ ] -> set (* Kale p. 186 *)
   | [ c :: r ] -> 
       if vowel c then 
          if all_consonants r then 
             match root with
             [ "k.sii" | "ji" | "nii#1" | "vaa#3" | "zii#1" | "su#2" 
2394
             | "stu" | "sru" | "haa#1" -> vet
huet's avatar
huet committed
2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413
             | ".dii" | "nu#1" | "yu#1" | "yu#2" | "ru" | "zri" 
             | "k.su" | "k.s.nu" | "snu" (* Kale *) | "zuu"
                 -> set
             | _ -> anit 
             ] 
          else set 
       else if semivowel c then set
       else match root with
            [ "ak.s" | "a~nj" | "k.rt#1" | "k.rp" | "k.lp" | "kram" | "k.sam" 
            | "klid" | "gup" | "guh" | "ghu.s" | "jan" | "ta~nc" | "tap" | "t.rd"
            | "tyaj#1" | "dah#1" | "d.rp" | "nam" | "naz" | "n.rt" | "bandh" 
            | "bhaj" | "majj" | "man" | "m.rj" | "yam" | "ruh" | "labh" | "likh"
            | "vap#2" | "vas#1" | "vah#1" | "vij" | "vid#1" | "v.rj" | "v.rt#1" 
            | "vrazc" | "sad#1" | "sah#1" | "sidh#2" | "svap" | "han#1" 
            | "syand"  (* WR says set for atma, anit for para  *)
                -> vet  
            | "grah" -> setl
            | "s.rj#1" -> [ 3 ] (* sra.s.taa *)
            | "k.r.s" -> [ 3 :: vet ] (* ar -> ra optionally *)
2414
            | "bh.rjj" | "sp.rz#1" -> [ 3 :: anit ] (* idem *)
huet's avatar
huet committed
2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425
            | "ad#1" | "aap" | "krudh#1" | "kruz" | "k.sip" | "k.sud" 
            | "k.sudh#1" | "khid" | "chid#1" | "tud#1" | "tu.s" | "t.rp#1"
            | "tvi.s#1" | "diz#1" | "dih" | "du.s" | "duh#1" | "d.rz#1" 
            | "dvi.s#1" | "nah" | "nij" | "nud" | "pac" | "pad#1" | "pi.s" 
            | "pu.s#1" | "praz" | "budh#1" | "bha~nj" | "bha.s" | "bhid#1"
            | "bhuj#1" | "bhuj#2" | "mih" | "muc#1" | "m.rz" | "yaj#1" | "yabh" 
            | "yuj#1" | "yudh#1" | "ra~nj" | "rabh" | "ram" | "raadh" | "ric"
            | "ruj#1" | "rudh#1" | "rudh#2" | "ruh#1" | "lip" | "liz" | "lih#1"
            | "lup" | "vac" | "vap#1" | "vic" | "vid#2" | "viz#1" | "vi.s#1" 
            | "vyadh" | "zak" | "zad" | "zap" | "zi.s" | "zudh" | "zu.s" 
            | "zli.s" | "sa~nj" | "sic" | "sidh#1" | "s.rp" | "skand" 
2426
            | "sva~nj" | "svid#2" | "had"