// Path: src/edu/stanford/nlp/semparse/open/dataset/entity/TargetEntity.java
// public interface TargetEntity {
//   public boolean match(String predictedEntity);
//   public boolean matchAny(Collection<String> predictedEntities);
// }
// 
// Path: src/edu/stanford/nlp/semparse/open/dataset/entity/TargetEntityPersonName.java
// public class TargetEntityPersonName implements TargetEntity {
//   
//   public final String first;
//   public final String mid;
//   public final String last;
//   final List<String> patterns = new ArrayList<>();
//   
//   public TargetEntityPersonName(String first, String last) {
//     this.first = first;
//     this.mid = null;
//     this.last = last;
//     generatePatterns();
//   }
//   
//   public TargetEntityPersonName(String first, String mid, String last) {
//     this.first = first;
//     if (mid.length() == 2 && mid.charAt(1) == '.')
//       this.mid = mid.substring(0, 1);
//     else
//       this.mid = mid;
//     this.last = last;
//     generatePatterns();
//   }
//   
//   private void generatePatterns() {
//     patterns.add(first + " " + last);
//     patterns.add(last + ", " + first);
//     patterns.add(first.charAt(0) + ". " + last);
//     patterns.add(last + ", " + first.charAt(0) + ".");
//     if (mid != null) {
//       if (mid.length() > 1) {
//         patterns.add(first + " " + mid + " " + last);
//         patterns.add(last + ", " + first + " " + mid);
//       }
//       patterns.add(first + " " + mid.charAt(0) + ". " + last);
//       patterns.add(last + ", " + first + " " + mid.charAt(0) + ".");
//     }
//   }
//   
//   @Override
//   public String toString() {
//     if (mid != null)
//       return first + " " + mid + " " + last;
//     return first + " " + last;
//   }
// 
//   @Override
//   public boolean match(String predictedEntity) {
//     for (String pattern : patterns)
//       if (pattern.equals(predictedEntity)) return true;
//     return false;
//   }
// 
//   @Override
//   public boolean matchAny(Collection<String> predictedEntities) {
//     for (String pattern : patterns)
//       if (predictedEntities.contains(pattern)) return true;
//     return false;
//   }
// 
// }
// 
// 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();
//   }
// }


import java.util.*;
import edu.stanford.nlp.semparse.open.dataset.entity.TargetEntity;
import edu.stanford.nlp.semparse.open.dataset.entity.TargetEntityPersonName;
import edu.stanford.nlp.semparse.open.model.candidate.Candidate;
import fig.basic.LogInfo;
  // ============================================================
  // Shorthands for creating datasets.
  // ============================================================
  
  public Example E(String phrase, ExpectedAnswer expectedAnswer) {
    return E(phrase, expectedAnswer, true);
  }
  
  public Example E(String phrase, ExpectedAnswer expectedAnswer, boolean isTrain) {
    Example ex = new Example(phrase, expectedAnswer);
    if (isTrain)
      addTrainExample(ex);
    else
      addTestExample(ex);
    return ex;
  }
  
  public ExpectedAnswer L(String... items) {
    return L(false, items);
  }
  
  public ExpectedAnswer L(boolean exact, String... items) {
    return new ExpectedAnswerInjectiveMatch(items);
  }
  
  public ExpectedAnswer LN(String... items) {
    return LN(false, items);
  }
  
  public ExpectedAnswer LN(boolean exact, String... items) {
// Path: src/edu/stanford/nlp/semparse/open/dataset/entity/TargetEntity.java
// public interface TargetEntity {
//   public boolean match(String predictedEntity);
//   public boolean matchAny(Collection<String> predictedEntities);
// }
// 
// Path: src/edu/stanford/nlp/semparse/open/dataset/entity/TargetEntityPersonName.java
// public class TargetEntityPersonName implements TargetEntity {
//   
//   public final String first;
//   public final String mid;
//   public final String last;
//   final List<String> patterns = new ArrayList<>();
//   
//   public TargetEntityPersonName(String first, String last) {
//     this.first = first;
//     this.mid = null;
//     this.last = last;
//     generatePatterns();
//   }
//   
//   public TargetEntityPersonName(String first, String mid, String last) {
//     this.first = first;
//     if (mid.length() == 2 && mid.charAt(1) == '.')
//       this.mid = mid.substring(0, 1);
//     else
//       this.mid = mid;
//     this.last = last;
//     generatePatterns();
//   }
//   
//   private void generatePatterns() {
//     patterns.add(first + " " + last);
//     patterns.add(last + ", " + first);
//     patterns.add(first.charAt(0) + ". " + last);
//     patterns.add(last + ", " + first.charAt(0) + ".");
//     if (mid != null) {
//       if (mid.length() > 1) {
//         patterns.add(first + " " + mid + " " + last);
//         patterns.add(last + ", " + first + " " + mid);
//       }
//       patterns.add(first + " " + mid.charAt(0) + ". " + last);
//       patterns.add(last + ", " + first + " " + mid.charAt(0) + ".");
//     }
//   }
//   
//   @Override
//   public String toString() {
//     if (mid != null)
//       return first + " " + mid + " " + last;
//     return first + " " + last;
//   }
// 
//   @Override
//   public boolean match(String predictedEntity) {
//     for (String pattern : patterns)
//       if (pattern.equals(predictedEntity)) return true;
//     return false;
//   }
// 
//   @Override
//   public boolean matchAny(Collection<String> predictedEntities) {
//     for (String pattern : patterns)
//       if (predictedEntities.contains(pattern)) return true;
//     return false;
//   }
// 
// }
// 
// 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/dataset/Dataset.java
import java.util.*;
import edu.stanford.nlp.semparse.open.dataset.entity.TargetEntity;
import edu.stanford.nlp.semparse.open.dataset.entity.TargetEntityPersonName;
import edu.stanford.nlp.semparse.open.model.candidate.Candidate;
import fig.basic.LogInfo;

  // ============================================================
  // Shorthands for creating datasets.
  // ============================================================
  
  public Example E(String phrase, ExpectedAnswer expectedAnswer) {
    return E(phrase, expectedAnswer, true);
  }
  
  public Example E(String phrase, ExpectedAnswer expectedAnswer, boolean isTrain) {
    Example ex = new Example(phrase, expectedAnswer);
    if (isTrain)
      addTrainExample(ex);
    else
      addTestExample(ex);
    return ex;
  }
  
  public ExpectedAnswer L(String... items) {
    return L(false, items);
  }
  
  public ExpectedAnswer L(boolean exact, String... items) {
    return new ExpectedAnswerInjectiveMatch(items);
  }
  
  public ExpectedAnswer LN(String... items) {
    return LN(false, items);
  }
  
  public ExpectedAnswer LN(boolean exact, String... items) {
    TargetEntity[] targetEntities = new TargetEntity[items.length];