aboutsummaryrefslogtreecommitdiff
path: root/motus/js/initialize.ml
diff options
context:
space:
mode:
Diffstat (limited to 'motus/js/initialize.ml')
-rw-r--r--motus/js/initialize.ml34
1 files changed, 23 insertions, 11 deletions
diff --git a/motus/js/initialize.ml b/motus/js/initialize.ml
index 9d07a85..9375880 100644
--- a/motus/js/initialize.ml
+++ b/motus/js/initialize.ml
@@ -5,7 +5,7 @@ open Brr
type t =
{ length : int
- ; content : (int * Jstr.t, Jv.Error.t) result
+ ; html_response : (int * Jstr.t, Jv.Error.t) result
; sender : (int * Jstr.t * Validity.t) E.send
; proposition : State.proposition
}
@@ -18,16 +18,24 @@ type t =
The rule list is used to identify the letter already fixed by the previous
results. *)
let get_proposition :
- int -> Wordlist.t -> Criteria.t list -> State.proposition option =
- fun length wordlist rules ->
- Printf.printf "Number of elements : %d\n" (Wordlist.list_size wordlist);
-
+ int
+ -> catalog:Wordlist.t
+ -> Wordlist.t
+ -> Criteria.t list
+ -> State.proposition option =
+ fun length ~catalog wordlist rules ->
let word =
- if Wordlist.list_size wordlist > 2000
+ let elements = Wordlist.list_size wordlist in
+ if elements > 2000
then Freq_analysis.analyse wordlist |> Freq_analysis.pick_next_word wordlist
- else
- let _, word = Entropy.analyse length wordlist in
+ else if elements > 1
+ then
+ let _, word = Entropy.analyse length ~catalog wordlist in
word
+ else
+ match Wordlist.pick wordlist with
+ | Some w -> w
+ | None -> ""
in
match String.equal String.empty word with
| true -> None
@@ -56,8 +64,8 @@ let get_proposition :
Some proposition
-let process { sender; length; content; proposition } state =
- match content with
+let process { sender; length; html_response; proposition } state =
+ match html_response with
| Ok (200, value) ->
let rules =
Criteria.Lenght length :: State.get_current_rules proposition
@@ -68,8 +76,11 @@ let process { sender; length; content; proposition } state =
|> Seq.map (fun w -> Jstr.(to_string (uppercased w)))
|> Wordlist.add_words rules
in
+ Printf.printf
+ "Number of elements after filter : %d\n"
+ (Motus_lib.Wordlist.list_size analysis);
- let current_prop = get_proposition length analysis rules
+ let current_prop = get_proposition ~catalog:analysis length analysis rules
and fields = FieldList.make length sender in
( match current_prop with
| None -> state
@@ -78,6 +89,7 @@ let process { sender; length; content; proposition } state =
State.
{ analysis
+ ; catalog = analysis
; rules
; length
; current_prop = prop