scl_parser.ml 2.44 KB
Newer Older
1 2 3 4 5 6
(**************************************************************************)
(*                                                                        *)
(*                     The Sanskrit Heritage Platform                     *)
(*                                                                        *)
(*                      Gérard Huet & Amba Kulkarni                       *)
(*                                                                        *)
7
(* ©2018 Institut National de Recherche en Informatique et en Automatique *)
8 9
(**************************************************************************)

10
(* Module [Scl_parser] used as interface with UoH dependency parser *)
11 12 13 14 15 16

open Html; 
open Web; (* ps pl etc. *)
open Morphology; (* inflected lemma morphology *)
open Phases; (* Phases *)
open Dispatcher; (* Dispatch *)
17
open SCLpaths; (* [scl_url scl_cgi default_output_font] *) 
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36


module Prel = struct  
 value prelude () = Web.reader_prelude Web.reader_title;
 end (* Prel *)
;
(* Global parameters of the lexer *)
value iterate = ref True (* by default a chunk is a list of words *)
and complete  = ref True (* by default we call the fuller segmenter *)
and output_channel = ref stdout (* by default cgi output on standard output *)
;
module Lexer_control = struct
 value star = iterate;
 value full = complete;
 value out_chan = output_channel
; 
end (* [Lexer_control] *)
;
(* Multi-phase lexer *)
37
module Lex = Lexer.Lexer Prel Lexer_control (* [print_scl_segment] *)
38 39
;
value print_scl_output output = 
40
  List.fold_left Lex.print_scl_segment 1 (List.rev output) 
41 42
;
value print_scl_solutions s =
43
  let _ = print_scl_output s in ()
44 45 46 47 48 49 50 51 52 53
;
(* Invocation of UoH's CSL parser for dependency graph display *)
value print_scl1 (solutions : list (Phases.phase * Word.word)) =
  let svg_interface_url = scl_cgi ^ "SHMT/" in do
  { ps ("<script type=\"text/javascript\" src=\"" ^ scl_url ^ "js_files/dragtable.js\"></script>")
  ; ps ("<form name=\"word-order\" method=\"POST\" action = \""
       ^ svg_interface_url ^ "prog/Word_order/call_heritage2anu.cgi\">\n")
  ; ps ("<table class=\"draggable\">")
  ; ps tr_begin
  ; print_scl_solutions solutions
54
  ; ps ("<td><input type=\"hidden\" name=\"DISPLAY\" value=\"" ^ default_output_font ^"\"/></td>")
55 56 57 58 59 60 61 62 63 64 65 66
  ; ps tr_end
  ; ps table_end 
  ; ps (submit_input "Submit")
  } 
;
(* We restrict to the first solution - TEMPORARY *)
value print_scl sols = match sols with 
  [ [] -> failwith "No sol"
  | [ s :: _ ] -> print_scl1 s
  ]
;
(* end; *)