Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 3948ef84 authored by Bruno Guillaume's avatar Bruno Guillaume
Browse files

review "load_grs"

parent ab4ce810
No related branches found
No related tags found
No related merge requests found
...@@ -74,14 +74,28 @@ let run_command request = ...@@ -74,14 +74,28 @@ let run_command request =
(* ======================= load_grs ======================= *) (* ======================= load_grs ======================= *)
| Some "load_grs" -> | Some "load_grs" ->
begin begin
match json |> member "filename" |> to_string_option with let dict = json |> to_assoc in
| Some filename -> match List.assoc_opt "filename" dict with
| Some `String filename ->
let grs = Grs.load ~config filename in let grs = Grs.load ~config filename in
let index = Global.grs_add grs in let index = Global.grs_add grs in
(* let json = Grs.to_json grs in *)
let data = `Assoc [("index", `Int index)] in let data = `Assoc [("index", `Int index)] in
Yojson.Basic.to_string (`Assoc [("status", `String "OK"); ("data", data)]) Yojson.Basic.to_string (`Assoc [("status", `String "OK"); ("data", data)])
| None -> json_error "no 'filename' in 'load_grs' command" | _ ->
match List.assoc_opt "str" dict with
| Some `String str ->
let grs = Grs.parse ~config str in
let index = Global.grs_add grs in
let data = `Assoc [("index", `Int index)] in
Yojson.Basic.to_string (`Assoc [("status", `String "OK"); ("data", data)])
| _ ->
match List.assoc_opt "json" dict with
| Some data ->
let grs = json |> member "json" |> Grs.of_json ~config in
let index = Global.grs_add grs in
let data = `Assoc [("index", `Int index)] in
Yojson.Basic.to_string (`Assoc [("status", `String "OK"); ("data", data)])
| _ -> json_error "fail in 'load_grs' command"
end end
(* ======================= load_corpus ======================= *) (* ======================= load_corpus ======================= *)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment