Skip to content

Commit f0cd444

Browse files
committed
README updated, formatting
1 parent 1cb42fe commit f0cd444

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The main characteristics of each implemented algorithm are presented below. The
4545
| [Normalized Levenshtein](#normalized-levenshtein) |distance<br>similarity | Yes | No | | O(m*n) <sup>1</sup> |
4646
| [Weighted Levenshtein](#weighted-levenshtein) |distance | No | No | | O(m*n) <sup>1</sup> |
4747
| [Damerau-Levenshtein](#damerau-levenshtein) <sup>3</sup> |distance | No | Yes | | O(m*n) <sup>1</sup> |
48-
| Optimal String Alignment <sup>3</sup> |not implemented yet | No | No | | O(m*n) <sup>1</sup> |
48+
| []Optimal String Alignment](#optimal-string-alignment) <sup>3</sup> |distance | No | No | | O(m*n) <sup>1</sup> |
4949
| [Jaro-Winkler](#jaro-winkler) |similarity<br>distance | Yes | No | | O(m*n) |
5050
| [Longest Common Subsequence](#longest-common-subsequence) |distance | No | No | | O(m*n) <sup>1,2</sup> |
5151
| [Metric Longest Common Subsequence](#metric-longest-common-subsequence) |distance | Yes | Yes | | O(m*n) <sup>1,2</sup> |
@@ -210,7 +210,30 @@ Will produce:
210210
6.0
211211
```
212212

213+
## Optimal-String-Alignment
214+
The Optimal String Alignment variant of Damerau–Levenshtein (sometimes called the restricted edit distance) computes the number of edit operations needed to make the strings equal under the condition that no substring is edited more than once, whereas the true Damerau–Levenshtein presents no such restriction.
213215

216+
Note that for the optimal string alignment distance, the triangle inequality does not hold and so it is not a true metric.
217+
218+
```java
219+
import info.debatty.java.stringsimilarity.*;
220+
221+
public class MyApp {
222+
223+
224+
public static void main(String[] args) {
225+
OptimalStringAlignment d = new OptimalStringAlignment();
226+
227+
System.out.println(osa.distance("CA", "ABC"));;
228+
}
229+
}
230+
```
231+
232+
Will produce:
233+
234+
```
235+
3.0
236+
```
214237

215238
## Jaro-Winkler
216239
Jaro-Winkler is a string edit distance that was developed in the area of record linkage (duplicate detection) (Winkler, 1990). The Jaro–Winkler distance metric is designed and best suited for short strings such as person names, and to detect typos.

src/main/java/info/debatty/java/stringsimilarity/OptimalStringAlignment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public final double distance(final String s1, final String s2) {
7878

7979
d[i][j] = min(
8080
d[i - 1][j - 1] + cost, // substitution
81-
d[i][j - 1] + 1, // insertion
82-
d[i - 1][j] + 1 // deletion
81+
d[i][j - 1] + 1, // insertion
82+
d[i - 1][j] + 1 // deletion
8383
);
8484

8585
//transposition check

src/main/java/info/debatty/java/stringsimilarity/examples/Examples.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ public static void main(String[] args) {
121121
// =======
122122
System.out.println("\nOptimal String Alignment");
123123
OptimalStringAlignment osa = new OptimalStringAlignment();
124-
124+
125+
//Will produce 3.0
125126
System.out.println(osa.distance("CA", "ABC"));
126127

127128

0 commit comments

Comments
 (0)