]> gitweb.factorcode.org Git - factor.git/blob - basis/lcs/lcs-docs.factor
core, basis, extra: Remove DOS line endings from files.
[factor.git] / basis / lcs / lcs-docs.factor
1 USING: help.syntax help.markup sequences ;
2 IN: lcs
3
4 HELP: levenshtein
5 { $values { "old" sequence } { "new" sequence } { "n" "the Levenshtein distance" } }
6 { $description "Calculates the Levenshtein distance between old and new, that is, the minimal number of changes from the old sequence to the new one, in terms of deleting, inserting and replacing characters." } ;
7
8 HELP: lcs
9 { $values { "seq1" sequence } { "seq2" sequence } { "lcs" "a longest common subsequence" } }
10 { $description "Given two sequences, calculates a longest common subsequence between them. Note two things: this is only one of the many possible LCSs, and the LCS may not be contiguous." } ;
11
12 HELP: lcs-diff
13 { $values { "old" sequence } { "new" sequence } { "diff" "an edit script" } }
14 { $description "Given two sequences, find a minimal edit script from the old to the new. There may be more than one minimal edit script, and this chooses one arbitrarily. This script is in the form of an array of the tuples of the classes " { $link retain } ", " { $link delete } " and " { $link insert } " which have their information stored in the 'item' slot." } ;
15
16 HELP: retain
17 { $class-description "Represents an action in an edit script where an item is kept, going from the initial sequence to the final sequence. This has one slot, called item, containing the thing which is retained" } ;
18
19 HELP: delete
20 { $class-description "Represents an action in an edit script where an item is deleted, going from the initial sequence to the final sequence. This has one slot, called item, containing the thing which is deleted" } ;
21
22 HELP: insert
23 { $class-description "Represents an action in an edit script where an item is added, going from the initial sequence to the final sequence. This has one slot, called item, containing the thing which is inserted" } ;
24
25 ARTICLE: "lcs" "LCS, diffing and distance"
26 "This vocabulary provides words for three apparently unrelated but in fact very similar problems: finding a longest common subsequence between two sequences, getting a minimal edit script (diff) between two sequences, and calculating the Levenshtein distance between two sequences. The implementations of these algorithms are very closely related, and all running times are O(nm), where n and m are the lengths of the input sequences."
27 { $subsections
28     lcs
29     lcs-diff
30     levenshtein
31 }
32 "The " { $link lcs-diff } " word returns a sequence of tuples of the following classes. They all hold their contents in the 'item' slot."
33 { $subsections
34     insert
35     delete
36     retain
37 } ;
38
39 ABOUT: "lcs"