1 USING: help.markup help.syntax strings generic vectors assocs
5 ARTICLE: "tools.completion" "Fuzzy completion"
6 "Various developer tools make use of a general-purpose fuzzy completion algorithm."
8 "The main entry point:"
9 { $subsection completions }
10 "The words used to implement the algorithm can be called as well, for finer control over fuzzy matching:"
14 { $subsection complete }
15 { $subsection rank-completions } ;
17 ABOUT: "tools.completion"
20 { $values { "full" string } { "short" string } { "indices" vector } }
21 { $description "If " { $snippet "short" } " can be obtained from " { $snippet "full" } " by removing subsequences, then outputs the index of every character from " { $snippet "short" } " in " { $snippet "full" } ", otherwise outputs " { $link f } "." } ;
24 { $values { "seq" "a sequence of integers" } { "newseq" "a sequence of sequences of integers" } }
25 { $description "Groups subsequences of consecutive integers." }
27 { $example "USING: prettyprint tools.completion ;" "{ 1 2 3 5 6 9 10 } runs ." "V{ V{ 1 2 3 } V{ 5 6 } V{ 9 10 } }" }
31 { $values { "full" string } { "fuzzy" "a sequence of sequences of integers" } { "n" integer } }
32 { $description "Ranks " { $snippet "fuzzy" } " by how closely it approximates the sequence " { $snippet "{ { 0 ... n-1 } }" } " where " { $snippet "n" } " is the length of " { $snippet "full" } "." } ;
34 HELP: rank-completions
35 { $values { "results" "an alist" } { "newresults" "an alist" } }
36 { $description "Sorts " { $snippet "results" } " by the first element of each pair, and discards the low 33% of the results." } ;
39 { $values { "full" string } { "short" string } { "score" "a rational number between 0 and 1" } }
40 { $description "Ranks how close " { $snippet "short" } " is to " { $snippet "full" } " by edit distance." } ;
43 { $values { "short" string } { "candidate" "a pair " { $snippet "{ obj full }" } } { "result" "a pair " { $snippet "{ score obj }" } } }
44 { $description "Outputs a pair of two elements:"
46 { "how close " { $snippet "short" } " is to " { $snippet "full" } " by edit distance" }
47 { "the original value of " { $snippet "obj" } }
52 { $values { "short" string } { "candidates" "a sequence of pairs of the shape " { $snippet "{ obj full }" } } { "seq" "a sequence of pairs of the shape " { $snippet "{ score obj }" } } }
53 { $description "Calls " { $link completion } " to produce a sequence of " { $snippet "{ score obj }" } " pairs, then calls " { $link rank-completions } " to sort them and discard the low 33%." } ;