code: package edu.jhu.thrax.hadoop.features;
  
  import java.util.Map;
  
  import org.apache.hadoop.io.IntWritable;
  import org.apache.hadoop.io.Writable;
  
  import edu.jhu.thrax.hadoop.datatypes.RuleWritable;
  import edu.jhu.thrax.util.Vocabulary;
  
  public class XRuleFeature implements SimpleFeature {
  
    public static final String NAME = "x_rule";
  
    private static final IntWritable ZERO = new IntWritable(0);
    private static final IntWritable ONE = new IntWritable(1);
  
    // TODO: should be default nonterminal and not explicitly X.
    private final int PATTERN = Vocabulary.id("[X]");
  
    public Writable score(RuleWritable r) {
      return (r.lhs == PATTERN ? ONE : ZERO);
    }
  
    public String getName() {
      return NAME;
    }
  
    public void unaryGlueRuleScore(int nt, Map<Integer, Writable> map) {
      map.put(Vocabulary.id(NAME), ZERO);
    }
  
    public void binaryGlueRuleScore(int nt, Map<Integer, Writable> map) {
      map.put(Vocabulary.id(NAME), ZERO);
    }
  }
  