aboutsummaryrefslogtreecommitdiff
path: root/motus/js
diff options
context:
space:
mode:
Diffstat (limited to 'motus/js')
-rw-r--r--motus/js/initialize.ml34
-rw-r--r--motus/js/motus.ml4
-rw-r--r--motus/js/next.ml11
-rw-r--r--motus/js/reload.ml11
-rw-r--r--motus/js/state.ml2
5 files changed, 46 insertions, 16 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
diff --git a/motus/js/motus.ml b/motus/js/motus.ml
index 402e14a..5e1252a 100644
--- a/motus/js/motus.ml
+++ b/motus/js/motus.ml
@@ -86,10 +86,10 @@ let main
let proposition = S.value initial_prop in
Elements.Transfert.get_content_from_url words
- |> E.map (fun content ->
+ |> E.map (fun html_response ->
State.App.dispatch
(module Initialize)
- Initialize.{ length; content; sender; proposition } ) )
+ Initialize.{ length; html_response; sender; proposition } ) )
send_btn
|> E.join
in
diff --git a/motus/js/next.ml b/motus/js/next.ml
index f3bb2fe..e6baf51 100644
--- a/motus/js/next.ml
+++ b/motus/js/next.ml
@@ -11,6 +11,9 @@ let process : t -> State.state -> State.state =
(* Update the word list with the new rules *)
let analysis = Motus_lib.Wordlist.filter rules state.analysis in
+ Printf.printf
+ "Number of elements after filter : %d\n"
+ (Motus_lib.Wordlist.list_size analysis);
let rules =
Motus_lib.Criteria.merge_lists ~init:state.rules rules
@@ -23,7 +26,13 @@ let process : t -> State.state -> State.state =
let new_state = { state with propositions; current_prop; rules; analysis } in
(* Get the new proposition if any *)
- let current_prop = Initialize.get_proposition state.length analysis rules in
+ let current_prop =
+ Initialize.get_proposition
+ ~catalog:state.catalog
+ state.length
+ analysis
+ rules
+ in
match current_prop with
| None -> new_state
| Some prop ->
diff --git a/motus/js/reload.ml b/motus/js/reload.ml
index f0b581f..ee9ab37 100644
--- a/motus/js/reload.ml
+++ b/motus/js/reload.ml
@@ -18,11 +18,18 @@ let process : t -> State.state -> State.state =
in
let new_state =
- { state with analysis = Motus_lib.Wordlist.remove_word state.analysis word }
+ { state with
+ analysis = Motus_lib.Wordlist.remove_word state.analysis word
+ ; catalog = Motus_lib.Wordlist.remove_word state.catalog word
+ }
in
(* Get the new proposition if any *)
let current_prop =
- Initialize.get_proposition state.length new_state.analysis state.rules
+ Initialize.get_proposition
+ ~catalog:new_state.catalog
+ state.length
+ new_state.analysis
+ state.rules
in
match current_prop with
| None -> new_state
diff --git a/motus/js/state.ml b/motus/js/state.ml
index cbab14f..e2e531d 100644
--- a/motus/js/state.ml
+++ b/motus/js/state.ml
@@ -5,6 +5,7 @@ type proposition = (Jstr.t * Validity.t) option list
type state =
{ analysis : Wordlist.t
+ ; catalog : Wordlist.t
; rules : Criteria.t list
; length : int
; propositions : proposition list
@@ -14,6 +15,7 @@ type state =
let init () =
{ analysis = Wordlist.empty_data ()
+ ; catalog = Wordlist.empty_data ()
; rules = []
; length = 0
; propositions = []