ocaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

formatting

+73 -87
+5 -5
lib/compiler/URI_util.ml
··· 26 26 let config = forest.config in 27 27 let keys = 28 28 List.of_seq @@ 29 - let@ uri = Seq.filter_map @~ addrs in 30 - if URI.host config.url = URI.host uri then 31 - let@ prefix', key = Option.bind @@ URI_scheme.split_addr uri in 32 - if prefix = prefix' then Some key else None 33 - else None 29 + let@ uri = Seq.filter_map @~ addrs in 30 + if URI.host config.url = URI.host uri then 31 + let@ prefix', key = Option.bind @@ URI_scheme.split_addr uri in 32 + if prefix = prefix' then Some key else None 33 + else None 34 34 in 35 35 let next = 36 36 match mode with
+10 -10
lib/compiler/test/Test_compiler.ml
··· 28 28 29 29 let test_batch_run ~env () = 30 30 let forest, history = 31 - with_test_forest 32 - ~raw_trees 33 - ~env 34 - ~config 35 - (fun path -> 36 - Sys.chdir (Eio.Path.native_exn path); 37 - let@ () = Reporter.easy_run in 38 - let forest = State.make ~env ~config ~dev: false () in 39 - Driver.run_with_history Load_all_configured_dirs forest 40 - ) 31 + let@ path = 32 + with_test_forest 33 + ~raw_trees 34 + ~env 35 + ~config 36 + in 37 + Sys.chdir (Eio.Path.native_exn path); 38 + let@ () = Reporter.easy_run in 39 + let forest = State.make ~env ~config ~dev: false () in 40 + Driver.run_with_history Load_all_configured_dirs forest 41 41 in 42 42 Alcotest.(check @@ list action) 43 43 "all actions have run"
+1
lib/compiler/test/Test_diagnostic_store.ml
··· 1 +
+3 -2
lib/compiler/test/Test_expansion.ml
··· 61 61 let@ () = Reporter.easy_run in 62 62 let forest = State.make ~env ~config ~dev: false () in 63 63 let expanded = 64 - expand ~forest 64 + expand 65 + ~forest 65 66 {| 66 67 \subtree[foo]{ 67 68 \title{Hello} ··· 79 80 evaluated 80 81 81 82 let test_visible ~env () = 82 - let forest = State.make ~env ~config ~dev: false () in 83 + let forest = State.make ~env ~config ~dev: false () in 83 84 let code = 84 85 Result.get_ok @@ 85 86 parse_string
+1 -1
lib/compiler/test/Test_import_graph.ml
··· 14 14 15 15 let config = {(Config.default ()) with trees = ["imports"]} 16 16 17 - let mk_vertex v = T.Uri_vertex (URI_scheme.named_uri ~base:config.url v) 17 + let mk_vertex v = T.Uri_vertex (URI_scheme.named_uri ~base: config.url v) 18 18 19 19 let has_edge g v w = 20 20 Forest_graph.mem_edge g (mk_vertex v) (mk_vertex w)
+13 -12
lib/frontend/Config_parser.ml
··· 23 23 let keys (tbl : Toml.Types.value Toml.Types.Table.t) = 24 24 let rec go current keys tbl = 25 25 List.fold_left 26 - (fun acc (key, value) -> 27 - match value with 28 - | Toml.Types.TBool _ 29 - | TInt _ 30 - | TFloat _ 31 - | TString _ 32 - | TDate _ 33 - | TArray _ -> 34 - (key :: current) :: acc 35 - | TTable tbl -> 36 - go (key :: current) acc tbl 37 - ) 26 + begin 27 + fun acc (key, value) -> 28 + match value with 29 + | Toml.Types.TBool _ 30 + | TInt _ 31 + | TFloat _ 32 + | TString _ 33 + | TDate _ 34 + | TArray _ -> 35 + (key :: current) :: acc 36 + | TTable tbl -> 37 + go (key :: current) acc tbl 38 + end 38 39 keys 39 40 (Toml.Types.Table.to_list tbl) 40 41 in
+40 -56
lib/search/Index.ml
··· 4 4 * SPDX-License-Identifier: GPL-3.0-or-later 5 5 *) 6 6 7 + open Forester_prelude 7 8 open Forester_core 8 9 open Spelll 9 10 ··· 21 22 number_of_docs: int; 22 23 } 23 24 24 - let average_doc_length 25 - : t -> float 26 - = fun {number_of_tokens; number_of_docs; _} -> 25 + let average_doc_length {number_of_tokens; number_of_docs; _} : float = 27 26 Float.of_int number_of_tokens /. Float.of_int number_of_docs 28 27 29 - let add_one 30 - : T.content T.article -> t -> t 31 - = fun article ({index; number_of_tokens; number_of_docs;} as t) -> 28 + let add_one (article : T.content T.article) ({index; number_of_tokens; number_of_docs;} as t) : t = 32 29 if Option.is_none T.(article.frontmatter.uri) then t 33 30 else 34 31 let tokens_in_article = Tokenizer.tokenize_article article in ··· 36 33 let new_tokens = ref 0 in 37 34 let new_index = 38 35 List.fold_left 39 - (fun index (ocurrences, token) -> 40 - match Index.retrieve_l ~limit: 0 index token with 41 - | [] -> 42 - (* Unseen token*) 43 - (* TODO: add to list of ocurrences*) 44 - let ocurrence = Ocurrences.singleton ([ocurrences], uri) in 45 - new_tokens := !new_tokens + 1; 46 - Index.add index token ocurrence 47 - | ids :: [] -> 48 - Index.add index token (Ocurrences.add ([ocurrences], uri) ids) 49 - | _ -> 50 - (* We are using limit=0, so this shouldn't happen*) 51 - assert false 52 - ) 36 + begin 37 + fun index (ocurrences, token) -> 38 + match Index.retrieve_l ~limit: 0 index token with 39 + | [] -> 40 + (* Unseen token*) 41 + (* TODO: add to list of ocurrences*) 42 + let ocurrence = Ocurrences.singleton ([ocurrences], uri) in 43 + new_tokens := !new_tokens + 1; 44 + Index.add index token ocurrence 45 + | ids :: [] -> 46 + Index.add index token (Ocurrences.add ([ocurrences], uri) ids) 47 + | _ -> 48 + (* We are using limit=0, so this shouldn't happen*) 49 + assert false 50 + end 53 51 index 54 52 tokens_in_article 55 53 in ··· 59 57 number_of_tokens = number_of_tokens + !new_tokens 60 58 } 61 59 62 - let add 63 - : T.content T.article list -> t -> t 64 - = 60 + let add : T.content T.article list -> t -> t = 65 61 List.fold_right add_one 66 62 67 - let search 68 - : ?fuzz: int -> t -> string -> (int list list * URI.t) list 69 - = fun ?(fuzz = 0) index term -> 70 - Tokenizer.tokenize term 71 - |> List.concat_map 72 - (fun str -> 73 - List.concat_map Ocurrences.to_list @@ 74 - Index.retrieve_l ~limit: fuzz index.index str 75 - ) 63 + let search ?(fuzz = 0) (index : t) (term : string) : (int list list * URI.t) list = 64 + let@ str = List.concat_map @~ Tokenizer.tokenize term in 65 + List.concat_map Ocurrences.to_list @@ 66 + Index.retrieve_l ~limit: fuzz index.index str 76 67 77 68 module BM_25 = struct 78 69 let sum = List.fold_left (+.) 0. ··· 87 78 List.length @@ 88 79 Tokenizer.tokenize_article d 89 80 90 - let score 91 - : T.content T.article -> string -> t -> float 92 - = fun d q index -> 81 + let score (d : T.content T.article) (q : string) (index : t) : float = 93 82 let tokens = Tokenizer.tokenize q in 94 83 assert (List.length tokens > 0); 95 84 let avg_len = average_doc_length index in 96 85 let k_1 = 1.5 in 97 86 let b = 0.75 in 98 87 sum @@ 99 - List.map 100 - (fun q_i -> 101 - let num_occurrences = 102 - Float.of_int @@ 103 - List.length @@ search index q_i 104 - in 105 - (* Format.printf "num_occurrences: %f" num_occurrences; *) 106 - idf q index *. 107 - begin 108 - (num_occurrences *. k_1 +. 1.) /. 109 - (num_occurrences +. k_1 *. (1. -. b +. (b *. doc_length d /. avg_len))) +. 110 - 1. 111 - end 112 - ) 113 - tokens 88 + let@ q_i = List.map @~ tokens in 89 + let num_occurrences = 90 + Float.of_int @@ 91 + List.length @@ search index q_i 92 + in 93 + (* Format.printf "num_occurrences: %f" num_occurrences; *) 94 + idf q index *. 95 + begin 96 + (num_occurrences *. k_1 +. 1.) /. 97 + (num_occurrences +. k_1 *. (1. -. b +. (b *. doc_length d /. avg_len))) +. 98 + 1. 99 + end 114 100 end 115 101 116 102 let create articles = ··· 124 110 125 111 let marshal (v : t) filename = 126 112 let oc = open_out_bin filename in 127 - Fun.protect 128 - ~finally: (fun () -> close_out oc) 129 - (fun () -> Marshal.to_channel oc v []) 113 + let@ () = Fun.protect ~finally: (fun () -> close_out oc) in 114 + Marshal.to_channel oc v [] 130 115 131 116 let unmarshal filename : t = 132 117 let ic = open_in_bin filename in 133 - Fun.protect 134 - ~finally: (fun () -> close_in ic) 135 - (fun () -> Marshal.from_channel ic) 118 + let@ () = Fun.protect ~finally: (fun () -> close_in ic) in 119 + Marshal.from_channel ic
-1
lib/search/Search_engine.ml
··· 10 10 open Forester_search 11 11 open Forester_frontend 12 12 13 - 14 13 open struct module T = Types end 15 14 16 15 let ranked_search