Commit 13493b75 authored by Bruno Guillaume's avatar Bruno Guillaume

add to_orfeo function

parent eff8c0ee
......@@ -922,6 +922,39 @@ module G_graph = struct
Sentence.fr_clean_spaces (loop None snodes)
let start_dur gnode =
let fs = G_node.get_fs gnode in
match (G_fs.get_string_atom "_start" fs, G_fs.get_string_atom "_stop" fs) with (Some _start, Some _stop) ->
let start = float_of_string _start
and stop = float_of_string _stop in
(start, stop -. start)
| _ -> (-1., -1.)
let to_orfeo ?(deco=G_deco.empty) graph =
let is_highlighted_gid gid = List.mem_assoc gid deco.nodes in
let nodes = Gid_map.fold (fun id elt acc -> (id,elt)::acc) graph.map [] in
let snodes = List.sort (fun (_,n1) (_,n2) -> G_node.position_comp n1 n2) nodes in
let buff = Buffer.create 32 in
CCList.iteri (fun i (gid, gnode) ->
match G_fs.to_word (G_node.get_fs gnode) with
| None -> ()
| Some word ->
let (start, dur) = start_dur gnode in
Printf.bprintf buff
"<span id=\"tok%d\" data-dur=\"%g\" data-begin=\"%g\" tabindex=\"0\" data-index=\"%d\" %s%s>%s </span>"
i dur start i
(if i=1 then "class=\"speaking highlight\"" else "")
(if is_highlighted_gid gid then "class=\"highlight\"" else "")
word
) snodes;
Buffer.contents buff
(* -------------------------------------------------------------------------------- *)
let is_non_lexical_node node =
let fs = G_node.get_fs node in G_fs.get_string_atom "kind" fs <> None
......
......@@ -203,6 +203,7 @@ module G_graph: sig
val to_gr: t -> string
val to_dot: ?main_feat:string -> ?get_url:(string -> string option) -> ?deco:G_deco.t -> t -> string
val to_sentence: ?only_pivot: bool -> ?main_feat:string -> ?deco:G_deco.t -> t -> string
val to_orfeo: ?deco:G_deco.t -> t -> string
val to_dep: ?filter: (string -> bool) -> ?main_feat:string -> ?deco:G_deco.t -> t -> string
val to_conll: t -> Conll.t
val to_conll_string: ?cupt:bool -> t -> string
......
......@@ -229,6 +229,12 @@ module Graph = struct
Grew_graph.G_graph.to_sentence ?only_pivot ?main_feat ?deco gr
) ()
let to_orfeo ?deco gr =
Libgrew.handle ~name:"Graph.to_orfeo"
(fun () ->
Grew_graph.G_graph.to_orfeo ?deco gr
) ()
let save_conll filename graph =
Libgrew.handle ~name:"Graph.save_conll" (fun () ->
let out_ch = open_out filename in
......
......@@ -98,6 +98,7 @@ module Graph : sig
val sentence_of_pst: ?domain:Domain.t -> string -> string
val to_sentence: ?only_pivot: bool -> ?main_feat:string -> ?deco:Deco.t -> t -> string
val to_orfeo: ?deco:Deco.t -> t -> string
val to_dot : ?main_feat:string -> ?deco:Deco.t -> ?get_url:(string -> string option) -> t -> string
......
Markdown is supported
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