phases.ml 5.44 KB
Newer Older
huet's avatar
huet committed
1 2 3 4 5 6
(**************************************************************************)
(*                                                                        *)
(*                     The Sanskrit Heritage Platform                     *)
(*                                                                        *)
(*                              Gérard Huet                               *)
(*                                                                        *)
7
(* ©2019 Institut National de Recherche en Informatique et en Automatique *)
huet's avatar
huet committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
(**************************************************************************)

module Phases = struct 
(* Lexical sorts as phases, i.e. states of the modular transducer *)
type phase = 
  [ Noun | Noun2
  | Pron 
  | Root 
  | Inde (* indeclinable forms *)
  | Absv (* vowel-initial abs-tvaa *) 
  | Absc (* consonant-initial abs-tvaa *) 
  | Abso (* abs in -ya *)
  | Voca 
  | Inv 
  | Iic | Iic2 
  | Iiif (* iic of ifc, atteinable from previous iic eg -vartin iic -varti- *)
  | Iiv | Iivv | Iivc (* inchoatives - cvi verbal compounds *)
  | Auxi | Auxik | Auxiick 
  | Ifc | Ifc2 
  | Peri (* periphrastic perfect *)
  | Lopa (* e/o conjugated root forms with lopa *) 
  | Lopak (* e/o kridantas forms with lopa *) 
  | Pv (* Preverb optional before Root or Lopa or mandatory before Abso *)
  | Pvk | Pvkc | Pvkv (* Preverb optional before Krid or Iik or Lopak *) 
  | A | An (* privative nan-compounds *)
  | Ai | Ani (* initial privative nan-compounds *)
  | Iicv | Iicc (* split of Iic by first letter resp. vowel or consonant *)
  | Nouv | Nouc (* idem for Noun *)
  | Krid (* Kridantas eg participles *) 
  | Vok (* Kridanta vocatives *)  
  | Iik (* Kridanta iics *)
  | Iikv | Iikc | Kriv | Kric | Vocv | Vocc | Vokv | Vokc
  | Iiy | Avy (* Avyayiibhaavas *)
41 42
  | Inftu | Kama (* vaktukaama cpds *) 
  | Cache   (* Lexicon acquisition *) 
huet's avatar
huet committed
43 44
  | Unknown (* Unrecognized chunk *)
  (* now pseudo phase tagging root/kridanta forms with preverbs *)
45
  | Comp of tag and (* pv *) Word.word and (* root/krid in tag *) Word.word 
huet's avatar
huet committed
46 47
  ] 
and tag = (phase * phase) (* preverb phase and root/taddhita phase *)
48
(* NB. It is essential to keep both phases to identify transition checkpoints *)
huet's avatar
huet committed
49
and phases = list phase
50
(* NB. In Simplified mode, we use only 10 phases:
huet's avatar
huet committed
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
   [[ Noun2; Pron; Iic2; Ifc2; Root; Inde; Pv; Iiv; Abso; Lopa ]] *)
;
(* Marshalling for cgi invocations *)
value rec string_of_phase = fun 
  [ Noun  -> "Noun"
  | Noun2 -> "Noun2" 
  | Pron  -> "Pron"
  | Root  -> "Root" 
  | Inde  -> "Inde"
  | Absv  -> "Absv" 
  | Absc  -> "Absc" 
  | Abso  -> "Abso" 
  | Voca  -> "Voca"
  | Inv   -> "Inv" 
  | Iic   -> "Iic"
  | Iic2  -> "Iic2" 
  | Iiif  -> "Iiif"
  | Iiv   -> "Iiv"
  | Iivv  -> "Iivv"
  | Iivc  -> "Iivc"
  | Auxi  -> "Auxi" 
  | Auxik -> "Auxik" 
  | Auxiick -> "Auxiick" 
  | Ifc   -> "Ifc"
  | Ifc2  -> "Ifc2" 
  | Lopa  -> "Lopa"
  | Lopak -> "Lopak"
  | Pv    -> "Pv" 
  | Pvk   -> "Pvk"
  | Pvkc  -> "Pvkc" 
  | Pvkv  -> "Pvkv"
  | A     -> "A"
  | An    -> "An" 
  | Ai    -> "Ai"
  | Ani   -> "Ani" 
  | Iicv  -> "Iicv"
  | Iicc  -> "Iicc" 
  | Nouv  -> "Nouv"
  | Nouc  -> "Nouc"  
  | Krid  -> "Krid"
  | Vok   -> "Vok" 
  | Vokv  -> "Vokv" 
  | Vokc  -> "Vokc" 
  | Iik   -> "Iik"
  | Iikv  -> "Iikv" 
  | Iikc  -> "Iikc"
  | Iiy   -> "Iiy" 
  | Avy   -> "Avya" 
  | Kriv  -> "Kriv"
  | Kric  -> "Kric" 
  | Vocv  -> "Vocv" 
  | Vocc  -> "Vocc"
  | Peri  -> "Peri"
  | Inftu -> "Inftu"
105 106
  | Kama  -> "Kama" 
  | Cache -> "Cache" 
huet's avatar
huet committed
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
  | Unknown -> "Unknown"
  | _ -> failwith "string_of_phase"
  ] 
and phase_of_string = fun (* unsafe *)  
  [ "Noun"  -> Noun
  | "Noun2" -> Noun2 
  | "Pron"  -> Pron
  | "Root"  -> Root
  | "Inde"  -> Inde
  | "Abso"  -> Abso
  | "Absv"  -> Absv
  | "Absc"  -> Absc
  | "Voca"  -> Voca
  | "Inv"   -> Inv
  | "Iic"   -> Iic
  | "Iic2"  -> Iic2
  | "Iiif"  -> Iiif
  | "Iiv"   -> Iiv
  | "Iivv"  -> Iivv
  | "Iivc"  -> Iivc
  | "Auxi"  -> Auxi
  | "Auxik" -> Auxik 
  | "Auxiick" -> Auxiick
  | "Ifc"   -> Ifc
  | "Ifc2"  -> Ifc2
  | "Lopa"  -> Lopa
  | "Lopak" -> Lopak
  | "Pv"    -> Pv
  | "Pvk"   -> Pvk
  | "Pvkc"  -> Pvkc
  | "Pvkv"  -> Pvkv
  | "A"     -> A
  | "An"    -> An
  | "Ai"    -> Ai
  | "Ani"   -> Ani
  | "Iicv"  -> Iicv
  | "Iicc"  -> Iicc
  | "Nouv"  -> Nouv
  | "Nouc"  -> Nouc
  | "Krid"  -> Krid
  | "Vokv"  -> Vokv
  | "Vokc"  -> Vokc
  | "Iik"   -> Iik
  | "Iikv"  -> Iikv
  | "Iikc"  -> Iikc
  | "Iiy"   -> Iiy
  | "Avya"  -> Avy
  | "Kriv"  -> Kriv
  | "Kric"  -> Kric
  | "Vocv"  -> Vocv
  | "Vocc"  -> Vocc
158
  | "Peri"  -> Peri 
huet's avatar
huet committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
  | "Inftu" -> Inftu
  | "Kama"  -> Kama
  | "Unknown" -> Unknown
  | "Cache" -> Cache
  | s -> failwith ("Unknown phase " ^ s)
  ]
;
value unknown = Unknown
and aa_phase = fun (* phase of preverb "aa" according to following phase *)
    [ Root | Abso | Peri -> Pv | _ -> Pvkv ]
and un_lopa = fun (* phase of origin of lopa *)
    [ Lopa -> Root | Lopak -> Kriv | _ -> failwith "un_lopa" ] 
and preverb_phase = fun 
    [ Pv | Pvk | Pvkc | Pvkv -> True | _ -> False ]
and krid_phase = fun [ Krid | Kric | Kriv -> True | _ -> False ]
and ikrid_phase = fun [ Iik | Iikc | Iikv -> True | _ -> False ]
and vkrid_phase = fun [ Vokc | Vokv -> True | _ -> False ]
176
and ii_phase = fun [ Iicv | Iicc | Iikv | Iikc | A | An -> True | _ -> False ]
huet's avatar
huet committed
177 178 179 180 181 182 183 184 185
and is_cache phase = (phase = Cache)
;
(* Needed as argument of [Morpho.print_inv_morpho] *)
value rec generative = fun
  [ Krid | Kriv | Kric | Vokv | Vokc | Iik | Iikv | Iikc | Auxik -> True
  | Comp (_,ph) _ _ -> generative ph
  | _ -> False
  ]
;
186

huet's avatar
huet committed
187
end; (* Phases *)