Skip to content
This repository has been archived by the owner on Mar 16, 2019. It is now read-only.

Commit

Permalink
Bugfix - dont allow cutoff to be 0
Browse files Browse the repository at this point in the history
Ignore-this: db1a9faa9a079fbe9402a13c874793a0

darcs-hash:20101126030802-1e580-8def4cff7e4d9c700f3dbacdab2f7e7c89fce530.gz
  • Loading branch information
jamii committed Nov 26, 2010
1 parent b6fbbc6 commit fae9e88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion latex.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let rec minimum (x : int) y z =

let cutoff precision latex =
let errors = (1.0 -. precision) *. (float_of_int (length latex)) in
min 5 (int_of_float (ceil errors))
max 1 (min 5 (int_of_float (ceil errors)))

(*
Calculation of the Levensthein edit distance between two latex strings.
Expand Down
20 changes: 18 additions & 2 deletions suffix_array_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ let rec random_query max_length =
| 1 -> Query.Or (random_query max_length, random_query max_length)
| _ -> Query.Latex (random_latex max_length, "")

let test_find test find n =
let random_corpus n =
let latexs = random_list n (fun () -> random_latex 1000) in
let opaques = random_list n (fun () -> random_string 1000) in
let items = List.combine opaques latexs in
let sa = Suffix_array.create () in
Suffix_array.add sa items;
Suffix_array.prepare sa;
(items, sa)

let test_find test find n =
let (items, sa) = random_corpus n in
let test_result = List.sort compare (test items) in
let real_result = List.sort compare (List.map (fun (_,opaque) -> opaque) (find sa)) in
if test_result <> real_result then Util.flush_line "Fail!" else Util.flush_line "Pass!";
Expand Down Expand Up @@ -82,4 +86,16 @@ let test_find_query n =
let find sa =
Suffix_array.find_query sa precision query in
test_find test find n


let test_find_max_precision n =
let latexL = random_latex 5 in
let test items =
Util.filter_map
(fun (id,latexR) ->
if exact_match latexL latexR
then Some id
else None)
items in
let find sa =
Suffix_array.find_approx sa 1.0 latexL in
test_find test find n

0 comments on commit fae9e88

Please sign in to comment.