Cambridge SMT System
FeatureFunctions.java
Go to the documentation of this file.
1 /*******************************************************************************
2  * Licensed under the Apache License, Version 2.0 (the "License");
3  * you may not use these files except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  *
14  *******************************************************************************/
15 
16 package uk.ac.cam.eng.rule.features;
17 
18 import org.apache.hadoop.io.ByteWritable;
19 
20 import uk.ac.cam.eng.extraction.Rule;
22 
23 public final class FeatureFunctions {
24 
25  static final double[] one = new double[] { 1 };
26 
27  static final double[] minusOne = new double[] { -1 };
28 
29  static final double[] empty = new double[] { 0 };
30 
31  private static final ByteWritable zeroIndex = new ByteWritable((byte) 0);
32 
33 
34  static double[] ruleCount1(Rule r, FeatureFunctionInputData data) {
35  // 0 element is count over the entire data
36  int count = data.counts.get(zeroIndex)
37  .get();
38  if (count == 1) {
39  return one;
40  } else
41  return empty;
42  }
43 
44  static double[] ruleCount2(Rule r, FeatureFunctionInputData data) {
45  // 0 element is count over the entire data
46  int count = data.counts.get(zeroIndex)
47  .get();
48  if (count == 2) {
49  return one;
50  } else
51  return empty;
52  }
53 
54  static double[] ruleGreaterThan2(Rule r, FeatureFunctionInputData data) {
55  // 0 element is count over the entire data
56  int count = data.counts.get(zeroIndex)
57  .get();
58  if (count > 2) {
59  return one;
60  }
61  return empty;
62  }
63 
64  static double[] noOfWords(Rule r, FeatureFunctionInputData data) {
65  return new double[]{r.target().getWordCount()};
66  }
67 
68 }