Commit 86659134 authored by Vlad Dumitru's avatar Vlad Dumitru
Browse files

add some helpful tort functions

parent daa7ba10
......@@ -52,6 +52,22 @@ let bucket_of_file path =
| `Yes -> Yojson.Basic.from_file path |> Speechcake.Storage.Bucket.load
| _ -> Ok (Speechcake.Storage.Bucket.init ())
let tiers () path =
let contents = In_channel.read_all path in
let result =
let open Result.Monad_infix in
Speechcake.Annotation.Textgrid.Read.of_string contents
>>| fun tiers ->
List.map tiers ~f:Annotation.Tier.name
in
match result with
| Ok tiers ->
Fmt.(pr "%a@." (list ~sep:(any "@.") string)) tiers
| Error (`Parsing_error e) ->
Fmt.epr "parsing error: %s@." e
| Error (`Tier_not_found t) ->
Fmt.epr "tier not found: %s@." t
let extract () path name =
let contents = In_channel.read_all path in
let result =
......@@ -125,6 +141,28 @@ let default_t =
let open Term in
const (fun () -> Fmt.pr "no default action@.") $ setup, info ""
let uuid_t =
let open Term in
let action () =
let uuid = Uuidm.v `V4 in
Fmt.pr "%s@." (Uuidm.to_string uuid)
in
let doc = "Generate a random UUIDv4" in
( const action $ setup
, info ~doc "uuid"
)
let tiers_t =
let open Term in
let path =
let doc = "Path to the TextGrid file" in
Arg.(value & pos 0 string "" & info [] ~docv:"PATH" ~doc) in
let doc = "List the tiers from a TextGrid file" in
( const tiers $ setup $ path
, info ~doc "tiers"
)
let extract_t =
let open Term in
let path =
......@@ -250,7 +288,8 @@ let () =
Logs.set_reporter (reporter Fmt.stderr);
Term.exit @@
Term.eval_choice default_t
[ extract_t
[ uuid_t
; tiers_t; extract_t
; wrap_t
; persist_t
; commit_t
......
......@@ -437,6 +437,7 @@ let load =
let commit t root ~info =
let version = Block.Version (root, info) in
let v_ptr = Block_storage.put t.blocks version in
Log.info (fun m -> m "committed %a@." Block.pp (Hashtbl.find_exn t.blocks v_ptr)) ;
v_ptr
let tag t name ptr =
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment