nus-yam/ex-repair huggingface dataset:
Program: 131514
Project: 131514
Buggy source:
@Test public void testExcludeUnsupportedFeatures(){
  FeatureTemplateList fts=getFtl();
  FgExamples data=new FgExamples(fts);
  data.add(getExForFts("String_Node_Str","String_Node_Str",fts));
  data.add(getExForFts("String_Node_Str","String_Node_Str",fts));
  data.add(getExForFts("String_Node_Str","String_Node_Str",fts));
  data.add(getExForFts("String_Node_Str","String_Node_Str",fts));
  FgModel model1=new FgModel(data,true);
  System.out.println("String_Node_Str" + model1);
  assertEquals(20,model1.getNumParams());
  FgModel model2=new FgModel(data,false);
  System.out.println("String_Node_Str" + model2);
  assertEquals(6 + 4,model2.getNumParams());
}

Fixed version (ground truth):
@Test public void testExcludeUnsupportedFeatures(){
  boolean useLat=false;
  FeatureTemplateList fts=getFtl(useLat);
  FgExamples data=new FgExamples(fts);
  data.add(getExForFts("String_Node_Str","String_Node_Str",fts,useLat));
  data.add(getExForFts("String_Node_Str","String_Node_Str",fts,useLat));
  data.add(getExForFts("String_Node_Str","String_Node_Str",fts,useLat));
  data.add(getExForFts("String_Node_Str","String_Node_Str",fts,useLat));
  FgModel model1=new FgModel(data,true);
  System.out.println("String_Node_Str" + model1);
  assertEquals(20,model1.getNumParams());
  FgModel model2=new FgModel(data,false);
  System.out.println("String_Node_Str" + model2);
  assertEquals(6 + 4,model2.getNumParams());
}
Program: 131515
Project: 131515
Buggy source:
@Test public void testPreprocess() throws Exception {
  InputStream inputStream=this.getClass().getResourceAsStream(CoNLL09ReadWriteTest.conll2009Example);
  CoNLL09FileReader cr=new CoNLL09FileReader(inputStream);
  List<CoNLL09Sentence> sents=cr.readSents(1);
  CorpusStatistics.normalizeRoleNames(sents);
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  cs.init(sents);
  SentFeatureExtractorPrm fePrm=new SentFeatureExtractorPrm();
  SrlFgExampleBuilderPrm prm=new SrlFgExampleBuilderPrm();
  prm.fePrm.useZhaoFeats=false;
  prm.fePrm.useSimpleFeats=false;
  prm.fePrm.useDepPathFeats=false;
  prm.fePrm=fePrm;
  prm.fgPrm.roleStructure=RoleStructure.PREDS_GIVEN;
  prm.fgPrm.alwaysIncludeLinkVars=true;
{
    FeatureTemplateList fts=new FeatureTemplateList();
    prm.featCountCutoff=0;
    SrlFgExamplesBuilder builder=new SrlFgExamplesBuilder(prm,fts,cs);
    FgExamples data=builder.getData(sents);
    assertEquals(13388,fts.getNumObsFeats());
  }
{
    FeatureTemplateList fts=new FeatureTemplateList();
    prm.featCountCutoff=5;
    SrlFgExamplesBuilder builder=new SrlFgExamplesBuilder(prm,fts,cs);
    FgExamples data=builder.getData(sents);
    assertEquals(2729,fts.getNumObsFeats());
  }
}

Fixed version (ground truth):
@Test public void testPreprocess() throws Exception {
  InputStream inputStream=this.getClass().getResourceAsStream(CoNLL09ReadWriteTest.conll2009Example);
  CoNLL09FileReader cr=new CoNLL09FileReader(inputStream);
  List<CoNLL09Sentence> sents=cr.readSents(1);
  CorpusStatistics.normalizeRoleNames(sents);
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  cs.init(sents);
  SentFeatureExtractorPrm fePrm=new SentFeatureExtractorPrm();
  SrlFgExampleBuilderPrm prm=new SrlFgExampleBuilderPrm();
  prm.fePrm.useZhaoFeats=false;
  prm.fePrm.useSimpleFeats=false;
  prm.fePrm.useDepPathFeats=false;
  prm.fePrm=fePrm;
  prm.fgPrm.roleStructure=RoleStructure.PREDS_GIVEN;
  prm.fgPrm.alwaysIncludeLinkVars=true;
{
    FeatureTemplateList fts=new FeatureTemplateList();
    prm.featCountCutoff=0;
    SrlFgExamplesBuilder builder=new SrlFgExamplesBuilder(prm,fts,cs);
    FgExamples data=builder.getData(sents);
    assertEquals(13388,fts.getNumObsFeats());
    FgModel model=new FgModel(data,false);
    assertEquals(26308,model.getNumParams());
  }
{
    FeatureTemplateList fts=new FeatureTemplateList();
    prm.featCountCutoff=5;
    SrlFgExamplesBuilder builder=new SrlFgExamplesBuilder(prm,fts,cs);
    FgExamples data=builder.getData(sents);
    assertEquals(2729,fts.getNumObsFeats());
    FgModel model=new FgModel(data,false);
    assertEquals(6108,model.getNumParams());
  }
}
Program: 131516
Project: 131516
Buggy source:
public SentFeatureExtractor(SentFeatureExtractorPrm prm,CoNLL09Sentence sent,CorpusStatistics cs){
  this.prm=prm;
  this.sent=sent;
  this.cs=cs;
  this.sig=cs.sig;
  this.parents=getParents(sent);
  if (prm.useZhaoFeats) {
    this.zhaoSentence=createZhaoSentence();
    this.zhaoHeadDefault=new ZhaoObject("String_Node_Str");
    this.zhaoTailDefault=new ZhaoObject("String_Node_Str");
  }
}

Fixed version (ground truth):
public SentFeatureExtractor(SentFeatureExtractorPrm prm,CoNLL09Sentence sent,CorpusStatistics cs){
  this.prm=prm;
  this.sent=sent;
  this.cs=cs;
  this.sig=cs.sig;
  if (!prm.biasOnly) {
    this.parents=getParents(sent);
    if (prm.useZhaoFeats) {
      this.zhaoSentence=createZhaoSentence();
      this.zhaoHeadDefault=new ZhaoObject("String_Node_Str");
      this.zhaoTailDefault=new ZhaoObject("String_Node_Str");
    }
  }
 else {
    this.parents=null;
  }
}
Program: 131517
Project: 131517
Buggy source:
public void stopGrowth(){
  for (  FeatureTemplate ft : fts) {
    ft.getAlphabet().stopGrowth();
  }
  isGrowing=false;
}

Fixed version (ground truth):
public void stopGrowth(){
  for (  FeatureTemplate ft : fts) {
    ft.getAlphabet().stopGrowth();
  }
  templateKeyAlphabet.stopGrowth();
  isGrowing=false;
}
Program: 131518
Project: 131518
Buggy source:
/** 
 * For each factor in the data, lookup its configId. Set all the observed features for that configuration to true.
 */
