16 package uk.ac.cam.eng.rule.features;
18 import java.util.HashMap;
20 import java.util.function.BiFunction;
38 static class FeatureFunctionInputData {
50 private FeatureFunctionInputData() {
58 this.requested = requested;
65 private static ThreadLocal<FeatureFunctionInputData> ffInput =
new ThreadLocal<FeatureFunctionInputData>(){
68 protected FeatureFunctionInputData initialValue() {
69 return new FeatureFunctionInputData();
75 private static Map<Feature, BiFunction<Rule, FeatureFunctionInputData, double[]>> featureFunctions =
new HashMap<>();
77 static double[] computeFeature(
Feature feature, Rule rule,
79 if (ComputeLocation.MAP_REDUCE == feature.
computed) {
80 throw new UnsupportedOperationException(
81 "Attempting to compute the MapReduce featue: " 84 BiFunction<Rule, FeatureFunctionInputData, double[]> f
85 = featureFunctions.get(feature);
89 return f.apply(
new Rule(rule), ffInput.get().build(data, feature, fReg));
93 private static void registerFunction(
Feature f,
94 BiFunction<Rule, FeatureFunctionInputData,
double[]> ff) {
96 throw new UnsupportedOperationException(
97 "Trying to register feature functions for a non-retrieval time feature");
99 featureFunctions.put(f, ff);
107 FeatureFunctions::ruleCount1);
109 FeatureFunctions::ruleCount2);
112 FeatureFunctions::noOfWords);
RULE_COUNT_GREATER_THAN_2