Scored implements Serializable { @SuppressWarnings("unchecked") public static <T extends Scored> List<T> makeUniform(List<T> terms) { if(terms.isEmpty()) return terms; ArrayList<T> result = new ArrayList<T>(terms.size()); for(T wt : terms) { result.add((T) wt.clone(1.0)); } return result; } Scored(double score); abstract Scored clone(double score); @SuppressWarnings("unchecked") static List<T> rmNormalizeScores(List<T> terms); @SuppressWarnings("unchecked") static List<T> makeUniform(List<T> terms); @SuppressWarnings("unchecked") static List<T> maxMinNormalize(List<T> terms); static List<T> normalize(String method, List<T> input); public double score; static Comparator<? super Scored> byScore; }
@Test public void makeUniformTest() { List<ScoredTerm> terms = Arrays.asList( new ScoredTerm("foo", 3.0), new ScoredTerm("bar", 2.0), new ScoredTerm("baz", 1.0) ); List<ScoredTerm> normalized = Scored.makeUniform(terms); assertEquals(1.0, normalized.get(0).score, CmpUtil.epsilon); assertEquals(1.0, normalized.get(1).score, CmpUtil.epsilon); assertEquals(1.0, normalized.get(2).score, CmpUtil.epsilon); }