1
2 package org.galagosearch.core.scoring;
3
4 import java.util.HashMap;
5 import java.util.HashSet;
6 import java.util.Map;
7 import java.util.Set;
8 import org.galagosearch.tupleflow.Parameters;
9
10 /***
11 *
12 * @author trevor
13 */
14 public class DistributionSmootherFactory {
15 public static DistributionSmoother newInstance(Map<String, String> feature, HashMap<String, Double> backgrounds) {
16 String smootherName = "dirichlet";
17
18 if (feature.containsKey("smoothing")) {
19 smootherName = feature.get("smoothing");
20 }
21
22 DistributionSmoother smoother;
23
24 if (smootherName.equals("linear") || smootherName.equals("jm")) {
25 double lambda = 0.4;
26 if (feature.containsKey("lambda")) {
27 lambda = Double.parseDouble(feature.get("lambda"));
28 }
29 smoother = new LinearSmoother(lambda, backgrounds);
30 } else {
31 double mu = 2500;
32 if (feature.containsKey("mu")) {
33 mu = Double.parseDouble(feature.get("mu"));
34 }
35 smoother = new DirichletSmoother(mu, backgrounds);
36 }
37
38 return smoother;
39 }
40
41 public static DistributionSmoother newInstance(Parameters.Value feature, HashMap<String, Double> backgrounds) {
42 Set<String> keys = new HashSet<String>();
43 if (feature != null) {
44 keys = feature.map().keySet();
45 }
46 HashMap<String, String> map = new HashMap();
47
48 for (String key : keys) {
49 map.put(key, feature.get(key));
50 }
51
52 return newInstance(map, backgrounds);
53 }
54
55 public static DistributionSmoother newInstance(Parameters.Value feature) {
56 return newInstance(feature, new HashMap());
57 }
58 }