doc and tests for CCLevenshtein

This commit is contained in:
Simon Cruanes 2015-09-27 21:42:58 +02:00
parent 219e06c1fe
commit 179cafde9e
2 changed files with 17 additions and 7 deletions

View file

@ -93,7 +93,7 @@ let rec klist_to_list l = match l () with
l, Index.of_list l' l, Index.of_list l'
in in
let gen = Q.Gen.( let gen = Q.Gen.(
list_size (3 -- 15) (string_size (0 -- 10)) >|= mklist list_size (3 -- 15) (string_size (1 -- 10)) >|= mklist
) in ) in
let small (l,_) = List.length l in let small (l,_) = List.length l in
let print (l,_) = Q.Print.(list string) l in let print (l,_) = Q.Print.(list string) l in
@ -106,12 +106,23 @@ let rec klist_to_list l = match l () with
let retrieved = Index.retrieve ~limit:2 idx s let retrieved = Index.retrieve ~limit:2 idx s
|> klist_to_list in |> klist_to_list in
List.for_all List.for_all
(fun s' -> edit_distance s s' <= 2) retrieved (fun s' -> edit_distance s s' <= 2) retrieved &&
List.for_all
(fun s' -> not (edit_distance s s' <= 2) || List.mem s' retrieved)
l
) l ) l
) )
*) *)
(*$R
let idx = Index.of_list ["aa", "aa"; "ab", "ab"; "cd", "cd"; "a'c", "a'c"] in
assert_equal ~printer:Q.Print.(list string)
["a'c"; "aa"; "ab"]
(Index.retrieve ~limit:1 idx "ac" |> CCKList.to_list
|> List.sort Pervasives.compare)
*)
module type S = sig module type S = sig
type char_ type char_
type string_ type string_

View file

@ -79,15 +79,14 @@ The signature for a given string representation provides 3 main things:
A possible use of the index could be: A possible use of the index could be:
{[ {[
open Batteries;;
let words = File.with_file_in "/usr/share/dict/english" let words = CCIO.with_in "/usr/share/dict/words"
(fun i -> IO.read_all i |> String.nsplit ~by:"\\n");; (fun i -> CCIO.read_all i |> CCString.Split.list_cpy ~by:"\n");;
let words = List.map (fun s->s,s) words;; let words = List.map (fun s->s,s) words;;
let idx = Levenshtein.Index.of_list words;; let idx = CCLevenshtein.Index.of_list words;;
Levenshtein.Index.retrieve ~limit:1 idx "hell" |> Levenshtein.klist_to_list;; CCLevenshtein.Index.retrieve ~limit:1 idx "hell" |> CCLevenshtein.klist_to_list;;
]} ]}
*) *)