Commit df249d4d authored by Bruno Guillaume's avatar Bruno Guillaume
Browse files

Add comments for Projection module

parent 56a95e78
......@@ -244,13 +244,13 @@ module Projection = struct
let to_json keys t =
let rec loop acc keys partial t =
match (keys, t) with
| ([], Leaf n) -> (`Assoc (("freq", `Int n) :: partial)) :: acc
| ([], Leaf n) -> (`Assoc (List.rev (("freq", `Int n) :: partial))) :: acc
| (key :: tail, Node map) ->
String_opt_map.fold
(fun value sub_t acc2 ->
let new_partial = (key, match value with Some s -> `String s | _ -> `Null) :: partial in
loop acc2 tail new_partial sub_t
) map acc
| _ -> Error.bug "[Projection.insert] inconsitent data" in
| _ -> Error.bug "[Projection.to_json] inconsitent data" in
`List (loop [] keys [] t)
end
\ No newline at end of file
......@@ -32,12 +32,31 @@ end
(** {2 Projection} *)
(* ==================================================================================================== *)
module Projection : sig
(* the type Projection.t encodes the projection of a corpus as a lexicon (used in ArboratogGrew). See [Graph.insert_proj] for usage.
It a recusive map of homogeneous depth, key are string otion for feature values.
[Graph.insert_proj] is supposed to used always the same key list when interacting with a projection.
*)
type t
(* empty projection *)
val empty: t
(* [prune_unambiguous n proj] prune in input proj with unambiguous structure at depth n
For instance, if the keys are values for features [form, lemma, upos, Gender, Number],
prune_unambiguous 3 proj will keep only lexicon entries where there is
more than one couple of value for Gender and Number with the same triple (form, lemma, upos).
*)
val prune_unambiguous: int -> t -> t
(* export the projection as a json data. The output is a list of object;
each object containts:
* a key for each feature key used to build it (value are string of null)
* a numeric key "freq" with the frequency of the corresponding values
Ex:
[ {"freq": 3, "Gender": "Masc", "upos": "NOUN", "lemma": "État", "form": "États" },
{"freq": 1, "Gender": null, "upos": "NOUN", "lemma": "État", "form": "États" } ]
*)
val to_json: string list -> t -> Yojson.Basic.t
end
......
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