eu.semaine.util
Class FuzzySort
java.lang.Object
eu.semaine.util.FuzzySort
public class FuzzySort
- extends java.lang.Object
This class implements an approximate sort operation on data for which only the following information is known:
- direct order relations between pairs of items, as in "a wants to be a direct successor of b";
- absolute positions at the ends of the chain, as in "a is initial" or "b is final"
.
The class computes a mean square error approximation of the solution.
- Author:
- marc
Method Summary |
static java.util.List<java.util.Set<FuzzySort.FuzzySortable>> |
sort(java.util.Set<FuzzySort.FuzzySortableRelation> relations,
boolean enforceInitialFinal)
For a set of relations between fuzzy sortables, attempt to come up with a reasonable ordering despite circular orderings etc. |
static java.util.List<java.util.Set<FuzzySort.FuzzySortable>> |
sort(java.util.Set<FuzzySort.FuzzySortableRelation> relations,
boolean enforceInitialFinal,
double threshold)
For a set of relations between fuzzy sortables, attempt to come up with a reasonable ordering despite circular orderings etc. |
static java.lang.String |
toString(java.util.List<java.util.Set<FuzzySort.FuzzySortable>> sortedResults)
Convert the sorted results into a human-readable string. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
FuzzySort
public FuzzySort()
sort
public static java.util.List<java.util.Set<FuzzySort.FuzzySortable>> sort(java.util.Set<FuzzySort.FuzzySortableRelation> relations,
boolean enforceInitialFinal)
- For a set of relations between fuzzy sortables, attempt to come up with a reasonable ordering despite circular orderings etc.
A heuristic will be used to determine the threshold below which two items will be considered to be "equal" with respect to sorting.
- Parameters:
relations
- a non-null, non-empty set of relationsenforceInitialFinal
- whether to interpret the initial/final requests by FuzzySortable as a soft or a hard constraint.
If set to true, we guarantee that the first set in the returned list contains all initial items, and the last set in the list contains all final items.
- Returns:
- a non-null, non-empty set of non-null, non-empty sets of sortables.
- Throws:
NullPointerException,
- IllegalArgumentException if relations is null or empty
sort
public static java.util.List<java.util.Set<FuzzySort.FuzzySortable>> sort(java.util.Set<FuzzySort.FuzzySortableRelation> relations,
boolean enforceInitialFinal,
double threshold)
- For a set of relations between fuzzy sortables, attempt to come up with a reasonable ordering despite circular orderings etc.
- Parameters:
relations
- a non-null, non-empty set of relationsenforceInitialFinal
- whether to interpret the initial/final requests by FuzzySortable as a soft or a hard constraint.
If set to true, we guarantee that the first set in the returned list contains all initial items, and the last set in the list contains all final items.threshold
- the threshold below which two sortables are considered equal, given that each relation represents a requested distance of 1.
This must be a non-negative value, or Float.NaN. If a value of 0 is given, a very small threshold is used; if NaN is given, a heuristic threshold is computed.
- Returns:
- a non-null, non-empty set of non-null, non-empty sets of sortables.
- Throws:
NullPointerException,
- IllegalArgumentException if relations is null or empty, or if threshold is invalid
toString
public static java.lang.String toString(java.util.List<java.util.Set<FuzzySort.FuzzySortable>> sortedResults)
- Convert the sorted results into a human-readable string. Each line contains one set of sortables;
items in each line are separated by a white space character.
- Parameters:
sortedResults
- non-null, non-empty list of non-null, non-empty sets of fuzzy sortables
- Returns:
- a non-null string representing sortedResult
- Throws:
IllegalArgumentException,
- NullPointerException when the parameter is not conformant