Package nzilbb.editpath
Class DefaultEditComparator<T>
- java.lang.Object
-
- nzilbb.editpath.DefaultEditComparator<T>
-
- All Implemented Interfaces:
EditComparator<T>
public class DefaultEditComparator<T> extends Object implements EditComparator<T>
Default implementation of IEditComparator, for which any from/to pair for which equals() is not true is given an edit distance ofgetChangeDistance().- Author:
- Robert Fromont robert@fromont.net.nz
-
-
Constructor Summary
Constructors Constructor Description DefaultEditComparator()Default constructorDefaultEditComparator(int insertDeleteChangeDistance)ConstructorDefaultEditComparator(int insertDistance, int deleteDistance, int changeDistance)ConstructorDefaultEditComparator(Comparator<T> comparator)Constructor with custom comparator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EditStep<T>compare(T from, T to)EditComparatormethod: Compares two sequence elements, and evaluates the distance between them.EditStep<T>delete(T from)The distance for deleting the given element.intgetChangeDistance()Getter foriChangeDistance: The distance represented by a change.Comparator<T>getComparator()Getter forcomparator: A comparator to use to determin equality, or null to use java.util.Object.equals(Object).intgetDeleteDistance()Getter foriDeleteDistance: The distance represented by a deletion.intgetInsertDistance()Getter foriInsertDistance: The distance represented by an insertion.EditStep<T>insert(T to)The distance for inserting the given element.DefaultEditComparator<T>setChangeDistance(int iNewChangeDistance)Setter foriChangeDistance: The distance represented by a change.DefaultEditComparator<T>setComparator(Comparator<T> newComparator)Setter forcomparator: A comparator to use to determin equality, or null to use java.util.Object.equals(Object).DefaultEditComparator<T>setDeleteDistance(int iNewDeleteDistance)Setter foriDeleteDistance: The distance represented by a deletion.DefaultEditComparator<T>setInsertDistance(int iNewInsertDistance)Setter foriInsertDistance: The distance represented by an insertion.
-
-
-
Constructor Detail
-
DefaultEditComparator
public DefaultEditComparator()
Default constructor
-
DefaultEditComparator
public DefaultEditComparator(Comparator<T> comparator)
Constructor with custom comparator.- Parameters:
comparator- The custom comparator.
-
DefaultEditComparator
public DefaultEditComparator(int insertDeleteChangeDistance)
Constructor- Parameters:
insertDeleteChangeDistance- The distance applied to an insert, delete, or change.
-
DefaultEditComparator
public DefaultEditComparator(int insertDistance, int deleteDistance, int changeDistance)Constructor- Parameters:
insertDistance- The distance applied to an insertion.deleteDistance- The distance applied to a deletion.changeDistance- The distance applied to a change.
-
-
Method Detail
-
getChangeDistance
public int getChangeDistance()
Getter foriChangeDistance: The distance represented by a change.- Returns:
- The distance represented by a change.
-
setChangeDistance
public DefaultEditComparator<T> setChangeDistance(int iNewChangeDistance)
Setter foriChangeDistance: The distance represented by a change.- Parameters:
iNewChangeDistance- The distance represented by a change.
-
getDeleteDistance
public int getDeleteDistance()
Getter foriDeleteDistance: The distance represented by a deletion.- Returns:
- The distance represented by a deletion.
-
setDeleteDistance
public DefaultEditComparator<T> setDeleteDistance(int iNewDeleteDistance)
Setter foriDeleteDistance: The distance represented by a deletion.- Parameters:
iNewDeleteDistance- The distance represented by a deletion.
-
getInsertDistance
public int getInsertDistance()
Getter foriInsertDistance: The distance represented by an insertion.- Returns:
- The distance represented by an insertion.
-
setInsertDistance
public DefaultEditComparator<T> setInsertDistance(int iNewInsertDistance)
Setter foriInsertDistance: The distance represented by an insertion.- Parameters:
iNewInsertDistance- The distance represented by an insertion.
-
getComparator
public Comparator<T> getComparator()
Getter forcomparator: A comparator to use to determin equality, or null to use java.util.Object.equals(Object).- Returns:
- A comparator to use to determin equality, or null to use java.util.Object.equals(Object).
-
setComparator
public DefaultEditComparator<T> setComparator(Comparator<T> newComparator)
Setter forcomparator: A comparator to use to determin equality, or null to use java.util.Object.equals(Object).- Parameters:
newComparator- A comparator to use to determine equality, or null to use java.util.Object.equals(Object).
-
compare
public EditStep<T> compare(T from, T to)
EditComparatormethod: Compares two sequence elements, and evaluates the distance between them.- Specified by:
comparein interfaceEditComparator<T>- Parameters:
from- The element from the source sequence, which may be null.to- The element from the destination sequence, which may be null.- Returns:
- An edit step between the two elements.
EditStep.getFrom()is set to from,EditStep.getTo()is set to to,EditStep.getStepDistance()is set to the computed edit distance between these two elements, andEditStep.getOperation()is set to either EditStep.StepOperation.NONE or EditStep.StepOperation.CHANGE.
-
delete
public EditStep<T> delete(T from)
The distance for deleting the given element.- Specified by:
deletein interfaceEditComparator<T>- Parameters:
from- The element that would be deleted, which may be null.- Returns:
- An edit step with
EditStep.getStepDistance()set to the distance for deleting the given element.EditStep.getFrom()is set to from, andEditStep.getOperation()is set to EditStep.StepOperation.DELETE
-
insert
public EditStep<T> insert(T to)
The distance for inserting the given element.- Specified by:
insertin interfaceEditComparator<T>- Parameters:
to- The element that would be inserted, which may be null.- Returns:
- An edit step with
EditStep.getStepDistance()set to the distance for inserting the given element.EditStep.getTo()is set to to, andEditStep.getOperation()is set to EditStep.StepOperation.INSERT
-
-