web_corpus.ml 1.47 KB
Newer Older
Idir Lankri's avatar
Idir Lankri committed
1 2 3 4 5 6 7 8
(**************************************************************************)
(*                     The Sanskrit Heritage Platform                     *)
(*                                                                        *)
(*                              Idir Lankri                               *)
(*                                                                        *)
(* ©2017 Institut National de Recherche en Informatique et en Automatique *)
(**************************************************************************)

9
include Corpus.Make (struct value path = Web.corpus_dir; end)
10
;
11 12
value url mode sentence =
  let env =
13
    [ (Params.corpus_mode, Web.string_of_corpus_mode mode) ::
14 15 16 17
      (Corpus.Sentence.state sentence) ]
  in
  Cgi.url (Corpus.Sentence.analyzer sentence) ~query:(Cgi.query_of_env env)
;
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
exception Citation_mismatch of string
;
value citation subdir id text editable =
  let mode = if editable then Web.Annotator else Web.Reader in
  let sentence =
    try sentence subdir id with
    [ No_such_sentence ->
      let init_state =
        [ (Params.corpus_dir, subdir)
        ; (Params.sentence_no, string_of_int id)
        ; ("t", Paths.default_transliteration)
        ; ("text", text)
        ]
      in
      Corpus.Sentence.make id Web.graph_cgi init_state
    ]
  in
  let expected_text =
    sentence
    |> Corpus.Sentence.state
    |> List.assoc "text"
  in
  if text = expected_text then url mode sentence else
    raise (Citation_mismatch expected_text)
42
;