Levenshtein distance/Alignment: Difference between revisions
Content deleted Content added
+ D entry |
Simpler D entry |
||
Line 19: | Line 19: | ||
immutable s1 = "rosettacode"; |
immutable s1 = "rosettacode"; |
||
immutable s2 = "raisethysword"; |
immutable s2 = "raisethysword"; |
||
const dd = levenshteinDistanceAndPath(s1, s2); |
|||
// EditOp Key: |
|||
// n = none. Current items are equal, no editing is necessary. |
|||
// s = substitute current target item with current source item. |
|||
// i = insert current item from the source into the target. |
|||
// r = remove current item from the target. |
|||
writeln("Levenshtein distance and edit operations:\n", dd, "\n"); |
|||
string s1b, s2b; |
string s1b, s2b; |
||
size_t pos1, pos2; |
size_t pos1, pos2; |
||
foreach (immutable c; |
foreach (immutable c; levenshteinDistanceAndPath(s1, s2)[1]) { |
||
final switch (c) with (EditOp) { |
final switch (c) with (EditOp) { |
||
case none, substitute: |
case none, substitute: |
||
Line 48: | Line 40: | ||
} |
} |
||
writeln( |
writeln(s1b, "\n", s2b); |
||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |
||
⚫ | |||
<pre>Levenshtein distance and edit operations: |
|||
const(Tuple!(uint, EditOp[]))(8, nisnnnisssnss) |
|||
Alignments: |
|||
⚫ | |||
raisethysword</pre> |
raisethysword</pre> |
||