// Path: src/edu/stanford/nlp/semparse/open/dataset/Example.java
// public class Example {
//   public String displayId;  // For debugging
//   
//   public final String phrase;
//   public final ExpectedAnswer expectedAnswer;
//   public KNode tree;  // Deterministic function of the phrase
//   public List<CandidateGroup> candidateGroups;
//   public List<Candidate> candidates;  // Candidate predictions
//   public AveragedWordVector averagedWordVector;
// 
//   public Example(String phrase) {
//     this(phrase, null);
//   }
//   
//   public Example(String phrase, ExpectedAnswer expectedAnswer) {
//     this.phrase = phrase;
//     this.expectedAnswer = expectedAnswer;
//   }
//   
//   @Override public String toString() {
//     return "[" + phrase + "]";
//   }
//   
//   public void initAveragedWordVector() {
//     if (averagedWordVector == null)
//       averagedWordVector = new AveragedWordVector(phrase);
//   }
// }
// 
// Path: src/edu/stanford/nlp/semparse/open/model/candidate/Candidate.java
// public class Candidate {
//   public final Example ex;
//   public final CandidateGroup group;
//   public final TreePattern pattern;
//   public final List<String> predictedEntities;
//   public FeatureVector features;
//   
//   public Candidate(CandidateGroup group, TreePattern pattern) {
//     this.pattern = pattern;
//     this.group = group;
//     group.candidates.add(this);
//     // Perform shallow copy
//     this.ex = group.ex;
//     this.predictedEntities = group.predictedEntities;
//   }
//   
//   public int numEntities() {
//     return group.numEntities();
//   }
//   
//   public double getReward() {
//     return group.ex.expectedAnswer.reward(this);
//   }
//   
//   public Map<String, Double> getCombinedFeatures() {
//     Map<String, Double> map = new HashMap<>();
//     features.increment(1, map);
//     group.features.increment(1, map);
//     return map;
//   }
//   
//   // ============================================================
//   // Debug Print
//   // ============================================================
//   
//   public String sampleEntities() {
//     return group.sampleEntities();
//   }
//   
//   public String allEntities() {
//     return group.allEntities();
//   }
// }
// 
// Path: src/edu/stanford/nlp/semparse/open/util/Multiset.java
// public class Multiset<T> {
//   protected final HashMap<T, Integer> map = new HashMap<>();
//   protected int size = 0;
// 
//   public void add(T entry) {
//     Integer count = map.get(entry);
//     if (count == null)
//       count = 0;
//     map.put(entry, count + 1);
//     size++;
//   }
//   
//   public void add(T entry, int incr) {
//     Integer count = map.get(entry);
//     if (count == null)
//       count = 0;
//     map.put(entry, count + incr);
//     size += incr;
//   }
// 
//   public boolean contains(T entry) {
//     return map.containsKey(entry);
//   }
// 
//   public int count(T entry) {
//     Integer count = map.get(entry);
//     if (count == null)
//       count = 0;
//     return count;
//   }
// 
//   public Set<T> elementSet() {
//     return map.keySet();
//   }
// 
//   public Set<Map.Entry<T, Integer>> entrySet() {
//     return map.entrySet();
//   }
// 
//   public int size() {
//     return size;
//   }
// 
//   public boolean isEmpty() {
//     return size == 0;
//   }
//   
//   public Multiset<T> getPrunedByCount(int minCount) {
//     Multiset<T> pruned = new Multiset<>();
//     for (Map.Entry<T, Integer> entry : map.entrySet()) {
//       if (entry.getValue() >= minCount)
//         pruned.add(entry.getKey(), entry.getValue());
//     }
//     return pruned;
//   }
// }


import java.util.*;
import edu.stanford.nlp.semparse.open.dataset.Example;
import edu.stanford.nlp.semparse.open.model.candidate.Candidate;
import edu.stanford.nlp.semparse.open.util.Multiset;
import fig.basic.LogInfo;
package edu.stanford.nlp.semparse.open.model;



public class FeatureCountPruner implements FeatureMatcher {

  public Multiset<String> counts = new Multiset<>();
  public boolean beVeryQuiet;
  
  public FeatureCountPruner(boolean beVeryQuiet) {
    this.beVeryQuiet = beVeryQuiet;
  }
  
