Skip to content

Commit 5e26bcf

Browse files
authored
Merge pull request #343 from cicirello/deprecate
Deprecated double-valued costs constructor of EditDistance for arrays and other sequences
2 parents 24362ac + 74b0531 commit 5e26bcf

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased] - 2023-05-15
7+
## [Unreleased] - 2023-05-30
88

99
### Added
1010

1111
### Changed
1212

1313
### Deprecated
14+
* Deprecated double-valued costs constructor of EditDistance for arrays and other sequences, with the existing EditDistanceDouble class as its replacement. This constructor will be removed in the next major release, most likely sometime in the Fall of 2023.
1415

1516
### Removed
1617

src/main/java/org/cicirello/sequences/distance/EditDistance.java

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JavaPermutationTools: A Java library for computation on permutations and sequences
3-
* Copyright 2005-2022 Vincent A. Cicirello, <https://www.cicirello.org/>.
3+
* Copyright 2005-2023 Vincent A. Cicirello, <https://www.cicirello.org/>.
44
*
55
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
66
*
@@ -29,17 +29,13 @@
2929
*
3030
* <p>Edit distance is the minimum cost to transform one string (or sequence) into the other, which
3131
* is the sum of the costs of the edit operations necessary to do so. This edit distance considers 3
32-
* edit operations: Inserts which insert a new element into the sequence, Deletes which remove an
32+
* edit operations: Inserts which inserts a new element into the sequence, Deletes which removes an
3333
* element from the sequence, and Changes which replace an element with a different element.
3434
*
35-
* <p>The edit distance is parameterized by costs for the edit operations. We provide two
36-
* constructors which enable you to specify 3 costs, 1 for each type of edit operation. One of the
37-
* constructors expects integer costs, and the other double valued costs. If you specify costs as
38-
* integers, then all of the distance and distancef methods from the {@link
39-
* org.cicirello.sequences.distance.SequenceDistanceMeasurer SequenceDistanceMeasurer} and {@link
40-
* org.cicirello.sequences.distance.SequenceDistanceMeasurerDouble SequenceDistanceMeasurerDouble}
41-
* interfaces are available. If costs are specified as doubles, then only the distancef methods will
42-
* function, while the distance methods will throw exceptions.
35+
* <p>The edit distance is parameterized by costs for the edit operations. The class provides a
36+
* constructor which enables you to specify 3 costs as ints, 1 for each type of edit operation. If
37+
* your application requires non-integer costs, then use the {@link EditDistanceDouble} class which
38+
* defines the costs as doubles, but is otherwise an implementation of the same algorithm.
4339
*
4440
* <p>This class supports computing EditDistance for Java String objects or arrays of any of the
4541
* primitive types, or arrays of objects. It makes no assumptions about the contents of the Strings
@@ -80,7 +76,9 @@ public class EditDistance extends EditDistanceDouble implements SequenceDistance
8076
* @param deleteCost Cost of an deletion operation. Must be non-negative.
8177
* @param changeCost Cost of an change operation. Must be non-negative.
8278
* @throws IllegalArgumentException if any of the costs are negative.
79+
* @deprecated For double-valued costs, use the {@link EditDistanceDouble} class instead.
8380
*/
81+
@Deprecated
8482
public EditDistance(double insertCost, double deleteCost, double changeCost) {
8583
super(insertCost, deleteCost, changeCost);
8684
if (isIntAsDouble(insertCost) && isIntAsDouble(deleteCost) && isIntAsDouble(changeCost)) {
@@ -95,8 +93,7 @@ public EditDistance(double insertCost, double deleteCost, double changeCost) {
9593
}
9694

9795
/**
98-
* Constructs an edit distance measure with the specified edit operation costs. With integer
99-
* costs, all of the distance and distancef methods are available.
96+
* Constructs an edit distance measure with the specified edit operation costs.
10097
*
10198
* @param insertCost Cost of an insertion operation. Must be non-negative.
10299
* @param deleteCost Cost of an deletion operation. Must be non-negative.

src/main/java/org/cicirello/sequences/distance/EditDistanceDouble.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JavaPermutationTools: A Java library for computation on permutations and sequences
3-
* Copyright 2005-2022 Vincent A. Cicirello, <https://www.cicirello.org/>.
3+
* Copyright 2005-2023 Vincent A. Cicirello, <https://www.cicirello.org/>.
44
*
55
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
66
*
@@ -26,9 +26,8 @@
2626
/**
2727
* EditDistanceDouble is an implementation of Wagner and Fischer's dynamic programming algorithm for
2828
* computing string edit distance. This class supports double-valued costs, while the {@link
29-
* EditDistance} class supports both double-valued as well as int-valued costs. If your costs are
30-
* int-valued, the {@link EditDistance} class may be slightly faster, but not asymptotically faster.
31-
* If your costs are double-valued, there should be no difference (one is a subclass of the other).
29+
* EditDistance} class supports int-valued costs. If your costs are int-valued, the {@link
30+
* EditDistance} class may be slightly faster, but not asymptotically faster.
3231
*
3332
* <p>Edit distance is the minimum cost to transform one string (or sequence) into the other, which
3433
* is the sum of the costs of the edit operations necessary to do so. This edit distance considers 3

src/main/java/org/cicirello/sequences/distance/LongestCommonSubsequenceDistance.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JavaPermutationTools: A Java library for computation on permutations and sequences
3-
* Copyright 2005-2022 Vincent A. Cicirello, <https://www.cicirello.org/>.
3+
* Copyright 2005-2023 Vincent A. Cicirello, <https://www.cicirello.org/>.
44
*
55
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
66
*
@@ -42,7 +42,7 @@
4242
* length, common set of elements, and unique elements properties of permutations to more
4343
* efficiently (in O(n lg n) time) compute the longest common subpermutation (i.e., that class does
4444
* not delegate the work to the edit distance algorithm). However, the result of ReinsertionDistance
45-
* is half of what LongestCommonSunsequenceDistance would compute. This is because for permutations
45+
* is half of what LongestCommonSubsequenceDistance would compute. This is because for permutations
4646
* the elements that would be inserted are exactly the same as those that would be deleted by the
4747
* edit operations, and ReinsertionDistance is defined as an edit distance with one edit operation,
4848
* removal/reinsertion (i.e., a deletion is only half the operation, and the insertion is the other

src/test/java/org/cicirello/sequences/distance/EditDistanceTests.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2022 Vincent A. Cicirello, <https://www.cicirello.org/>.
2+
* Copyright 2018-2023 Vincent A. Cicirello, <https://www.cicirello.org/>.
33
*
44
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
55
*
@@ -30,6 +30,7 @@
3030
public class EditDistanceTests extends InternalTestHelpersSequenceDistance {
3131

3232
@Test
33+
@SuppressWarnings("deprecation")
3334
public void testEditDistanceExceptions() {
3435
final EditDistance d = new EditDistance(1.5, 1.5, 1.5);
3536
UnsupportedOperationException thrown =
@@ -118,6 +119,7 @@ public void testEditObjectSequences() {
118119
}
119120

120121
@Test
122+
@SuppressWarnings("deprecation")
121123
public void testIdentical() {
122124
EditDistance d = new EditDistance(1, 2, 10);
123125
identicalSequences(d);
@@ -145,6 +147,7 @@ public void testIdentical() {
145147
}
146148

147149
@Test
150+
@SuppressWarnings("deprecation")
148151
public void testEditDistance() {
149152
int cost_i = 1;
150153
int cost_d = 1;

0 commit comments

Comments
 (0)