
de.citec.tcs.alignment.ComparatorValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of algorithms Show documentation
Show all versions of algorithms Show documentation
This module defines the interface for AlignmentAlgorithms as well as some helper classes. An
AlignmentAlgorithm computes an Alignment of two given input sequences, given a Comparator that
works in these sequences.
More details on the AlignmentAlgorithm can be found in the respective interface. More information
on Comparators can be found in the comparators module.
The resulting 'Alignment' may be just a real-valued dissimilarity between the input sequence or
may incorporate additional information, such as a full Alignment, a PathList, a PathMap or a
CooptimalModel. If those results support the calculation of a Gradient, they implement the
DerivableAlignmentDistance interface.
In more detail, the Alignment class represents the result of a backtracing scheme, listing all
Operations that have been applied in one co-optimal Alignment.
A classic AlignmentAlgorithm does not result in a differentiable dissimilarity, because the
minimum function is not differentiable. Therefore, this package also contains utility functions
for a soft approximation of the minimum function, namely Softmin.
For faster (parallel) computation of many different alignments or gradients we also provide the
ParallelProcessingEngine, the SquareParallelProcessingEngine and the ParallelGradientEngine.
The newest version!
/*
* TCS Alignment Toolbox Version 3
*
* Copyright (C) 2016
* Benjamin Paaßen
* AG Theoretical Computer Science
* Centre of Excellence Cognitive Interaction Technology (CITEC)
* University of Bielefeld
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package de.citec.tcs.alignment;
import de.citec.tcs.alignment.comparators.Comparator;
import de.citec.tcs.alignment.comparators.OperationType;
import lombok.NonNull;
/**
* This class has the sole purpose to validate that a Comparator supports all OperationTypes an
* AlignmentAlgorithm requires.
*
* @author Benjamin Paassen - [email protected]
*/
public class ComparatorValidator {
private ComparatorValidator() {
}
/**
* Returns true if and only if the given Comparator supports all OperationType the given
* AlignmentAlgorithm requires.
*
* @param the class of elements in left-hand sequences for the given AlignmentAlgorithm.
* @param the class of elements in right-hand sequences for the given AlignmentAlgorithm.
* @param algorithm an AlignmentAlgorithm.
* @param comp a Comparator.
* @return true if and only if the given Comparator supports all OperationType the given
* AlignmentAlgorithm requires.
*/
public static boolean isValid(@NonNull AlignmentAlgorithm algorithm,
@NonNull Comparator extends X, ? extends Y> comp) {
return checkValidity(algorithm, comp) == null;
}
/**
* Checks whether the given Comparator supports all OperationType the given AlignmentAlgorithm
* requires and throws an IllegalArgumentException if it does not.
*
* @param the class of elements in left-hand sequences for the given AlignmentAlgorithm.
* @param the class of elements in right-hand sequences for the given AlignmentAlgorithm.
* @param algorithm an AlignmentAlgorithm.
* @param comp a Comparator.
* @throws IllegalArgumentException if at least one required OperationType is not supported by
* the given Comparator.
*/
public static void validate(@NonNull AlignmentAlgorithm algorithm,
@NonNull Comparator extends X, ? extends Y> comp) throws IllegalArgumentException {
final IllegalArgumentException ex = checkValidity(algorithm, comp);
if (ex != null) {
throw ex;
}
}
/**
* Checks whether the given Comparator supports all OperationType the given AlignmentAlgorithm
* requires and returns an IllegalArgumentException if it does not.
*
* @param the class of elements in left-hand sequences for the given AlignmentAlgorithm.
* @param the class of elements in right-hand sequences for the given AlignmentAlgorithm.
* @param algorithm an AlignmentAlgorithm.
* @param comp a Comparator.
* @return null if everything is fine and an IllegalArgumentException if at least one required
* OperationType is not supported by the given Comparator.
*/
public static IllegalArgumentException checkValidity(
@NonNull AlignmentAlgorithm algorithm, @NonNull Comparator extends X, ? extends Y> comp) {
for (final OperationType type : OperationType.values()) {
if (algorithm.requires(type) && !comp.supports(type)) {
return new IllegalArgumentException("The given algorithm of type "
+ algorithm.getClass().getName() + " requires OperationType " + type
+ " but the given comparator of type " + comp.getClass().getName()
+ " does not support that OperationType.");
}
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy