From 95432043550bd4a41b4466395502bc3b748e6746 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Thu, 24 Feb 2022 09:26:23 +0100 Subject: Moved the wordlist into a set --- motus/js/initialize.ml | 12 +++++------- motus/js/next.ml | 7 +------ 2 files changed, 6 insertions(+), 13 deletions(-) (limited to 'motus/js') diff --git a/motus/js/initialize.ml b/motus/js/initialize.ml index 82f1288..a088a0e 100644 --- a/motus/js/initialize.ml +++ b/motus/js/initialize.ml @@ -21,7 +21,7 @@ let get_proposition : Wordlist.t -> Criteria.t list -> State.proposition option = fun analysis rules -> let word = - Wordlist.extract_freq analysis |> Wordlist.pick_next_word analysis |> fst + Freq_analysis.analyse analysis |> Freq_analysis.pick_next_word analysis in match String.equal String.empty word with | true -> None @@ -58,13 +58,11 @@ let process { sender; length; content; proposition } state = in let words = Jstr.cuts ~sep:(Jstr.v "\n") value in let analysis = - List.fold_left - ~f:(fun a w -> - let upper = Jstr.uppercased w in - Wordlist.add_word rules a (Jstr.to_string upper) ) - ~init:(Wordlist.empty_data ()) - words + List.to_seq words + |> Seq.map (fun w -> Jstr.(to_string (uppercased w))) + |> Wordlist.add_words rules in + let current_prop = get_proposition analysis rules and fields = FieldList.make length sender in ( match current_prop with diff --git a/motus/js/next.ml b/motus/js/next.ml index 72db9e4..104b3e6 100644 --- a/motus/js/next.ml +++ b/motus/js/next.ml @@ -15,12 +15,7 @@ let process : t -> State.state -> State.state = in (* Update the word list with the new rules *) - let analysis = - List.fold_left - ~f:(Motus_lib.Wordlist.add_word rules) - ~init:(Motus_lib.Wordlist.empty_data ()) - (Motus_lib.Wordlist.words state.analysis) - in + let analysis = Motus_lib.Wordlist.filter rules state.analysis in let propositions = state.current_prop :: state.propositions and current_prop = [] in -- cgit v1.2.3