Coverage Report - org.galagosearch.core.scoring.DistributionSmootherFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
DistributionSmootherFactory
0%
0/23
0%
0/14
0
 
 1  
 // BSD License (http://www.galagosearch.org/license)
 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  0
 public class DistributionSmootherFactory {
 15  
     public static DistributionSmoother newInstance(Map<String, String> feature, HashMap<String, Double> backgrounds) {
 16  0
         String smootherName = "dirichlet";
 17  
 
 18  0
         if (feature.containsKey("smoothing")) {
 19  0
             smootherName = feature.get("smoothing");
 20  
         }
 21  
 
 22  
         DistributionSmoother smoother;
 23  
 
 24  0
         if (smootherName.equals("linear") || smootherName.equals("jm")) {
 25  0
             double lambda = 0.4;
 26  0
             if (feature.containsKey("lambda")) {
 27  0
                 lambda = Double.parseDouble(feature.get("lambda"));
 28  
             }
 29  0
             smoother = new LinearSmoother(lambda, backgrounds);
 30  0
         } else {
 31  0
             double mu = 2500;
 32  0
             if (feature.containsKey("mu")) {
 33  0
                 mu = Double.parseDouble(feature.get("mu"));
 34  
             }
 35  0
             smoother = new DirichletSmoother(mu, backgrounds);
 36  
         }
 37  
 
 38  0
         return smoother;
 39  
     }
 40  
 
 41  
     public static DistributionSmoother newInstance(Parameters.Value feature, HashMap<String, Double> backgrounds) {
 42  0
         Set<String> keys = new HashSet<String>();
 43  0
         if (feature != null) {
 44  0
             keys = feature.map().keySet();
 45  
         }
 46  0
         HashMap<String, String> map = new HashMap();
 47  
 
 48  0
         for (String key : keys) {
 49  0
             map.put(key, feature.get(key));
 50  
         }
 51  
 
 52  0
         return newInstance(map, backgrounds);
 53  
     }
 54  
 
 55  
     public static DistributionSmoother newInstance(Parameters.Value feature) {
 56  0
         return newInstance(feature, new HashMap());
 57  
     }
 58  
 }