···2626 let config = forest.config in
2727 let keys =
2828 List.of_seq @@
2929- let@ uri = Seq.filter_map @~ addrs in
3030- if URI.host config.url = URI.host uri then
3131- let@ prefix', key = Option.bind @@ URI_scheme.split_addr uri in
3232- if prefix = prefix' then Some key else None
3333- else None
2929+ let@ uri = Seq.filter_map @~ addrs in
3030+ if URI.host config.url = URI.host uri then
3131+ let@ prefix', key = Option.bind @@ URI_scheme.split_addr uri in
3232+ if prefix = prefix' then Some key else None
3333+ else None
3434 in
3535 let next =
3636 match mode with
+10-10
lib/compiler/test/Test_compiler.ml
···28282929let test_batch_run ~env () =
3030 let forest, history =
3131- with_test_forest
3232- ~raw_trees
3333- ~env
3434- ~config
3535- (fun path ->
3636- Sys.chdir (Eio.Path.native_exn path);
3737- let@ () = Reporter.easy_run in
3838- let forest = State.make ~env ~config ~dev: false () in
3939- Driver.run_with_history Load_all_configured_dirs forest
4040- )
3131+ let@ path =
3232+ with_test_forest
3333+ ~raw_trees
3434+ ~env
3535+ ~config
3636+ in
3737+ Sys.chdir (Eio.Path.native_exn path);
3838+ let@ () = Reporter.easy_run in
3939+ let forest = State.make ~env ~config ~dev: false () in
4040+ Driver.run_with_history Load_all_configured_dirs forest
4141 in
4242 Alcotest.(check @@ list action)
4343 "all actions have run"
···6161 let@ () = Reporter.easy_run in
6262 let forest = State.make ~env ~config ~dev: false () in
6363 let expanded =
6464- expand ~forest
6464+ expand
6565+ ~forest
6566 {|
6667 \subtree[foo]{
6768 \title{Hello}
···7980 evaluated
80818182let test_visible ~env () =
8282- let forest = State.make ~env ~config ~dev: false () in
8383+ let forest = State.make ~env ~config ~dev: false () in
8384 let code =
8485 Result.get_ok @@
8586 parse_string
+1-1
lib/compiler/test/Test_import_graph.ml
···14141515let config = {(Config.default ()) with trees = ["imports"]}
16161717-let mk_vertex v = T.Uri_vertex (URI_scheme.named_uri ~base:config.url v)
1717+let mk_vertex v = T.Uri_vertex (URI_scheme.named_uri ~base: config.url v)
18181919let has_edge g v w =
2020 Forest_graph.mem_edge g (mk_vertex v) (mk_vertex w)
+13-12
lib/frontend/Config_parser.ml
···2323let keys (tbl : Toml.Types.value Toml.Types.Table.t) =
2424 let rec go current keys tbl =
2525 List.fold_left
2626- (fun acc (key, value) ->
2727- match value with
2828- | Toml.Types.TBool _
2929- | TInt _
3030- | TFloat _
3131- | TString _
3232- | TDate _
3333- | TArray _ ->
3434- (key :: current) :: acc
3535- | TTable tbl ->
3636- go (key :: current) acc tbl
3737- )
2626+ begin
2727+ fun acc (key, value) ->
2828+ match value with
2929+ | Toml.Types.TBool _
3030+ | TInt _
3131+ | TFloat _
3232+ | TString _
3333+ | TDate _
3434+ | TArray _ ->
3535+ (key :: current) :: acc
3636+ | TTable tbl ->
3737+ go (key :: current) acc tbl
3838+ end
3839 keys
3940 (Toml.Types.Table.to_list tbl)
4041 in
+40-56
lib/search/Index.ml
···44 * SPDX-License-Identifier: GPL-3.0-or-later
55 *)
6677+open Forester_prelude
78open Forester_core
89open Spelll
910···2122 number_of_docs: int;
2223}
23242424-let average_doc_length
2525- : t -> float
2626-= fun {number_of_tokens; number_of_docs; _} ->
2525+let average_doc_length {number_of_tokens; number_of_docs; _} : float =
2726 Float.of_int number_of_tokens /. Float.of_int number_of_docs
28272929-let add_one
3030- : T.content T.article -> t -> t
3131-= fun article ({index; number_of_tokens; number_of_docs;} as t) ->
2828+let add_one (article : T.content T.article) ({index; number_of_tokens; number_of_docs;} as t) : t =
3229 if Option.is_none T.(article.frontmatter.uri) then t
3330 else
3431 let tokens_in_article = Tokenizer.tokenize_article article in
···3633 let new_tokens = ref 0 in
3734 let new_index =
3835 List.fold_left
3939- (fun index (ocurrences, token) ->
4040- match Index.retrieve_l ~limit: 0 index token with
4141- | [] ->
4242- (* Unseen token*)
4343- (* TODO: add to list of ocurrences*)
4444- let ocurrence = Ocurrences.singleton ([ocurrences], uri) in
4545- new_tokens := !new_tokens + 1;
4646- Index.add index token ocurrence
4747- | ids :: [] ->
4848- Index.add index token (Ocurrences.add ([ocurrences], uri) ids)
4949- | _ ->
5050- (* We are using limit=0, so this shouldn't happen*)
5151- assert false
5252- )
3636+ begin
3737+ fun index (ocurrences, token) ->
3838+ match Index.retrieve_l ~limit: 0 index token with
3939+ | [] ->
4040+ (* Unseen token*)
4141+ (* TODO: add to list of ocurrences*)
4242+ let ocurrence = Ocurrences.singleton ([ocurrences], uri) in
4343+ new_tokens := !new_tokens + 1;
4444+ Index.add index token ocurrence
4545+ | ids :: [] ->
4646+ Index.add index token (Ocurrences.add ([ocurrences], uri) ids)
4747+ | _ ->
4848+ (* We are using limit=0, so this shouldn't happen*)
4949+ assert false
5050+ end
5351 index
5452 tokens_in_article
5553 in
···5957 number_of_tokens = number_of_tokens + !new_tokens
6058 }
61596262-let add
6363- : T.content T.article list -> t -> t
6464- =
6060+let add : T.content T.article list -> t -> t =
6561 List.fold_right add_one
66626767-let search
6868- : ?fuzz: int -> t -> string -> (int list list * URI.t) list
6969-= fun ?(fuzz = 0) index term ->
7070- Tokenizer.tokenize term
7171- |> List.concat_map
7272- (fun str ->
7373- List.concat_map Ocurrences.to_list @@
7474- Index.retrieve_l ~limit: fuzz index.index str
7575- )
6363+let search ?(fuzz = 0) (index : t) (term : string) : (int list list * URI.t) list =
6464+ let@ str = List.concat_map @~ Tokenizer.tokenize term in
6565+ List.concat_map Ocurrences.to_list @@
6666+ Index.retrieve_l ~limit: fuzz index.index str
76677768module BM_25 = struct
7869 let sum = List.fold_left (+.) 0.
···8778 List.length @@
8879 Tokenizer.tokenize_article d
89809090- let score
9191- : T.content T.article -> string -> t -> float
9292- = fun d q index ->
8181+ let score (d : T.content T.article) (q : string) (index : t) : float =
9382 let tokens = Tokenizer.tokenize q in
9483 assert (List.length tokens > 0);
9584 let avg_len = average_doc_length index in
9685 let k_1 = 1.5 in
9786 let b = 0.75 in
9887 sum @@
9999- List.map
100100- (fun q_i ->
101101- let num_occurrences =
102102- Float.of_int @@
103103- List.length @@ search index q_i
104104- in
105105- (* Format.printf "num_occurrences: %f" num_occurrences; *)
106106- idf q index *.
107107- begin
108108- (num_occurrences *. k_1 +. 1.) /.
109109- (num_occurrences +. k_1 *. (1. -. b +. (b *. doc_length d /. avg_len))) +.
110110- 1.
111111- end
112112- )
113113- tokens
8888+ let@ q_i = List.map @~ tokens in
8989+ let num_occurrences =
9090+ Float.of_int @@
9191+ List.length @@ search index q_i
9292+ in
9393+ (* Format.printf "num_occurrences: %f" num_occurrences; *)
9494+ idf q index *.
9595+ begin
9696+ (num_occurrences *. k_1 +. 1.) /.
9797+ (num_occurrences +. k_1 *. (1. -. b +. (b *. doc_length d /. avg_len))) +.
9898+ 1.
9999+ end
114100end
115101116102let create articles =
···124110125111let marshal (v : t) filename =
126112 let oc = open_out_bin filename in
127127- Fun.protect
128128- ~finally: (fun () -> close_out oc)
129129- (fun () -> Marshal.to_channel oc v [])
113113+ let@ () = Fun.protect ~finally: (fun () -> close_out oc) in
114114+ Marshal.to_channel oc v []
130115131116let unmarshal filename : t =
132117 let ic = open_in_bin filename in
133133- Fun.protect
134134- ~finally: (fun () -> close_in ic)
135135- (fun () -> Marshal.from_channel ic)
118118+ let@ () = Fun.protect ~finally: (fun () -> close_in ic) in
119119+ Marshal.from_channel ic
-1
lib/search/Search_engine.ml
···1010open Forester_search
1111open Forester_frontend
12121313-1413open struct module T = Types end
15141615let ranked_search