paraphrase.ml 8.54 KB
Newer Older
huet's avatar
huet committed
1 2 3 4 5 6
(**************************************************************************)
(*                                                                        *)
(*                     The Sanskrit Heritage Platform                     *)
(*                                                                        *)
(*                              Gérard Huet                               *)
(*                                                                        *)
7
(* ©2018 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 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
(**************************************************************************)

(* English paraphrase of semantic analysis *)
(* Deprecated *)

(*i module Paraphrase = struct i*)

open Skt_morph;
open Constraints; (* [val_of_voice regime root_regime] *)
open Html; 
open Web; (* ps pl etc. *)
open Morphology; (* [inflexions] *)

value imperative_paraphrase pers num =
  match pers with
  [ First -> match num with 
        [ Singular -> "Let me "
        | Dual     -> "Let us two "
        | Plural   -> "Let us "
        ] 
  | Second -> match num with 
        [ Singular -> "Thou "
        | Dual     -> "You two "
        | Plural   -> "You "
        ] 
  | Third -> match num with 
        [ Singular -> "Let it "
        | Dual     -> "Let them two "
        | Plural   -> "Let them "
        ] 
  ]
;
value subject_paraphrase pers num =
  match pers with
  [ First -> match num with 
        [ Singular -> "I "
        | Dual     -> "Both of us "
        | Plural   -> "We "
        ] 
  | Second -> match num with 
        [ Singular -> "Thou "
        | Dual     -> "Both of you "
        | Plural   -> "You "
        ] 
  | Third -> match num with 
        [ Singular -> "It "
        | Dual     -> "Both of them "
        | Plural   -> "All of them "
        ] 
  ]
;
exception Unknown
;
value reg_stem = fun (* regular english verbs paraphrase *)
  [ "k.lp"    -> "effect"
  | "krii.d"  -> "play"
  | "tan#1"   -> "stretch"
  | "tap"     -> "suffer"
  | "tyaj"    -> "abandon"
  | "dhaav#2" -> "clean"
  | "nind"    -> "blame"
  | "pac"     -> "cook"
  | "pa.th"   -> "learn"
  | "paa#2"   -> "protect"
  | "pi#2"    -> "increase"
  | "praz"    -> "ask"
74
  | "bhaa.s"  -> "talk"
huet's avatar
huet committed
75 76 77 78 79 80 81 82 83
  | "tarj" 
  | "bharts"  -> "threaten"
  | "bruu"    -> "say"
  | "bhii#1"  -> "fear"
  | "ruc#1"   -> "please"
  | "labh"    -> "obtain"
  | "lal"     -> "fondle"
  | "v.rt#1"  -> "exist"
  | "v.r.s"   -> "rain"
84
  | "zubh#1"  -> "shine"
huet's avatar
huet committed
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 184 185 186 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
  | "sp.rz#1" -> "touch"
  | "svid#2"  -> "sweat"
  | _ -> raise Unknown
  ]
;
value paraphrase = fun (* returns pair (present stem, past participle) *)
  [ "at" | "i" | "gam" | "gaa#1" | "car" -> ("go","gone") (* irregular verbs *)
  | "as#1"    -> ("i","")
  | "aas#2" 
  | "viz#1"   -> ("sit","seated")
  | "kath"    -> ("tell","told")
  | "j~naa#1" -> ("know","known")
  | "ta.d"    -> ("beat","beaten")
  | "daa#1"   -> ("give","given")
  | "dhaav#1" -> ("run","chased")
  | "dh.r"    -> ("hold","held")
  | "nii#1"   -> ("lead","led")
  | "paz"     -> ("see","seen")
  | "paa#1"   -> ("drink","drunk")
  | "bhuj#2"  -> ("eat","eaten")
  | "bhuu#1"  -> ("become","become")
  | "m.r"     -> ("die","dead")
  | "likh"    -> ("write","written")
  | "vac"     -> ("speak","spoken")
  | "vah#1"   -> ("carry","carried")
  | "vid#1"   -> ("know","known")
  | "vid#2"   -> ("find","found")
  | "v.rdh#1" -> ("grow","grown")
  | "vyadh" 
  | "han"     -> ("hit","hurt")
  | "zru"     -> ("hear","heard")
  | "suu#1"   -> ("impel","impelled")
  | "sthaa#1" -> ("stand","stood")
  | "svap"    -> ("sleep","asleep")
  | e -> try let regular = reg_stem e in
             (regular, regular ^ "ed")
         with [ Unknown -> ("do","done") (* default *) ]
  ]
;
value print_gender = fun 
  [ Mas -> ps "[M]"
  | Neu -> ps "[N]"
  | Fem -> ps "[F]" 
  | Deictic d -> match d with
     [ Speaker  -> ps "[Speaker]"  (* First person *)
     | Listener -> ps "[Listener]" (* Second person *)
     | Self     -> ps "[Self]"     (* reflexive subject *)
     | Numeral  -> ps "[Num]"      (* number *)
     ]
  ]
and print_number = fun
    [ Singular -> () | Dual -> ps "(2)" | Plural -> ps "s" ]
and print_case = fun 
    [ Nom -> ps "Subject" (* Actor/Agent *)
    | Acc -> ps "Object"  (* Goal *)
    | Voc -> ps "O"       (* Invocation *)
    | Ins -> ps "by"      (* Agent/Instrument *)
    | Dat -> ps "to"      (* Destination *)
    | Abl -> ps "from"    (* Origin *)
    | Gen -> ps "of"      (* Possessor *)
    | Loc -> ps "in"      (* Circumstance *)
    ]
and print_person = fun  
    [ First  -> ps "I" 
    | Second -> ps "You" 
    | Third  -> ()
    ]
  ;
value genitive = fun 
    [ Singular -> "'s" 
    | Dual     -> " pair's"
    | Plural   -> "s'"
    ]
;
value print_noun c n g = 
  match c with 
  [ Nom | Acc | Voc -> do (* direct *)
      { print_case c
      ; print_number n
      ; sp ()
      ; print_gender g
      }
  | Gen -> do 
      { print_gender g
      ; ps (genitive n) 
      }
  | _ -> do (* oblique *)
      { print_case c
      ; sp ()
      ; print_gender g
      ; print_number n
      }
  ]
          ;
value third_sg act = 
  if act = "do" || act = "go" then "es" else "s"
;
value print_role = fun 
  [ Subject _ _ -> ps "Subject" (* Actor/Agent *)
  | Object      -> ps "Object"  (* Goal/Patient *)
  | Instrument  -> ps "Agent"   (* Agent/Instrument *)
  | _ -> () 
  ]
;
value copula n = fun
  [ First  -> if n=Singular then "am" else "are"
  | Second -> "are"
  | Third  -> if n=Singular then "is" else "are"
  ]
;
value print_verb w f n p = 
  let (aspect,demand,_) = regime w f 
  and (act,pas) = paraphrase w in 
  match aspect with
  [ Imperfectif -> do 
     { ps (subject_paraphrase p n)
     ; if w = "as#1" then ps (copula n p)
       else do 
          { if act = "carry" then ps "carrie" else ps act
          ; match p with
            [ First | Second -> ()
            | Third -> if n=Singular then ps (third_sg act) else ()
            ]
          }
     ; ps " "
     ; List.iter print_role demand
     }  
  | Perfectif -> do
     { ps (subject_paraphrase p n)
     ; ps (copula n p)
     ; ps " "
     ; ps pas
     }
  | Impersonal -> do
     { ps act
     ; ps (third_sg act)
     }
  | Statif -> do
    { ps "It "
    ; ps act
    ; ps (third_sg act)
    }
  ]
;
value print_abs entry =  
  match root_regime entry with 
  [ Intransitive | Factitive -> ()
  | _ ->  ps "Object"
  ] (* conjugation [c] ignored at this stage *)
;
(* Translation Sanskrit -> English of tool words *)
value translate_tool = fun
  [ "ca"     -> "and"
  | "vaa"    -> "or"
  | "saha"   -> "with"
  | "iva"    -> "indeed"
  | "iti"    -> "even"
  | "eva"    -> "so"
  | "naaman" -> "by name"
  | "yathaa" -> "if"
  | "tathaa" -> "then"
  | x -> x (* keep stem *)
  ]
;
value print_verbal _ = ps "(Participial) " (* TODO *)
;
(* Adapted from [Morpho.print_morph] with extra string argument [w] for lexeme.
   Called from [Parser.print_roles]. *)
value print_sem w = fun
  [ Noun_form g n c -> print_noun c n g
  | Part_form v g n c -> do { print_verbal v; print_noun c n g }
  | Verb_form f n p -> print_verb w f n p
257 258 259
  | Abs_root _ | Ind_form Abs -> print_abs w 
  | Ind_form Adv -> ps "Adverb"
  | Ind_form _ -> ps (translate_tool w)
huet's avatar
huet committed
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 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
  | Bare_stem -> ps "Compound"
  | Auxi_form -> ps "Composed"
  | _ -> ()
  ]
;
value subj_of p n = match p with 
  [ First  -> match n with 
              [ Singular -> "I" | Dual -> "Us two" | Plural -> "Us" ]
  | Second -> match n with 
              [ Singular -> "Thou" | Dual -> "You two" | Plural -> "You" ]
  | Third  -> match n with 
              [ Singular -> "It" | Dual -> "Both" | Plural -> "They" ]
  ]
;
value print_noun_role = fun
  [ Subject p n  -> ps (subj_of p n)
  | Object       -> ps "Obj"
  | Instrument   -> ps "Agt"
  | Destination  -> ps "Dst"
  | Origin       -> ps "Org"
  | Possessor    -> ps "Pos" 
  | Circumstance -> ps "Cir"
  ]
;
value print_neg_noun_role k = do
  { ps "-"; print_noun_role k; ps " " }
;
value print_role ((seg,sub,ind),role) = do 
  { ps (html_red (string_of_int seg ^ "." ^ string_of_int sub
                  ^ "." ^ string_of_int ind))
  ; ps (html_green " [")
  ; ps (span_begin Latin12) 
  ; match role with
    [ Process noun_roles _
    | Subprocess noun_roles -> List.iter print_neg_noun_role noun_roles
    | Actor noun_role gender number -> do 
        { print_noun_role noun_role
        ; match noun_role with [ Subject _ _ -> () | _ -> print_number number ]
        ; print_gender gender
        }
    | Tool Coordination -> ps " & "
    | Tool _ -> ps " T "
    | Number _ _ _ -> ps " N "
    | Addressee -> ps " V "
    | Compound -> ps " C "
    | Ignored -> ps " _ "
    ]
  ; ps span_end 
  ; ps (html_green "] ")
  }
;
(*i end; i*)