Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 45 lines (35 sloc) 1.485 kB
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (* CF mli *)
19
20 let get_closest_names list typo =
21 let distances =
22 List.rev_map (
23 fun name -> (name, Sed.sed Sed.qwerty_distance name typo)
24 ) list in
25 let sorted =
26 List.sort (
27 fun (_, (value_1 : float)) (_, (value_2 :float)) -> compare value_1 value_2
28 ) distances in
29 List.map fst sorted
30
31
32 let get_closest_names_2 list typo =
33 match get_closest_names list typo with
34 | tag1 :: tag2 :: _ -> tag1, tag2
35 | _ -> invalid_arg "HintUtils.get_closest_names_2"
36
37
38 let pp_suggestion all fmt typo =
39 match get_closest_names all typo with
40 | [] -> ()
41 | [name] ->
42 Format.fprintf fmt "@[<2>@{<bright>Hint@}:@\nPerhaps you meant @{<bright>%s@} ?@]@\n" name
43 | (name_1)::(name_2)::_ ->
44 Format.fprintf fmt "@[<2>@{<bright>Hint@}:@\nPerhaps you meant @{<bright>%s@} or @{<bright>%s@} ?@]@\n" name_1 name_2
Something went wrong with that request. Please try again.