private void includeSupportedFeatures(FgExamples data,FeatureTemplateList templates){
  for (int i=0; i < data.size(); i++) {
    FgExample ex=data.get(i);
    for (int a=0; a < ex.getOriginalFactorGraph().getNumFactors(); a++) {
      Factor f=ex.getFgLat().getFactor(a);
      int t=templates.getTemplateId(f);
      if (t != -1) {
        FeatureVector fv=ex.getObservationFeatures(a);
        if (f.getVars().size() == 0) {
          int predConfig=ex.getGoldConfigIdxPred(a);
          for (          IntDoubleEntry entry : fv) {
            included[t][predConfig][entry.index()]=true;
          }
        }
 else {
          VarConfig predVc=ex.getGoldConfigPred(a);
          IntIter iter=IndexForVc.getConfigIter(ex.getFgLatPred().getFactor(a).getVars(),predVc);
          int numConfigs=f.getVars().calcNumConfigs();
          for (int c=0; c < numConfigs; c++) {
            int config=iter.next();
            for (            IntDoubleEntry entry : fv) {
              included[t][config][entry.index()]=true;
            }
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * For each factor in the data, lookup its configId. Set all the observed features for that configuration to true.
 */
private void includeSupportedFeatures(FgExamples data,FeatureTemplateList templates){
  for (int i=0; i < data.size(); i++) {
    FgExample ex=data.get(i);
    for (int a=0; a < ex.getOriginalFactorGraph().getNumFactors(); a++) {
      Factor f=ex.getFgLat().getFactor(a);
      if (f instanceof GlobalFactor) {
        continue;
      }
 else       if (f instanceof ExpFamFactor) {
        int t=templates.getTemplateId(f);
        if (t != -1) {
          FeatureVector fv=ex.getObservationFeatures(a);
          if (f.getVars().size() == 0) {
            int predConfig=ex.getGoldConfigIdxPred(a);
            for (            IntDoubleEntry entry : fv) {
              included[t][predConfig][entry.index()]=true;
            }
          }
 else {
            VarConfig predVc=ex.getGoldConfigPred(a);
            IntIter iter=IndexForVc.getConfigIter(ex.getFgLatPred().getFactor(a).getVars(),predVc);
            int numConfigs=f.getVars().calcNumConfigs();
            for (int c=0; c < numConfigs; c++) {
              int config=iter.next();
              for (              IntDoubleEntry entry : fv) {
                included[t][config][entry.index()]=true;
              }
            }
          }
        }
      }
 else {
        throw new UnsupportedFactorTypeException(f);
      }
    }
  }
}
Program: 131519
Project: 131519
Buggy source:
public FgExamples getData(){
  FeatureTemplateList fts=new FeatureTemplateList();
  Var v0=new Var(VarType.PREDICTED,descList.size(),"String_Node_Str",getStateNames());
  fts.add(new FeatureTemplate(new VarSet(v0),alphabet,TEMPLATE_KEY));
  FgExamples data=new FgExamples(fts);
  int state=0;
  for (  final LogLinearExDesc desc : descList) {
    for (int i=0; i < desc.getCount(); i++) {
      final VarConfig trainConfig=new VarConfig();
      trainConfig.put(v0,state);
      FactorGraph fg=new FactorGraph();
      v0=new Var(VarType.PREDICTED,descList.size(),"String_Node_Str",getStateNames());
      ExpFamFactor f0=new ExpFamFactor(new VarSet(v0),TEMPLATE_KEY);
      fg.addFactor(f0);
      ObsFeatureExtractor featExtractor=new ObsFeatureExtractor(){
        @Override public FeatureVector calcObsFeatureVector(        int factorId){
          return desc.getFeatures();
        }
      }
;
      data.add(new FgExample(fg,trainConfig,featExtractor,fts));
    }
    state++;
  }
  return data;
}

Fixed version (ground truth):
public FgExamples getData(){
  FeatureTemplateList fts=new FeatureTemplateList();
  Var v0=new Var(VarType.PREDICTED,descList.size(),"String_Node_Str",getStateNames());
  fts.add(new FeatureTemplate(new VarSet(v0),alphabet,TEMPLATE_KEY));
  FgExamples data=new FgExamples(fts);
  int state=0;
  for (  final LogLinearExDesc desc : descList) {
    for (int i=0; i < desc.getCount(); i++) {
      final VarConfig trainConfig=new VarConfig();
      trainConfig.put(v0,state);
      FactorGraph fg=new FactorGraph();
      v0=new Var(VarType.PREDICTED,descList.size(),"String_Node_Str",getStateNames());
      ExpFamFactor f0=new ExpFamFactor(new VarSet(v0),TEMPLATE_KEY);
      fg.addFactor(f0);
      ObsFeatureExtractor featExtractor=new ObsFeatureExtractor(){
        @Override public FeatureVector calcObsFeatureVector(        int factorId){
          return desc.getFeatures();
        }
        public void init(        FactorGraph fg,        FactorGraph fgLat,        FactorGraph fgLatPred,        VarConfig goldConfig,        FeatureTemplateList fts){
        }
      }
;
      data.add(new FgExample(fg,trainConfig,featExtractor,fts));
    }
    state++;
  }
  return data;
}
Program: 131520
Project: 131520
Buggy source:
public SimpleVCFeatureExtractor(FactorGraph fg,VarConfig goldConfig,FeatureTemplateList fts){
  super(fg,goldConfig);
  this.fts=fts;
}

Fixed version (ground truth):
public SimpleVCFeatureExtractor(FactorGraph fg,VarConfig goldConfig,FeatureTemplateList fts){
  super();
  this.fts=fts;
}
Program: 131521
Project: 131521
Buggy source:
public FeatureTemplate(VarSet vars,Alphabet<Feature> alphabet,Object key){
  super();
  if (VarSet.getVarsOfType(vars,VarType.OBSERVED).size() != 0) {
    throw new IllegalStateException("String_Node_Str");
  }
  this.numConfigs=vars.calcNumConfigs();
  this.alphabet=alphabet;
  this.key=key;
}

Fixed version (ground truth):
public FeatureTemplate(VarSet vars,Alphabet<Feature> alphabet,Object key){
  super();
  if (VarSet.getVarsOfType(vars,VarType.OBSERVED).size() != 0) {
    throw new IllegalStateException("String_Node_Str");
  }
  this.numConfigs=vars.calcNumConfigs();
  this.alphabet=alphabet;
  this.key=key;
  this.vars=vars;
}
Program: 131522
Project: 131522
Buggy source:
/** 
 * Constructs a train or test example for a Factor Graph.
 * @param fg The factor graph.
 * @param goldConfig The gold assignment to the variables.
 * @param fts TODO
 * @param featExtractor Feature extractor on the observations only (i.e. theobservation function).
 */
public FgExample(FactorGraph fg,VarConfig goldConfig,ObsFeatureExtractor fe,FeatureTemplateList fts){
  this.fg=fg;
  this.goldConfig=goldConfig;
  List<Var> observedVars=VarSet.getVarsOfType(fg.getVars(),VarType.OBSERVED);
  fgLatPred=fg.getClamped(goldConfig.getIntersection(observedVars));
  List<Var> predictedVars=VarSet.getVarsOfType(fg.getVars(),VarType.PREDICTED);
  fgLat=fgLatPred.getClamped(goldConfig.getIntersection(predictedVars));
  hasLatentVars=fg.getVars().size() - observedVars.size() - predictedVars.size() > 0;
  assert(fg.getNumFactors() == fgLatPred.getNumFactors());
  assert(fg.getNumFactors() == fgLat.getNumFactors());
  checkGoldConfig(fg,goldConfig);
  fts.update(fgLatPred);
  this.featExtractor=new ObsFeatureCache(fgLatPred,fe);
  cacheObsFeats();
}

Fixed version (ground truth):
/** 
 * Constructs a train or test example for a Factor Graph.
 * @param fg The factor graph.
 * @param goldConfig The gold assignment to the variables.
 * @param fts TODO
 * @param featExtractor Feature extractor on the observations only (i.e. theobservation function).
 */
public FgExample(FactorGraph fg,VarConfig goldConfig,ObsFeatureExtractor fe,FeatureTemplateList fts){
  this.fg=fg;
  this.goldConfig=goldConfig;
  List<Var> observedVars=VarSet.getVarsOfType(fg.getVars(),VarType.OBSERVED);
  fgLatPred=fg.getClamped(goldConfig.getIntersection(observedVars));
  List<Var> predictedVars=VarSet.getVarsOfType(fg.getVars(),VarType.PREDICTED);
  fgLat=fgLatPred.getClamped(goldConfig.getIntersection(predictedVars));
  hasLatentVars=fg.getVars().size() - observedVars.size() - predictedVars.size() > 0;
  assert(fg.getNumFactors() == fgLatPred.getNumFactors());
  assert(fg.getNumFactors() == fgLat.getNumFactors());
  checkGoldConfig(fg,goldConfig);
  fts.update(fgLatPred);
  this.featExtractor=new ObsFeatureCache(fgLatPred,fe);
  this.featExtractor.init(fg,fgLat,fgLatPred,goldConfig,fts);
  cacheObsFeats();
}
Program: 131523
Project: 131523
Buggy source:
public void printModel(Writer writer) throws IOException {
  for (int t=0; t < numTemplates; t++) {
    FeatureTemplate template=templates.get(t);
    int numConfigs=template.getNumConfigs();
    Alphabet<Feature> alphabet=template.getAlphabet();
    for (int c=0; c < numConfigs; c++) {
      for (int k=0; k < params[t][c].length; k++) {
        if (included[t][c][k]) {
          writer.write(template.getKey().toString());
          writer.write("String_Node_Str");
          writer.write(Integer.toString(c));
          writer.write("String_Node_Str");
          writer.write(alphabet.lookupObject(k).toString());
          writer.write("String_Node_Str");
          writer.write(String.format("String_Node_Str",params[t][c][k]));
          writer.write("String_Node_Str");
        }
      }
    }
  }
  writer.flush();
}

Fixed version (ground truth):
public void printModel(Writer writer) throws IOException {
  for (int t=0; t < numTemplates; t++) {
    FeatureTemplate template=templates.get(t);
    int numConfigs=template.getNumConfigs();
    Alphabet<Feature> alphabet=template.getAlphabet();
    for (int c=0; c < numConfigs; c++) {
      for (int k=0; k < params[t][c].length; k++) {
        if (included[t][c][k]) {
          writer.write(template.getKey().toString());
          writer.write("String_Node_Str");
          writer.write(template.getStateNamesStr(c));
          writer.write("String_Node_Str");
          writer.write(alphabet.lookupObject(k).toString());
          writer.write("String_Node_Str");
          writer.write(String.format("String_Node_Str",params[t][c][k]));
          writer.write("String_Node_Str");
        }
      }
    }
  }
  writer.flush();
}
Program: 131524
Project: 131524
Buggy source:
private FgExample getExForFts(String state1,String state2,FeatureTemplateList fts){
  Var v1=new Var(VarType.PREDICTED,2,"String_Node_Str",Utilities.getList("String_Node_Str","String_Node_Str"));
  Var v2=new Var(VarType.PREDICTED,3,"String_Node_Str",Utilities.getList("String_Node_Str","String_Node_Str","String_Node_Str"));
  FactorGraph fg=new FactorGraph();
  fg.addFactor(new ExpFamFactor(new VarSet(v1,v2),"String_Node_Str"));
  VarConfig vc=new VarConfig();
  vc.put(v1,state1);
  vc.put(v2,state2);
  return new FgExample(fg,vc,new MockFeatureExtractor(fg,vc,fts),fts);
}

Fixed version (ground truth):
private FgExample getExForFts(String state1,String state2,FeatureTemplateList fts){
  Var v1=new Var(VarType.PREDICTED,2,"String_Node_Str",Utilities.getList("String_Node_Str","String_Node_Str"));
  Var v2=new Var(VarType.PREDICTED,3,"String_Node_Str",Utilities.getList("String_Node_Str","String_Node_Str","String_Node_Str"));
  FactorGraph fg=new FactorGraph();
  fg.addFactor(new ExpFamFactor(new VarSet(v1,v2),"String_Node_Str"));
  VarConfig vc=new VarConfig();
  vc.put(v1,state1);
  vc.put(v2,state2);
  return new FgExample(fg,vc,new MockFeatureExtractor(),fts);
}
Program: 131525
Project: 131525
Buggy source:
public MockFeatureExtractor(FactorGraph fg,VarConfig goldConfig,FeatureTemplateList fts){
  super(fg,goldConfig);
  this.fts=fts;
}

Fixed version (ground truth):
public MockFeatureExtractor(){
  super();
}
Program: 131526
Project: 131526
Buggy source:
public ObsFeatureCache(FactorGraph fg,ObsFeatureExtractor featExtractor){
  this.feats=new FeatureVector[fg.getNumFactors()];
  this.featExtractor=featExtractor;
  for (int a=0; a < fg.getNumFactors(); a++) {
    Factor f=fg.getFactor(a);
    if (f instanceof GlobalFactor) {
      continue;
    }
 else     if (f instanceof DenseFactor) {
      continue;
    }
 else {
      throw new UnsupportedFactorTypeException(f);
    }
  }
}

Fixed version (ground truth):
public ObsFeatureCache(FactorGraph fg,ObsFeatureExtractor featExtractor){
  this.featExtractor=featExtractor;
  this.feats=new FeatureVector[fg.getNumFactors()];
  for (int a=0; a < fg.getNumFactors(); a++) {
    Factor f=fg.getFactor(a);
    if (f instanceof GlobalFactor) {
      continue;
    }
 else     if (f instanceof DenseFactor) {
      continue;
    }
 else {
      throw new UnsupportedFactorTypeException(f);
    }
  }
}
Program: 131527
Project: 131527
Buggy source:
public SlowObsFeatureExtractor(FactorGraph fg,VarConfig goldConfig){
  this.fg=fg;
  this.goldConfig=goldConfig;
}

Fixed version (ground truth):
public SlowObsFeatureExtractor(){
}
Program: 131528
Project: 131528
Buggy source:
public SrlFeatureExtractor(SrlFeatureExtractorPrm prm,SrlFactorGraph sfg,FeatureTemplateList fts,SentFeatureExtractor sentFeatExt,Alphabet<String> obsAlphabet){
  this.prm=prm;
  this.sfg=sfg;
  this.fts=fts;
  this.sentFeatExt=sentFeatExt;
  obsFeatsSolo=new BinaryStrFVBuilder[sentFeatExt.getSentSize()];
  obsFeatsPair=new BinaryStrFVBuilder[sentFeatExt.getSentSize()][sentFeatExt.getSentSize()];
  this.obsAlphabet=obsAlphabet;
}

Fixed version (ground truth):
public SrlFeatureExtractor(SrlFeatureExtractorPrm prm,SentFeatureExtractor sentFeatExt,Alphabet<String> obsAlphabet){
  this.prm=prm;
  this.sentFeatExt=sentFeatExt;
  obsFeatsSolo=new BinaryStrFVBuilder[sentFeatExt.getSentSize()];
  obsFeatsPair=new BinaryStrFVBuilder[sentFeatExt.getSentSize()][sentFeatExt.getSentSize()];
  this.obsAlphabet=obsAlphabet;
}
Program: 131530
Project: 131530
Buggy source:
@Test public void testCorrectNumFeatures() throws Exception {
  SrlFactorGraphPrm fgPrm=new SrlFactorGraphPrm();
  fgPrm.alwaysIncludeLinkVars=true;
  HashSet<Integer> knownPreds=new HashSet<Integer>(Utilities.getList(0,2));
  SrlFactorGraph sfg=new SrlFactorGraph(fgPrm,3,knownPreds,Utilities.getList("String_Node_Str","String_Node_Str","String_Node_Str"));
  FeatureTemplateList fts=new FeatureTemplateList();
  InputStream inputStream=this.getClass().getResourceAsStream(CoNLL09ReadWriteTest.conll2009Example);
  CoNLL09FileReader cr=new CoNLL09FileReader(inputStream);
  List<CoNLL09Sentence> sents=cr.readSents(1);
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  cs.init(sents);
  fts.update(sfg);
  SentFeatureExtractorPrm fePrm=new SentFeatureExtractorPrm();
  fePrm.biasOnly=true;
  SentFeatureExtractor sentFeatExt=new SentFeatureExtractor(fePrm,sents.get(0),cs);
  SrlFeatureExtractorPrm prm=new SrlFeatureExtractorPrm();
  prm.featureHashMod=-1;
  SrlFeatureExtractor featExt=new SrlFeatureExtractor(prm,sfg,fts,sentFeatExt);
  for (int a=0; a < sfg.getNumFactors(); a++) {
    featExt.calcObsFeatureVector(a);
  }
  assertEquals(3,fts.getNumObsFeats());
}

Fixed version (ground truth):
@Test public void testCorrectNumFeatures() throws Exception {
  SrlFactorGraphPrm fgPrm=new SrlFactorGraphPrm();
  fgPrm.alwaysIncludeLinkVars=true;
  HashSet<Integer> knownPreds=new HashSet<Integer>(Utilities.getList(0,2));
  SrlFactorGraph sfg=new SrlFactorGraph(fgPrm,3,knownPreds,Utilities.getList("String_Node_Str","String_Node_Str","String_Node_Str"));
  FeatureTemplateList fts=new FeatureTemplateList();
  InputStream inputStream=this.getClass().getResourceAsStream(CoNLL09ReadWriteTest.conll2009Example);
  CoNLL09FileReader cr=new CoNLL09FileReader(inputStream);
  List<CoNLL09Sentence> sents=cr.readSents(1);
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  cs.init(sents);
  fts.update(sfg);
  SentFeatureExtractorPrm fePrm=new SentFeatureExtractorPrm();
  fePrm.biasOnly=true;
  SentFeatureExtractor sentFeatExt=new SentFeatureExtractor(fePrm,sents.get(0),cs);
  SrlFeatureExtractorPrm prm=new SrlFeatureExtractorPrm();
  prm.featureHashMod=-1;
  SrlFeatureExtractor featExt=new SrlFeatureExtractor(prm,sentFeatExt);
  featExt.init(sfg,null,null,new VarConfig(),fts);
  for (int a=0; a < sfg.getNumFactors(); a++) {
    featExt.calcObsFeatureVector(a);
  }
  assertEquals(3,fts.getNumObsFeats());
}
Program: 131531
Project: 131531
Buggy source:
@Test public void testCorrectNumFeaturesWithFeatureHashing() throws Exception {
  SrlFactorGraphPrm fgPrm=new SrlFactorGraphPrm();
  HashSet<Integer> knownPreds=new HashSet<Integer>(Utilities.getList(0,2));
  SrlFactorGraph sfg=new SrlFactorGraph(fgPrm,3,knownPreds,Utilities.getList("String_Node_Str","String_Node_Str","String_Node_Str"));
  FeatureTemplateList fts=new FeatureTemplateList();
  InputStream inputStream=this.getClass().getResourceAsStream(CoNLL09ReadWriteTest.conll2009Example);
  CoNLL09FileReader cr=new CoNLL09FileReader(inputStream);
  List<CoNLL09Sentence> sents=cr.readSents(1);
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  cs.init(sents);
  fts.update(sfg);
  SentFeatureExtractorPrm fePrm=new SentFeatureExtractorPrm();
  fePrm.useNaradFeats=true;
  fePrm.useSimpleFeats=false;
  fePrm.useZhaoFeats=false;
  SentFeatureExtractor sentFeatExt=new SentFeatureExtractor(fePrm,sents.get(0),cs);
  SrlFeatureExtractorPrm prm=new SrlFeatureExtractorPrm();
  prm.featureHashMod=10;
  SrlFeatureExtractor featExt=new SrlFeatureExtractor(prm,sfg,fts,sentFeatExt);
  for (int a=0; a < sfg.getNumFactors(); a++) {
    featExt.calcObsFeatureVector(a);
  }
  System.out.println(fts);
  assertEquals(10,fts.getNumObsFeats());
}

Fixed version (ground truth):
@Test public void testCorrectNumFeaturesWithFeatureHashing() throws Exception {
  SrlFactorGraphPrm fgPrm=new SrlFactorGraphPrm();
  HashSet<Integer> knownPreds=new HashSet<Integer>(Utilities.getList(0,2));
  SrlFactorGraph sfg=new SrlFactorGraph(fgPrm,3,knownPreds,Utilities.getList("String_Node_Str","String_Node_Str","String_Node_Str"));
  FeatureTemplateList fts=new FeatureTemplateList();
  InputStream inputStream=this.getClass().getResourceAsStream(CoNLL09ReadWriteTest.conll2009Example);
  CoNLL09FileReader cr=new CoNLL09FileReader(inputStream);
  List<CoNLL09Sentence> sents=cr.readSents(1);
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  cs.init(sents);
  fts.update(sfg);
  SentFeatureExtractorPrm fePrm=new SentFeatureExtractorPrm();
  fePrm.useNaradFeats=true;
  fePrm.useSimpleFeats=false;
  fePrm.useZhaoFeats=false;
  fePrm.useDepPathFeats=true;
  SentFeatureExtractor sentFeatExt=new SentFeatureExtractor(fePrm,sents.get(0),cs);
  SrlFeatureExtractorPrm prm=new SrlFeatureExtractorPrm();
  prm.featureHashMod=10;
  SrlFeatureExtractor featExt=new SrlFeatureExtractor(prm,sentFeatExt);
  featExt.init(sfg,null,null,new VarConfig(),fts);
  for (int a=0; a < sfg.getNumFactors(); a++) {
    featExt.calcObsFeatureVector(a);
  }
  System.out.println(fts);
  assertEquals(10,fts.getNumObsFeats());
}
Program: 131532
Project: 131532
Buggy source:
public FgExamples getData(List<CoNLL09Sentence> sents){
  if (prm.featCountCutoff > 0) {
    throw new RuntimeException("String_Node_Str");
  }
  Alphabet<String> obsAlphabet=new Alphabet<String>();
  FgExamples data=new FgExamples(fts);
  for (int i=0; i < sents.size(); i++) {
    CoNLL09Sentence sent=sents.get(i);
    if (i % 1000 == 0 && i > 0) {
      log.debug("String_Node_Str" + i + "String_Node_Str");
    }
    SrlGraph srlGraph=sent.getSrlGraph();
    Set<Integer> knownPreds=getKnownPreds(srlGraph);
    SrlFactorGraph sfg=new SrlFactorGraph(prm.fgPrm,sent.size(),knownPreds,cs.roleStateNames);
    VarConfig trainConfig=getTrainAssignment(sent,srlGraph,sfg);
    SentFeatureExtractor sentFeatExt=new SentFeatureExtractor(prm.fePrm,sent,cs);
    ObsFeatureExtractor featExtractor=new SrlFeatureExtractor(prm.srlFePrm,sfg,fts,sentFeatExt,obsAlphabet);
    FgExample ex=new FgExample(sfg,trainConfig,featExtractor,fts);
    data.add(ex);
  }
  log.info("String_Node_Str" + obsAlphabet.size());
  data.setSourceSentences(sents);
  return data;
}

Fixed version (ground truth):
public FgExamples getData(List<CoNLL09Sentence> sents){
  if (prm.featCountCutoff > 0) {
    throw new RuntimeException("String_Node_Str");
  }
  Alphabet<String> obsAlphabet=new Alphabet<String>();
  FgExamples data=new FgExamples(fts);
  for (int i=0; i < sents.size(); i++) {
    CoNLL09Sentence sent=sents.get(i);
    if (i % 1000 == 0 && i > 0) {
      log.debug("String_Node_Str" + i + "String_Node_Str");
    }
    SrlGraph srlGraph=sent.getSrlGraph();
    Set<Integer> knownPreds=getKnownPreds(srlGraph);
    SrlFactorGraph sfg=new SrlFactorGraph(prm.fgPrm,sent.size(),knownPreds,cs.roleStateNames);
    VarConfig trainConfig=getTrainAssignment(sent,srlGraph,sfg);
    SentFeatureExtractor sentFeatExt=new SentFeatureExtractor(prm.fePrm,sent,cs);
    ObsFeatureExtractor featExtractor=new SrlFeatureExtractor(prm.srlFePrm,sentFeatExt,obsAlphabet);
    FgExample ex=new FgExample(sfg,trainConfig,featExtractor,fts);
    data.add(ex);
  }
  log.info("String_Node_Str" + obsAlphabet.size());
  data.setSourceSentences(sents);
  return data;
}
Program: 131533
Project: 131533
Buggy source:
/** 
 * Creates a feature set for the given pair of word positions. This defines a feature function of the form f(x, i, j), where x is a vector representing all the observations about a sentence and i and j are positions in the sentence. Examples where this feature function would be used include factors including a Role or Link variable in the SRL model, where both the parent and child are tokens in the sentence.
 * @param pidx The "parent" position.
 * @param aidx The "child" position.
 * @return The features.
 */
public BinaryStrFVBuilder createFeatureSet(int pidx,int aidx){
  BinaryStrFVBuilder feats=new BinaryStrFVBuilder(alphabet);
  feats.add("String_Node_Str");
  if (prm.biasOnly) {
    return feats;
  }
  if (prm.useSimpleFeats) {
    addSimplePairFeatures(pidx,aidx,feats);
  }
  if (prm.useNaradFeats) {
    addNaradowskyPairFeatures(pidx,aidx,feats);
  }
  if (prm.useZhaoFeats) {
    addZhaoPairFeatures(pidx,aidx,feats);
  }
  if (prm.useDepPathFeats) {
    addDependencyPathFeatures(pidx,aidx,feats);
  }
  return feats;
}

Fixed version (ground truth):
/** 
 * Creates a feature set for the given pair of word positions. This defines a feature function of the form f(x, i, j), where x is a vector representing all the observations about a sentence and i and j are positions in the sentence. Examples where this feature function would be used include factors including a Role or Link variable in the SRL model, where both the parent and child are tokens in the sentence.
 * @param pidx The "parent" position.
 * @param aidx The "child" position.
 * @return The features.
 */
public BinaryStrFVBuilder createFeatureSet(int pidx,int aidx){
  BinaryStrFVBuilder feats=new BinaryStrFVBuilder(alphabet);
  if (prm.biasOnly) {
    return feats;
  }
  if (prm.useSimpleFeats) {
    addSimplePairFeatures(pidx,aidx,feats);
  }
  if (prm.useNaradFeats) {
    addNaradowskyPairFeatures(pidx,aidx,feats);
  }
  if (prm.useZhaoFeats) {
    addZhaoPairFeatures(pidx,aidx,feats);
  }
  if (prm.useDepPathFeats) {
    addDependencyPathFeatures(pidx,aidx,feats);
  }
  return feats;
}
Program: 131534
Project: 131534
Buggy source:
/** 
 * Updates the factor graph with the latest parameter vector. 
 * @param logDomain TODO
 */
private FactorGraph getUpdatedFactorGraph(FactorGraph fg,double[] params,boolean logDomain){
  for (int a=0; a < fg.getNumFactors(); a++) {
    Factor f=fg.getFactor(a);
    if (f instanceof GlobalFactor) {
      continue;
    }
 else     if (f instanceof DenseFactor) {
      IntIter iter=null;
      if (fg == this.getFgLat()) {
        VarConfig predVc=this.getGoldConfigPred(a);
        iter=IndexForVc.getConfigIter(this.getFgLatPred().getFactor(a).getVars(),predVc);
      }
      DenseFactor factor=(DenseFactor)f;
      int numConfigs=factor.getVars().calcNumConfigs();
      for (int c=0; c < numConfigs; c++) {
        int config=(iter != null) ? iter.next() : c;
        FeatureVector fv=this.getFeatureVector(a,config);
        if (logDomain) {
          factor.setValue(c,fv.dot(params));
        }
 else {
          factor.setValue(c,Utilities.exp(fv.dot(params)));
        }
      }
    }
 else {
      throw new UnsupportedFactorTypeException(f);
    }
  }
  return fg;
}

Fixed version (ground truth):
/** 
 * Updates the factor graph with the latest parameter vector. 
 * @param logDomain TODO
 */
private FactorGraph getUpdatedFactorGraph(FactorGraph fg,double[] params,boolean logDomain){
  for (int a=0; a < fg.getNumFactors(); a++) {
    Factor f=fg.getFactor(a);
    if (f instanceof GlobalFactor) {
      continue;
    }
 else     if (f instanceof DenseFactor) {
      DenseFactor factor=(DenseFactor)f;
      int numConfigs=factor.getVars().calcNumConfigs();
      if (numConfigs == 0) {
        int config=this.getGoldConfigLatPred(a).getConfigIndex();
        this.getFeatureVector(a,config);
      }
 else {
        IntIter iter=null;
        if (fg == this.getFgLat()) {
          VarConfig predVc=this.getGoldConfigPred(a);
          iter=IndexForVc.getConfigIter(this.getFgLatPred().getFactor(a).getVars(),predVc);
        }
        for (int c=0; c < numConfigs; c++) {
          int config=(iter != null) ? iter.next() : c;
          FeatureVector fv=this.getFeatureVector(a,config);
          if (logDomain) {
            factor.setValue(c,fv.dot(params));
          }
 else {
            factor.setValue(c,Utilities.exp(fv.dot(params)));
          }
        }
      }
    }
 else {
      throw new UnsupportedFactorTypeException(f);
    }
  }
  return fg;
}
Program: 131535
Project: 131535
Buggy source:
public void preprocess(List<CoNLL09Sentence> sents){
  if (!(alphabet.isGrowing() && prm.featCountCutoff > 0)) {
    return;
  }
  CountingAlphabet<Feature> counter=new CountingAlphabet<Feature>();
  Alphabet<String> obsAlphabet=new Alphabet<String>();
  List<FeatureExtractor> featExts=new ArrayList<FeatureExtractor>();
  for (int i=0; i < sents.size(); i++) {
    CoNLL09Sentence sent=sents.get(i);
    if (i % 1000 == 0 && i > 0) {
      log.debug("String_Node_Str" + i + "String_Node_Str");
    }
    SrlGraph srlGraph=sent.getSrlGraph();
    Set<Integer> knownPreds=getKnownPreds(srlGraph);
    SrlFactorGraph sfg=new SrlFactorGraph(prm.fgPrm,sent.size(),knownPreds,cs.roleStateNames);
    VarConfig trainConfig=getTrainAssignment(sent,srlGraph,sfg);
    SentFeatureExtractor sentFeatExt=new SentFeatureExtractor(prm.fePrm,sent,cs,obsAlphabet);
    FeatureExtractor featExtractor=new SrlFeatureExtractor(prm.srlFePrm,sfg,counter,sentFeatExt);
    featExts.add(featExtractor);
    FgExample ex=new FgExample(sfg,trainConfig,featExtractor,false);
    ex.cacheLatFeats();
  }
  for (int i=0; i < counter.size(); i++) {
    int count=counter.lookupObjectCount(i);
    Feature feat=counter.lookupObject(i);
    if (count >= prm.featCountCutoff || feat.isBiasFeature()) {
      alphabet.lookupIndex(feat);
    }
  }
  alphabet.stopGrowth();
}

Fixed version (ground truth):
public void preprocess(List<CoNLL09Sentence> sents){
  if (!(alphabet.isGrowing() && prm.featCountCutoff > 0)) {
    log.info("String_Node_Str");
    return;
  }
  CountingAlphabet<Feature> counter=new CountingAlphabet<Feature>();
  Alphabet<String> obsAlphabet=new Alphabet<String>();
  List<FeatureExtractor> featExts=new ArrayList<FeatureExtractor>();
  for (int i=0; i < sents.size(); i++) {
    CoNLL09Sentence sent=sents.get(i);
    if (i % 1000 == 0 && i > 0) {
      log.debug("String_Node_Str" + i + "String_Node_Str");
    }
    SrlGraph srlGraph=sent.getSrlGraph();
    Set<Integer> knownPreds=getKnownPreds(srlGraph);
    SrlFactorGraph sfg=new SrlFactorGraph(prm.fgPrm,sent.size(),knownPreds,cs.roleStateNames);
    VarConfig trainConfig=getTrainAssignment(sent,srlGraph,sfg);
    SentFeatureExtractor sentFeatExt=new SentFeatureExtractor(prm.fePrm,sent,cs,obsAlphabet);
    FeatureExtractor featExtractor=new SrlFeatureExtractor(prm.srlFePrm,sfg,counter,sentFeatExt);
    featExts.add(featExtractor);
    FgExample ex=new FgExample(sfg,trainConfig,featExtractor,false);
    ex.cacheLatFeats();
  }
  for (int i=0; i < counter.size(); i++) {
    int count=counter.lookupObjectCount(i);
    Feature feat=counter.lookupObject(i);
    if (count >= prm.featCountCutoff || feat.isBiasFeature()) {
      alphabet.lookupIndex(feat);
    }
  }
  alphabet.stopGrowth();
}
Program: 131538
Project: 131538
Buggy source:
private String decideForm(String wordForm,int idx){
  String cleanWord=cs.normalize.clean(wordForm);
  if (!cs.knownWords.contains(cleanWord)) {
    String unkWord=cs.sig.getSignature(cleanWord,idx,prm.language);
    unkWord=cs.normalize.escape(unkWord);
    if (!cs.knownUnks.contains(unkWord)) {
      unkWord="String_Node_Str";
      return unkWord;
    }
  }
  return cleanWord;
}

Fixed version (ground truth):
private String decideForm(String wordForm,int idx){
  String cleanWord=cs.normalize.clean(wordForm);
  if (!cs.knownWords.contains(cleanWord)) {
    String unkWord=cs.sig.getSignature(cleanWord,idx,cs.prm.language);
    unkWord=cs.normalize.escape(unkWord);
    if (!cs.knownUnks.contains(unkWord)) {
      unkWord="String_Node_Str";
      return unkWord;
    }
  }
  return cleanWord;
}
Program: 131539
Project: 131539
Buggy source:
private void addZhaoUnsupervisedArgFeats(ZhaoObject zhaoArg,ZhaoObject zhaoArgNext,ZhaoObject zhaoArgLast,ArrayList<CoNLL09Token> argChildrenTokens,BinaryStrFVBuilder feats){
  String feat;
  feat=sent.get(zhaoArg.getFarLeftChild()).getForm();
  feats.add(feat);
  feat=zhaoArgLast.getForm();
  feats.add(feat);
  feat=zhaoArg.getForm() + "String_Node_Str" + zhaoArgNext.getForm();
  feats.add(feat);
  List<String> argChildrenPos=new ArrayList<String>();
  for (  CoNLL09Token child : argChildrenTokens) {
    if (prm.useGoldSyntax) {
      argChildrenPos.add(child.getPos());
    }
 else {
      argChildrenPos.add(child.getPpos());
    }
  }
  feat=zhaoArg.getForm() + "String_Node_Str" + StringUtils.join(argChildrenPos,"String_Node_Str");
  feats.add(feat);
  feat=zhaoArgNext.getPos() + "String_Node_Str" + zhaoArg.getPos();
  feats.add(feat);
}

Fixed version (ground truth):
private void addZhaoUnsupervisedArgFeats(ZhaoObject zhaoArg,ZhaoObject zhaoArgNext,ZhaoObject zhaoArgLast,ArrayList<CoNLL09Token> argChildrenTokens,BinaryStrFVBuilder feats){
  String feat;
  feat=sent.get(zhaoArg.getFarLeftChild()).getForm();
  feats.add(feat);
  feat=zhaoArgLast.getForm();
  feats.add(feat);
  feat=zhaoArg.getForm() + "String_Node_Str" + zhaoArgNext.getForm();
  feats.add(feat);
  List<String> argChildrenPos=new ArrayList<String>();
  for (  CoNLL09Token child : argChildrenTokens) {
    if (cs.prm.useGoldSyntax) {
      argChildrenPos.add(child.getPos());
    }
 else {
      argChildrenPos.add(child.getPpos());
    }
  }
  feat=zhaoArg.getForm() + "String_Node_Str" + StringUtils.join(argChildrenPos,"String_Node_Str");
  feats.add(feat);
  feat=zhaoArgNext.getPos() + "String_Node_Str" + zhaoArg.getPos();
  feats.add(feat);
}
Program: 131540
Project: 131540
Buggy source:
public void addSimpleSoloFeatures(int idx,BinaryStrFVBuilder feats){
  String wordForm=sent.get(idx).getForm();
  System.out.println("String_Node_Str" + wordForm);
  Set<String> a=sig.getSimpleUnkFeatures(wordForm,idx,prm.language);
  for (  String c : a) {
    feats.add(c);
  }
}

Fixed version (ground truth):
public void addSimpleSoloFeatures(int idx,BinaryStrFVBuilder feats){
  String wordForm=sent.get(idx).getForm();
  System.out.println("String_Node_Str" + wordForm);
  Set<String> a=sig.getSimpleUnkFeatures(wordForm,idx,cs.prm.language);
  for (  String c : a) {
    feats.add(c);
  }
}
Program: 131541
Project: 131541
Buggy source:
int[] getParents(CoNLL09Sentence sent){
  if (prm.useGoldSyntax) {
    return sent.getParentsFromHead();
  }
 else {
    return sent.getParentsFromPhead();
  }
}

Fixed version (ground truth):
int[] getParents(CoNLL09Sentence sent){
  if (cs.prm.useGoldSyntax) {
    return sent.getParentsFromHead();
  }
 else {
    return sent.getParentsFromPhead();
  }
}
Program: 131542
Project: 131542
Buggy source:
public void addSimplePairFeatures(int pidx,int aidx,BinaryStrFVBuilder feats){
  String predForm=sent.get(pidx).getForm();
  String argForm=sent.get(aidx).getForm();
  System.out.println("String_Node_Str" + predForm);
  System.out.println("String_Node_Str" + argForm);
  Set<String> a=sig.getSimpleUnkFeatures(predForm,pidx,prm.language);
  for (  String c : a) {
    feats.add(c);
  }
  Set<String> b=sig.getSimpleUnkFeatures(argForm,aidx,prm.language);
  for (  String c : a) {
    feats.add(c);
  }
}

Fixed version (ground truth):
public void addSimplePairFeatures(int pidx,int aidx,BinaryStrFVBuilder feats){
  String predForm=sent.get(pidx).getForm();
  String argForm=sent.get(aidx).getForm();
  System.out.println("String_Node_Str" + predForm);
  System.out.println("String_Node_Str" + argForm);
  Set<String> a=sig.getSimpleUnkFeatures(predForm,pidx,cs.prm.language);
  for (  String c : a) {
    feats.add(c);
  }
  Set<String> b=sig.getSimpleUnkFeatures(argForm,aidx,cs.prm.language);
  for (  String c : a) {
    feats.add(c);
  }
}
Program: 131543
Project: 131543
Buggy source:
public void addNaradowskySoloFeatures(int idx,BinaryStrFVBuilder feats){
  CoNLL09Token word=sent.get(idx);
  String wordForm=decideForm(word.getForm(),idx);
  String wordPos;
  if (prm.useGoldSyntax) {
    wordPos=word.getPos();
  }
 else {
    wordPos=word.getPpos();
  }
  feats.add("String_Node_Str" + wordForm + "String_Node_Str");
  feats.add("String_Node_Str" + wordPos + "String_Node_Str");
  feats.add("String_Node_Str" + sent.size());
  if (prm.withSupervision) {
    List<String> wordFeats=word.getFeat();
    if (wordFeats == null) {
      wordFeats=new ArrayList<String>();
      wordFeats.add("String_Node_Str");
    }
    for (    String m1 : wordFeats) {
      feats.add(m1 + "String_Node_Str");
    }
  }
}

Fixed version (ground truth):
public void addNaradowskySoloFeatures(int idx,BinaryStrFVBuilder feats){
  CoNLL09Token word=sent.get(idx);
  String wordForm=decideForm(word.getForm(),idx);
  String wordPos;
  if (cs.prm.useGoldSyntax) {
    wordPos=word.getPos();
  }
 else {
    wordPos=word.getPpos();
  }
  feats.add("String_Node_Str" + wordForm + "String_Node_Str");
  feats.add("String_Node_Str" + wordPos + "String_Node_Str");
  feats.add("String_Node_Str" + sent.size());
  if (prm.withSupervision) {
    List<String> wordFeats=word.getFeat();
    if (wordFeats == null) {
      wordFeats=new ArrayList<String>();
      wordFeats.add("String_Node_Str");
    }
    for (    String m1 : wordFeats) {
      feats.add(m1 + "String_Node_Str");
    }
  }
}
Program: 131544
Project: 131544
Buggy source:
@Test public void testZhaoPathFeatures(){
  CoNLL09Sentence sent=getSpanishConll09Sentence2();
  Alphabet<String> alphabet=new Alphabet<String>();
  SentFeatureExtractorPrm prm=new SentFeatureExtractorPrm();
  prm.useGoldSyntax=true;
  CorpusStatistics cs=new CorpusStatistics(prm);
  cs.init(Utilities.getList(sent));
  SentFeatureExtractor fe=new SentFeatureExtractor(prm,sent,cs,alphabet);
  int[] parents=fe.getParents(sent);
  ZhaoObject zhaoPred=new ZhaoObject(1,parents,sent,prm,"String_Node_Str");
  ZhaoObject zhaoArg=new ZhaoObject(0,parents,sent,prm,"String_Node_Str");
  ZhaoObject zhaoLink=new ZhaoObject(1,0,zhaoPred,zhaoArg,parents);
  List<Pair<Integer,Dir>> desiredDpPathShare=new ArrayList<Pair<Integer,Dir>>();
  desiredDpPathShare.add(new Pair<Integer,Dir>(1,Dir.UP));
  List<Pair<Integer,Dir>> observedDpPathShare=zhaoLink.getDpPathShare();
  System.out.println(observedDpPathShare);
  assertEquals(desiredDpPathShare,observedDpPathShare);
}

Fixed version (ground truth):
@Test public void testZhaoPathFeatures(){
  CoNLL09Sentence sent=getSpanishConll09Sentence2();
  Alphabet<String> alphabet=new Alphabet<String>();
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  csPrm.useGoldSyntax=true;
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  cs.init(Utilities.getList(sent));
  SentFeatureExtractorPrm fePrm=new SentFeatureExtractorPrm();
  SentFeatureExtractor fe=new SentFeatureExtractor(fePrm,sent,cs,alphabet);
  int[] parents=fe.getParents(sent);
  ZhaoObject zhaoPred=new ZhaoObject(1,parents,sent,cs,"String_Node_Str");
  ZhaoObject zhaoArg=new ZhaoObject(0,parents,sent,cs,"String_Node_Str");
  ZhaoObject zhaoLink=new ZhaoObject(1,0,zhaoPred,zhaoArg,parents);
  List<Pair<Integer,Dir>> desiredDpPathShare=new ArrayList<Pair<Integer,Dir>>();
  desiredDpPathShare.add(new Pair<Integer,Dir>(1,Dir.UP));
  List<Pair<Integer,Dir>> observedDpPathShare=zhaoLink.getDpPathShare();
  System.out.println(observedDpPathShare);
  assertEquals(desiredDpPathShare,observedDpPathShare);
}
Program: 131545
Project: 131545
Buggy source:
@Test public void testAddNaradowskyFeatures(){
  CoNLL09Sentence sent=getSpanishConll09Sentence1();
  Alphabet<String> alphabet=new Alphabet<String>();
  SentFeatureExtractorPrm prm=new SentFeatureExtractorPrm();
  prm.useGoldSyntax=true;
  CorpusStatistics cs=new CorpusStatistics(prm);
  cs.init(Utilities.getList(sent));
  SentFeatureExtractor fe=new SentFeatureExtractor(prm,sent,cs,alphabet);
  BinaryStrFVBuilder allFeats=new BinaryStrFVBuilder(alphabet);
  for (int i=0; i < sent.size(); i++) {
    for (int j=0; j < sent.size(); j++) {
      fe.addNaradowskyPairFeatures(i,j,allFeats);
    }
  }
  for (  String f : allFeats) {
    System.out.println(f);
  }
}

Fixed version (ground truth):
@Test public void testAddNaradowskyFeatures(){
  CoNLL09Sentence sent=getSpanishConll09Sentence1();
  Alphabet<String> alphabet=new Alphabet<String>();
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  csPrm.useGoldSyntax=true;
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  cs.init(Utilities.getList(sent));
  SentFeatureExtractorPrm fePrm=new SentFeatureExtractorPrm();
  SentFeatureExtractor fe=new SentFeatureExtractor(fePrm,sent,cs,alphabet);
  BinaryStrFVBuilder allFeats=new BinaryStrFVBuilder(alphabet);
  for (int i=0; i < sent.size(); i++) {
    for (int j=0; j < sent.size(); j++) {
      fe.addNaradowskyPairFeatures(i,j,allFeats);
    }
  }
  for (  String f : allFeats) {
    System.out.println(f);
  }
}
Program: 131546
Project: 131546
Buggy source:
@Test public void testGetParentsAndUseGoldSyntax(){
  CoNLL09Sentence sent=getDogConll09Sentence();
  Alphabet<String> alphabet=new Alphabet<String>();
{
    SentFeatureExtractorPrm prm=new SentFeatureExtractorPrm();
    prm.useGoldSyntax=true;
    CorpusStatistics cs=new CorpusStatistics(prm);
    cs.init(Utilities.getList(sent));
    SentFeatureExtractor fe=new SentFeatureExtractor(prm,sent,cs,alphabet);
    int[] goldParents=fe.getParents(sent);
    assertArrayEquals(new int[]{1,2,-1,2},goldParents);
  }
{
    SentFeatureExtractorPrm prm=new SentFeatureExtractorPrm();
    prm.useGoldSyntax=false;
    CorpusStatistics cs=new CorpusStatistics(prm);
    cs.init(Utilities.getList(sent));
    SentFeatureExtractor fe=new SentFeatureExtractor(prm,sent,cs,alphabet);
    int[] predParents=fe.getParents(sent);
    assertArrayEquals(new int[]{2,0,-1,2},predParents);
  }
}

Fixed version (ground truth):
@Test public void testGetParentsAndUseGoldSyntax(){
  CoNLL09Sentence sent=getDogConll09Sentence();
  Alphabet<String> alphabet=new Alphabet<String>();
  SentFeatureExtractorPrm fePrm=new SentFeatureExtractorPrm();
{
    CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
    csPrm.useGoldSyntax=true;
    CorpusStatistics cs=new CorpusStatistics(csPrm);
    cs.init(Utilities.getList(sent));
    SentFeatureExtractor fe=new SentFeatureExtractor(fePrm,sent,cs,alphabet);
    int[] goldParents=fe.getParents(sent);
    assertArrayEquals(new int[]{1,2,-1,2},goldParents);
  }
{
    CorpusStatisticsPrm prm=new CorpusStatisticsPrm();
    prm.useGoldSyntax=false;
    CorpusStatistics cs=new CorpusStatistics(prm);
    cs.init(Utilities.getList(sent));
    SentFeatureExtractor fe=new SentFeatureExtractor(fePrm,sent,cs,alphabet);
    int[] predParents=fe.getParents(sent);
    assertArrayEquals(new int[]{2,0,-1,2},predParents);
  }
}
Program: 131547
Project: 131547
Buggy source:
@Test public void testAddZhaoFeatures(){
  CoNLL09Sentence sent=getSpanishConll09Sentence1();
  Alphabet<String> alphabet=new Alphabet<String>();
  SentFeatureExtractorPrm prm=new SentFeatureExtractorPrm();
  prm.useGoldSyntax=true;
  CorpusStatistics cs=new CorpusStatistics(prm);
  cs.init(Utilities.getList(sent));
  SentFeatureExtractor fe=new SentFeatureExtractor(prm,sent,cs,alphabet);
  BinaryStrFVBuilder feats;
  BinaryStrFVBuilder allFeats=new BinaryStrFVBuilder(alphabet);
  for (int i=0; i < sent.size(); i++) {
    for (int j=0; j < sent.size(); j++) {
      fe.addZhaoPairFeatures(i,j,allFeats);
    }
  }
  for (  String f : allFeats) {
    System.out.println(f);
  }
}

Fixed version (ground truth):
@Test public void testAddZhaoFeatures(){
  CoNLL09Sentence sent=getSpanishConll09Sentence1();
  Alphabet<String> alphabet=new Alphabet<String>();
  CorpusStatisticsPrm csPrm=new CorpusStatisticsPrm();
  csPrm.useGoldSyntax=true;
  CorpusStatistics cs=new CorpusStatistics(csPrm);
  cs.init(Utilities.getList(sent));
  SentFeatureExtractorPrm fePrm=new SentFeatureExtractorPrm();
  SentFeatureExtractor fe=new SentFeatureExtractor(fePrm,sent,cs,alphabet);
  BinaryStrFVBuilder feats;
  BinaryStrFVBuilder allFeats=new BinaryStrFVBuilder(alphabet);
  for (int i=0; i < sent.size(); i++) {
    for (int j=0; j < sent.size(); j++) {
      fe.addZhaoPairFeatures(i,j,allFeats);
    }
  }
  for (  String f : allFeats) {
    System.out.println(f);
  }
}
Program: 131548
Project: 131548
Buggy source:
public void setHighLowSupport(String support){
  String parentPos;
  boolean haveLow=false;
  int i;
  for (  Pair<Integer,Dir> a : rootPath) {
    i=a.get1();
    if (i == -1) {
      break;
    }
    if (prm.useGoldSyntax) {
      parentPos=sent.get(i).getPos();
    }
 else {
      parentPos=sent.get(i).getPpos();
    }
    if (parentPos.equals(support)) {
      if (!haveLow) {
        haveLow=true;
        this.lowSupport=i;
        this.highSupport=i;
      }
 else {
        this.highSupport=i;
      }
    }
  }
}

Fixed version (ground truth):
public void setHighLowSupport(String support){
  String parentPos;
  boolean haveLow=false;
  int i;
  for (  Pair<Integer,Dir> a : rootPath) {
    i=a.get1();
    if (i == -1) {
      break;
    }
    if (cs.prm.useGoldSyntax) {
      parentPos=sent.get(i).getPos();
    }
 else {
      parentPos=sent.get(i).getPpos();
    }
    if (parentPos.equals(support)) {
      if (!haveLow) {
        haveLow=true;
        this.lowSupport=i;
        this.highSupport=i;
      }
 else {
        this.highSupport=i;
      }
    }
  }
}
Program: 131549
Project: 131549
Buggy source:
public void setParent(){
  if (prm.useGoldSyntax) {
    this.parent=word.getHead() - 1;
  }
 else {
    this.parent=word.getPhead() - 1;
  }
}

Fixed version (ground truth):
public void setParent(){
  if (cs.prm.useGoldSyntax) {
    this.parent=word.getHead() - 1;
  }
 else {
    this.parent=word.getPhead() - 1;
  }
}