  /**
   * Add features from the example to the count.
   * 
   * The same feature within the same example counts as 1 feature.
   */
// Path: src/edu/stanford/nlp/semparse/open/dataset/Example.java
// public class Example {
//   public String displayId;  // For debugging
//   
//   public final String phrase;
//   public final ExpectedAnswer expectedAnswer;
//   public KNode tree;  // Deterministic function of the phrase
//   public List<CandidateGroup> candidateGroups;
//   public List<Candidate> candidates;  // Candidate predictions
//   public AveragedWordVector averagedWordVector;
// 
//   public Example(String phrase) {
//     this(phrase, null);
//   }
//   
//   public Example(String phrase, ExpectedAnswer expectedAnswer) {
//     this.phrase = phrase;
//     this.expectedAnswer = expectedAnswer;
//   }
//   
//   @Override public String toString() {
//     return "[" + phrase + "]";
//   }
//   
//   public void initAveragedWordVector() {
//     if (averagedWordVector == null)
//       averagedWordVector = new AveragedWordVector(phrase);
//   }
// }
// 
// Path: src/edu/stanford/nlp/semparse/open/model/candidate/Candidate.java
// public class Candidate {
//   public final Example ex;
//   public final CandidateGroup group;
//   public final TreePattern pattern;
//   public final List<String> predictedEntities;
//   public FeatureVector features;
//   
//   public Candidate(CandidateGroup group, TreePattern pattern) {
//     this.pattern = pattern;
//     this.group = group;
//     group.candidates.add(this);
//     // Perform shallow copy
//     this.ex = group.ex;
//     this.predictedEntities = group.predictedEntities;
//   }
//   
//   public int numEntities() {
//     return group.numEntities();
//   }
//   
//   public double getReward() {
//     return group.ex.expectedAnswer.reward(this);
//   }
//   
//   public Map<String, Double> getCombinedFeatures() {
//     Map<String, Double> map = new HashMap<>();
//     features.increment(1, map);
//     group.features.increment(1, map);
//     return map;
//   }
//   
//   // ============================================================
//   // Debug Print
//   // ============================================================
//   
//   public String sampleEntities() {
//     return group.sampleEntities();
//   }
//   
//   public String allEntities() {
//     return group.allEntities();
//   }
// }
// 
// Path: src/edu/stanford/nlp/semparse/open/util/Multiset.java
// public class Multiset<T> {
//   protected final HashMap<T, Integer> map = new HashMap<>();
//   protected int size = 0;
// 
//   public void add(T entry) {
//     Integer count = map.get(entry);
//     if (count == null)
//       count = 0;
//     map.put(entry, count + 1);
//     size++;
//   }
//   
//   public void add(T entry, int incr) {
//     Integer count = map.get(entry);
//     if (count == null)
//       count = 0;
//     map.put(entry, count + incr);
//     size += incr;
//   }
// 
//   public boolean contains(T entry) {
//     return map.containsKey(entry);
//   }
// 
//   public int count(T entry) {
//     Integer count = map.get(entry);
//     if (count == null)
//       count = 0;
//     return count;
//   }
// 
//   public Set<T> elementSet() {
//     return map.keySet();
//   }
// 
//   public Set<Map.Entry<T, Integer>> entrySet() {
//     return map.entrySet();
//   }
// 
//   public int size() {
//     return size;
//   }
// 
//   public boolean isEmpty() {
//     return size == 0;
//   }
//   
//   public Multiset<T> getPrunedByCount(int minCount) {
//     Multiset<T> pruned = new Multiset<>();
//     for (Map.Entry<T, Integer> entry : map.entrySet()) {
//       if (entry.getValue() >= minCount)
//         pruned.add(entry.getKey(), entry.getValue());
//     }
//     return pruned;
//   }
// }


// Path: src/edu/stanford/nlp/semparse/open/model/FeatureCountPruner.java
import java.util.*;
import edu.stanford.nlp.semparse.open.dataset.Example;
import edu.stanford.nlp.semparse.open.model.candidate.Candidate;
import edu.stanford.nlp.semparse.open.util.Multiset;
import fig.basic.LogInfo;

package edu.stanford.nlp.semparse.open.model;



public class FeatureCountPruner implements FeatureMatcher {

  public Multiset<String> counts = new Multiset<>();
  public boolean beVeryQuiet;
  
  public FeatureCountPruner(boolean beVeryQuiet) {
    this.beVeryQuiet = beVeryQuiet;
  }
  
  /**
   * Add features from the example to the count.
   * 
   * The same feature within the same example counts as 1 feature.
   */
  public void add(Example example) {