nus-yam/ex-repair huggingface dataset:
Program: 131248
Project: 131248
Buggy source:
@Override public FeatureVector calcFeatureVector(FeExpFamFactor factor,int configId){
  FeTypedFactor f=(FeTypedFactor)factor;
  Enum<?> ft=f.getFactorType();
  VarSet vars=f.getVars();
  int[] vc=vars.getVarConfigAsArray(configId);
  if (ArrayUtils.contains(vc,LinkVar.FALSE)) {
    return emptyFv;
  }
  FeatureVector feats=new FeatureVector();
  if (ft == DepParseFactorTemplate.LINK_UNARY) {
    LinkVar var=(LinkVar)vars.get(0);
    int p=var.getParent();
    int c=var.getChild();
    FastDepParseFe.addArcFactoredMSTFeats(isent,p,c,feats,false,true);
  }
 else   if (ft == DepParseFactorTemplate.LINK_SIBLING) {
    SibFeTypedFactor f2=(SibFeTypedFactor)f;
    FastDepParseFe.add2ndOrderSiblingFeats(isent,f2.p,f2.c,f2.s,feats);
  }
 else   if (ft == DepParseFactorTemplate.LINK_GRANDPARENT) {
    GraFeTypedFactor f2=(GraFeTypedFactor)f;
    FastDepParseFe.add2ndOrderGrandparentFeats(isent,f2.g,f2.p,f2.c,feats);
  }
 else {
    throw new RuntimeException("String_Node_Str" + ft);
  }
  return feats;
}

Fixed version (ground truth):
@Override public FeatureVector calcFeatureVector(FeExpFamFactor factor,int configId){
  int i=0;
  while (alphabet.size() < featureHashMod) {
    alphabet.lookupIndex(i++);
  }
  FeTypedFactor f=(FeTypedFactor)factor;
  Enum<?> ft=f.getFactorType();
  VarSet vars=f.getVars();
  int[] vc=vars.getVarConfigAsArray(configId);
  if (ArrayUtils.contains(vc,LinkVar.FALSE)) {
    return emptyFv;
  }
  FeatureVector feats=new FeatureVector();
  if (ft == DepParseFactorTemplate.LINK_UNARY) {
    LinkVar var=(LinkVar)vars.get(0);
    int p=var.getParent();
    int c=var.getChild();
    FastDepParseFe.addArcFactoredMSTFeats(isent,p,c,feats,false,true);
  }
 else   if (ft == DepParseFactorTemplate.LINK_SIBLING) {
    SibFeTypedFactor f2=(SibFeTypedFactor)f;
    FastDepParseFe.add2ndOrderSiblingFeats(isent,f2.p,f2.c,f2.s,feats);
  }
 else   if (ft == DepParseFactorTemplate.LINK_GRANDPARENT) {
    GraFeTypedFactor f2=(GraFeTypedFactor)f;
    FastDepParseFe.add2ndOrderGrandparentFeats(isent,f2.g,f2.p,f2.c,feats);
  }
 else {
    throw new RuntimeException("String_Node_Str" + ft);
  }
  return feats;
}
Program: 131249
Project: 131249
Buggy source:
public FastDepParseFeatureExtractor(AnnoSentence sent,CorpusStatistics cs,int featureHashMod,FeatureNames alphabet){
  this.isent=new IntAnnoSentence(sent,cs.store);
  this.featureHashMod=featureHashMod;
  int i=0;
  while (alphabet.size() < featureHashMod) {
    alphabet.lookupIndex(i++);
  }
}

Fixed version (ground truth):
public FastDepParseFeatureExtractor(AnnoSentence sent,CorpusStatistics cs,int featureHashMod,FeatureNames alphabet){
  this.isent=new IntAnnoSentence(sent,cs.store);
  this.featureHashMod=featureHashMod;
  this.alphabet=alphabet;
}
Program: 131251
Project: 131251
Buggy source:
private List<FeatTemplate> getFeatTemplatesForSrl(AnnoSentenceCollection sents,CorpusStatisticsPrm csPrm,List<FeatTemplate> unigrams,ValExtractor valExt){
}

Fixed version (ground truth):
private List<FeatTemplate> getFeatTemplatesForSrl(AnnoSentenceCollection inputSents,AnnoSentenceCollection goldSents,CorpusStatisticsPrm csPrm,List<FeatTemplate> unigrams,ValExtractor valExt){
}
Program: 131252
Project: 131252
Buggy source:
@Override public Object call() throws Exception {
  computeInformationGain(t,allTpls,valExts,sents,cs,ig,featCount);
  return null;
}

Fixed version (ground truth):
@Override public Object call() throws Exception {
  computeInformationGain(t,allTpls,valExts,inputSents,goldSents,cs,ig,featCount);
  return null;
}
Program: 131253
Project: 131253
Buggy source:
public IGComputer(int t,List<FeatTemplate> allTpls,List<ValExtractor> valExts,AnnoSentenceCollection sents,CorpusStatistics cs,double[][] ig,int[] featCount){
  super();
  this.t=t;
  this.allTpls=allTpls;
  this.valExts=valExts;
  this.sents=sents;
  this.cs=cs;
  this.ig=ig;
  this.featCount=featCount;
}

Fixed version (ground truth):
public IGComputer(int t,List<FeatTemplate> allTpls,List<ValExtractor> valExts,AnnoSentenceCollection inputSents,AnnoSentenceCollection goldSents,CorpusStatistics cs,double[][] ig,int[] featCount){
  super();
  this.t=t;
  this.allTpls=allTpls;
  this.valExts=valExts;
  this.inputSents=inputSents;
  this.goldSents=goldSents;
  this.cs=cs;
  this.ig=ig;
  this.featCount=featCount;
}
Program: 131254
Project: 131254
Buggy source:
@Override public void train(AnnoSentenceCollection trainInput,AnnoSentenceCollection trainGold,AnnoSentenceCollection devInput,AnnoSentenceCollection devGold){
  featureSelection(trainGold,fePrm);
}

Fixed version (ground truth):
@Override public void train(AnnoSentenceCollection trainInput,AnnoSentenceCollection trainGold,AnnoSentenceCollection devInput,AnnoSentenceCollection devGold){
  featureSelection(trainInput,trainGold,fePrm);
}
Program: 131255
Project: 131255
Buggy source:
/** 
 * Do feature selection and update fePrm with the chosen feature templates.
 */
private static void featureSelection(AnnoSentenceCollection sents,JointNlpFeatureExtractorPrm fePrm){
  if (modelIn != null) {
    return;
  }
  SrlFeatureExtractorPrm srlFePrm=fePrm.srlFePrm;
  removeAts(fePrm);
  if (useTemplates && featureSelection) {
    CorpusStatisticsPrm csPrm=getCorpusStatisticsPrm();
    IGFeatureTemplateSelectorPrm prm=getInformationGainFeatureSelectorPrm();
    SrlFeatTemplates sft=new SrlFeatTemplates(srlFePrm.fePrm.soloTemplates,srlFePrm.fePrm.pairTemplates,null);
    IGFeatureTemplateSelector ig=new IGFeatureTemplateSelector(prm);
    sft=ig.getFeatTemplatesForSrl(sents,csPrm,sft);
    fePrm.srlFePrm.fePrm.soloTemplates=sft.srlSense;
    fePrm.srlFePrm.fePrm.pairTemplates=sft.srlArg;
  }
  if (CorpusHandler.getGoldOnlyAts().contains(AT.SRL) && acl14DepFeats) {
    fePrm.dpFePrm.firstOrderTpls=srlFePrm.fePrm.pairTemplates;
  }
  if (useTemplates) {
    log.info("String_Node_Str" + srlFePrm.fePrm.soloTemplates.size());
    log.info("String_Node_Str" + srlFePrm.fePrm.pairTemplates.size());
    if (senseFeatTplsOut != null) {
      TemplateWriter.write(senseFeatTplsOut,srlFePrm.fePrm.soloTemplates);
    }
    if (argFeatTplsOut != null) {
      TemplateWriter.write(argFeatTplsOut,srlFePrm.fePrm.pairTemplates);
    }
  }
}

Fixed version (ground truth):
/** 
 * Do feature selection and update fePrm with the chosen feature templates.
 */
private static void featureSelection(AnnoSentenceCollection inputSents,AnnoSentenceCollection goldSents,JointNlpFeatureExtractorPrm fePrm){
  if (modelIn != null) {
    return;
  }
  SrlFeatureExtractorPrm srlFePrm=fePrm.srlFePrm;
  removeAts(fePrm);
  if (useTemplates && featureSelection) {
    CorpusStatisticsPrm csPrm=getCorpusStatisticsPrm();
    IGFeatureTemplateSelectorPrm prm=getInformationGainFeatureSelectorPrm();
    SrlFeatTemplates sft=new SrlFeatTemplates(srlFePrm.fePrm.soloTemplates,srlFePrm.fePrm.pairTemplates,null);
    IGFeatureTemplateSelector ig=new IGFeatureTemplateSelector(prm);
    sft=ig.getFeatTemplatesForSrl(inputSents,goldSents,csPrm,sft);
    fePrm.srlFePrm.fePrm.soloTemplates=sft.srlSense;
    fePrm.srlFePrm.fePrm.pairTemplates=sft.srlArg;
  }
  if (CorpusHandler.getGoldOnlyAts().contains(AT.SRL) && acl14DepFeats) {
    fePrm.dpFePrm.firstOrderTpls=srlFePrm.fePrm.pairTemplates;
  }
  if (useTemplates) {
    log.info("String_Node_Str" + srlFePrm.fePrm.soloTemplates.size());
    log.info("String_Node_Str" + srlFePrm.fePrm.pairTemplates.size());
    if (senseFeatTplsOut != null) {
      TemplateWriter.write(senseFeatTplsOut,srlFePrm.fePrm.soloTemplates);
    }
    if (argFeatTplsOut != null) {
      TemplateWriter.write(argFeatTplsOut,srlFePrm.fePrm.pairTemplates);
    }
  }
}
Program: 131256
Project: 131256
Buggy source:
private void ensureHighLowSupport(){
  if (cachedSupports) {
    return;
  }
  if (cs == null) {
    throw new IllegalStateException("String_Node_Str" + "String_Node_Str");
  }
  ensureRootPath();
  String parentPos;
  boolean haveArgLow=false;
  boolean havePredLow=false;
  int i;
  this.lowSupportNoun=-1;
  this.highSupportNoun=-1;
  this.lowSupportVerb=-1;
  this.highSupportVerb=-1;
  for (  Pair<Integer,Dir> a : rootPath) {
    i=a.get1();
    if (i == -1) {
      break;
    }
    parentPos=sent.getPosTag(i);
    if (LanguageConstants.isNoun(parentPos,cs.getLanguage())) {
      if (!haveArgLow) {
        haveArgLow=true;
        this.lowSupportNoun=i;
        this.highSupportNoun=i;
      }
 else {
        this.highSupportNoun=i;
      }
    }
 else     if (LanguageConstants.isVerb(parentPos,cs.getLanguage())) {
      if (!havePredLow) {
        havePredLow=true;
        this.lowSupportVerb=i;
        this.highSupportVerb=i;
      }
 else {
        this.highSupportVerb=i;
      }
    }
  }
  cachedSupports=true;
}

Fixed version (ground truth):
private void ensureHighLowSupport(){
  if (cachedSupports) {
    return;
  }
  if (cs == null) {
    throw new IllegalStateException("String_Node_Str" + "String_Node_Str");
  }
  ensureRootPath();
  String parentPos;
  boolean haveArgLow=false;
  boolean havePredLow=false;
  int i;
  this.lowSupportNoun=-1;
  this.highSupportNoun=-1;
  this.lowSupportVerb=-1;
  this.highSupportVerb=-1;
  if (rootPath != null) {
    for (    Pair<Integer,Dir> a : rootPath) {
      i=a.get1();
      if (i == -1) {
        break;
      }
      parentPos=sent.getPosTag(i);
      if (LanguageConstants.isNoun(parentPos,cs.getLanguage())) {
        if (!haveArgLow) {
          haveArgLow=true;
          this.lowSupportNoun=i;
          this.highSupportNoun=i;
        }
 else {
          this.highSupportNoun=i;
        }
      }
 else       if (LanguageConstants.isVerb(parentPos,cs.getLanguage())) {
        if (!havePredLow) {
          havePredLow=true;
          this.lowSupportVerb=i;
          this.highSupportVerb=i;
        }
 else {
          this.highSupportVerb=i;
        }
      }
    }
  }
  cachedSupports=true;
}
Program: 131257
Project: 131257
Buggy source:
private void ensureDpPathShare(){
  if (dpPathShare != null) {
    return;
  }
  this.dpPathShare=new ArrayList<Pair<Integer,DepTree.Dir>>();
  List<Pair<Integer,Dir>> argRootPath=aTok.getRootPath();
  List<Pair<Integer,Dir>> predRootPath=pTok.getRootPath();
  int i=argRootPath.size() - 1;
  int j=predRootPath.size() - 1;
  Pair<Integer,DepTree.Dir> argP=argRootPath.get(i);
  Pair<Integer,DepTree.Dir> predP=predRootPath.get(j);
  while (argP.equals(predP)) {
    this.dpPathShare.add(argP);
    if (i == 0 || j == 0) {
      break;
    }
    i--;
    j--;
    argP=argRootPath.get(i);
    predP=predRootPath.get(j);
  }
  Collections.reverse(this.dpPathShare);
  int r;
  if (this.dpPathShare.isEmpty()) {
    r=-1;
    this.dpPathPred=new ArrayList<Pair<Integer,Dir>>();
    this.dpPathArg=new ArrayList<Pair<Integer,Dir>>();
  }
 else {
    r=this.dpPathShare.get(0).get1();
    this.dpPathPred=DepTree.getDependencyPath(pidx,r,parents);
    this.dpPathArg=DepTree.getDependencyPath(aidx,r,parents);
  }
}

Fixed version (ground truth):
private void ensureDpPathShare(){
}
Program: 131258
Project: 131258
Buggy source:
/** 
 * Gets features of the form:  path(lca(p,c),root).bc0+dir.noDup children(p).bc0.seq line(p,c).t.noDup
 * @param tpl Structured feature template.
 * @param local Local observations.
 * @param feats The feature list to which this will be added.
 */
protected void addListFeature(FeatTemplate3 tpl,LocalObservations local,List<String> feats){
  PositionList pl=tpl.pl;
  TokProperty prop=tpl.prop;
  EdgeProperty eprop=tpl.eprop;
  ListModifier lmod=tpl.lmod;
  if (prop == null && eprop == null) {
    throw new IllegalStateException("String_Node_Str");
  }
  List<String> vals;
switch (pl) {
case CHILDREN_P:
case NO_FAR_CHILDREN_P:
case CHILDREN_C:
case NO_FAR_CHILDREN_C:
case LINE_P_C:
case LINE_RI_RK:
case BTWN_P_C:
    if (eprop != null) {
      throw new IllegalStateException("String_Node_Str" + eprop + "String_Node_Str"+ tpl);
    }
 else     if (prop == null) {
      throw new IllegalStateException("String_Node_Str");
    }
  List<Integer> posList=getPositionList(pl,local);
vals=getTokPropsForList(prop,posList);
listAndPathHelper(vals,lmod,tpl,feats);
return;
case PATH_P_C:
case PATH_C_LCA:
case PATH_P_LCA:
case PATH_LCA_ROOT:
List<Pair<Integer,Dir>> path=getPath(pl,local);
vals=getTokPropsForPath(prop,eprop,path);
listAndPathHelper(vals,lmod,tpl,feats);
return;
default :
throw new IllegalStateException();
}
}

Fixed version (ground truth):
/** 
 * Gets features of the form:  path(lca(p,c),root).bc0+dir.noDup children(p).bc0.seq line(p,c).t.noDup
 * @param tpl Structured feature template.
 * @param local Local observations.
 * @param feats The feature list to which this will be added.
 */
protected void addListFeature(FeatTemplate3 tpl,LocalObservations local,List<String> feats){
  PositionList pl=tpl.pl;
  TokProperty prop=tpl.prop;
  EdgeProperty eprop=tpl.eprop;
  ListModifier lmod=tpl.lmod;
  if (prop == null && eprop == null) {
    throw new IllegalStateException("String_Node_Str");
  }
  List<String> vals;
switch (pl) {
case CHILDREN_P:
case NO_FAR_CHILDREN_P:
case CHILDREN_C:
case NO_FAR_CHILDREN_C:
case LINE_P_C:
case LINE_RI_RK:
case BTWN_P_C:
    if (eprop != null) {
      throw new IllegalStateException("String_Node_Str" + eprop + "String_Node_Str"+ tpl);
    }
 else     if (prop == null) {
      throw new IllegalStateException("String_Node_Str");
    }
  List<Integer> posList=getPositionList(pl,local);
vals=getTokPropsForList(prop,posList);
listAndPathHelper(vals,lmod,tpl,feats);
return;
case PATH_P_C:
case PATH_C_LCA:
case PATH_P_LCA:
case PATH_LCA_ROOT:
List<Pair<Integer,Dir>> path=getPath(pl,local);
if (path != null) {
vals=getTokPropsForPath(prop,eprop,path);
listAndPathHelper(vals,lmod,tpl,feats);
}
 else {
feats.add(toFeat(tpl.getName(),"String_Node_Str"));
}
return;
default :
throw new IllegalStateException();
}
}
Program: 131259
Project: 131259
Buggy source:
public int getCountOfNonConsecutivesInPath(){
  List<Pair<Integer,Dir>> path=getDependencyPath();
  int count=0;
  if (path.size() > 0) {
    for (int i=1; i < path.size(); i++) {
      int current=path.get(i).get1();
      int previous=path.get(i - 1).get1();
      if (Math.abs(current - previous) != 1) {
        count++;
      }
    }
  }
  return count;
}

Fixed version (ground truth):
public int getCountOfNonConsecutivesInPath(){
  List<Pair<Integer,Dir>> path=getDependencyPath();
  int count=0;
  if (path != null && path.size() > 0) {
    for (int i=1; i < path.size(); i++) {
      int current=path.get(i).get1();
      int previous=path.get(i - 1).get1();
      if (Math.abs(current - previous) != 1) {
        count++;
      }
    }
  }
  return count;
}
Program: 131260
Project: 131260
Buggy source:
private String getOtherFeatSingleton(OtherFeat template,LocalObservations local){
  int pidx=local.getPidx();
  int cidx=local.getCidx();
  FeaturizedTokenPair pair=getFeatTokPair(pidx,cidx);
switch (template) {
case DISTANCE:
    return Integer.toString(Math.abs(pidx - cidx));
case GENEOLOGY:
  return pair.getGeneologicalRelation();
case RELATIVE:
return pair.getRelativePosition();
case CONTINUITY:
return Integer.toString(pair.getCountOfNonConsecutivesInPath());
case PATH_LEN:
return Integer.toString(binInt(pair.getDependencyPath().size(),0,2,5,10,20,30,40));
case SENT_LEN:
return Integer.toString(binInt(fSent.size(),0,2,5,10,20,30,40));
case RULE_IS_UNARY:
return local.getRule().isUnary() ? "String_Node_Str" : "String_Node_Str";
default :
throw new IllegalStateException();
}
}

Fixed version (ground truth):
private String getOtherFeatSingleton(OtherFeat template,LocalObservations local){
  int pidx=local.getPidx();
  int cidx=local.getCidx();
  FeaturizedTokenPair pair=getFeatTokPair(pidx,cidx);
switch (template) {
case DISTANCE:
    return Integer.toString(Math.abs(pidx - cidx));
case GENEOLOGY:
  return pair.getGeneologicalRelation();
case RELATIVE:
return pair.getRelativePosition();
case CONTINUITY:
return Integer.toString(pair.getCountOfNonConsecutivesInPath());
case PATH_LEN:
List<Pair<Integer,Dir>> depPath=pair.getDependencyPath();
int pathLen=depPath == null ? 0 : depPath.size();
return Integer.toString(binInt(pathLen,0,2,5,10,20,30,40));
case SENT_LEN:
return Integer.toString(binInt(fSent.size(),0,2,5,10,20,30,40));
case RULE_IS_UNARY:
return local.getRule().isUnary() ? "String_Node_Str" : "String_Node_Str";
default :
throw new IllegalStateException();
}
}
Program: 131261
Project: 131261
Buggy source:
@Override public void train(AnnoSentenceCollection trainInput,AnnoSentenceCollection trainGold,AnnoSentenceCollection devInput,AnnoSentenceCollection devGold){
  for (  AnnoSentence sent : trainGold) {
    new LabelSequence<String>(alphabet,sent.getPosTags());
  }
  alphabet.stopGrowth();
  mat=new DenseIntegerMatrix(alphabet.size(),alphabet.size());
  mat.fill(0);
  for (  AnnoSentence sent : trainGold) {
    LabelSequence<String> tagSeq=new LabelSequence<String>(alphabet,sent.getPosTags());
    int[] tags=tagSeq.getLabelIds();
    int[] parents=sent.getParents();
    for (int c=0; c < parents.length; c++) {
      int p=parents[c];
      if (p == -1) {
        continue;
      }
      int dist=Math.abs(p - c);
      if (dist > mat.get(tags[p],tags[c])) {
        mat.set(tags[p],tags[c],dist);
      }
    }
  }
}

Fixed version (ground truth):
@Override public void train(AnnoSentenceCollection trainInput,AnnoSentenceCollection trainGold,AnnoSentenceCollection devInput,AnnoSentenceCollection devGold){
  for (  AnnoSentence sent : trainGold) {
    new LabelSequence<String>(alphabet,sent.getPosTags());
  }
  mat=new DenseIntegerMatrix(alphabet.size(),alphabet.size());
  mat.fill(0);
  for (  AnnoSentence sent : trainGold) {
    LabelSequence<String> tagSeq=new LabelSequence<String>(alphabet,sent.getPosTags());
    int[] tags=tagSeq.getLabelIds();
    int[] parents=sent.getParents();
    for (int c=0; c < parents.length; c++) {
      int p=parents[c];
      if (p == -1) {
        continue;
      }
      int dist=Math.abs(p - c);
      if (dist > mat.get(tags[p],tags[c])) {
        mat.set(tags[p],tags[c],dist);
      }
    }
  }
}
Program: 131264
Project: 131264
Buggy source:
@Test public void testExactVsApproxInf2ndOrderGraOnly(){
}

Fixed version (ground truth):
@Test public void testExactVsApproxInf2ndOrderGraOnly(){
  AnnoSentenceCollection sents=AnnoSentenceReaderSpeedTest.readPtbYmConllx();
  int numParams=1000000;
  FgModel model=new FgModel(numParams);
  Prng.seed(123456789101112l);
  model.setRandomStandardNormal();
  CorpusStatistics cs=new CorpusStatistics(new CorpusStatisticsPrm());
  cs.init(sents);
  FeatureNames alphabet=new FeatureNames();
  boolean onlyFast=true;
  int s=0;
  int n=0;
  double sumDiffs=0;
  int diffCount=0;
  int numSentsWithDiffMargs=0;
  int numToksWithDiffParents=0;
  Timer t=new Timer();
  t.start();
  for (  AnnoSentence sent : sents) {
    if (sent.size() > 10) {
      continue;
    }
    FactorGraph fg1, fg2;
    EdgeScores es1, es2;
    FgInferencer bp1, bp2;
    int[] parents1, parents2;
{
      UFgExample ex=get2ndOrderGraOnlyFg(sent,cs,alphabet,numParams,onlyFast);
      fg1=ex.getFgLatPred();
      fg1.updateFromModel(model);
      bp1=DepParseInferenceSpeedTest.runBp(fg1,10);
      DepParseDecoder decode=new DepParseDecoder();
      parents1=decode.decode(bp1,ex,sent);
    }
{
      UFgExample ex=get2ndOrderGraOnlyFg(sent,cs,alphabet,numParams,onlyFast);
      fg2=ex.getFgLatPred();
      fg2.updateFromModel(model);
      bp2=new O2AllGraFgInferencer(fg2,Algebras.LOG_SIGN_ALGEBRA);
      bp2.run();
      DepParseDecoder decode=new DepParseDecoder();
      parents2=decode.decode(bp2,ex,sent);
    }
    try {
      assertEqualMarginals(fg1,bp1,fg2,bp2,1);
    }
 catch (    AssertionError e) {
      numSentsWithDiffMargs++;
    }
    for (int c=0; c < parents1.length; c++) {
      if (parents1[c] != parents2[c]) {
        numToksWithDiffParents++;
      }
    }
    n+=sent.size();
    if (s++ % 1 == 0) {
      t.stop();
      System.out.println(String.format("String_Node_Str",s,n,n / t.totSec()));
      t.start();
    }
    if (s > 102) {
      break;
    }
  }
  t.stop();
  System.out.printf("String_Node_Str",numSentsWithDiffMargs,numToksWithDiffParents);
  System.out.printf("String_Node_Str",sumDiffs / diffCount);
  System.out.println("String_Node_Str" + t.totSec());
  System.out.println("String_Node_Str" + (sents.getNumTokens() / t.totSec()));
}
Program: 131265
Project: 131265
Buggy source:
protected abstract VarTensor getVarBeliefs(Var var);

Fixed version (ground truth):
/** 
 * Gets the normalized variable beliefs in the semiring of the inferencer. 
 */
protected abstract VarTensor getVarBeliefs(Var var);
Program: 131266
Project: 131266
Buggy source:
protected abstract VarTensor getFactorBeliefs(Factor factor);

Fixed version (ground truth):
/** 
 * Gets the normalized factor beliefs in the semiring of the inferencer. 
 */
protected abstract VarTensor getFactorBeliefs(Factor factor);
Program: 131267
Project: 131267
Buggy source:
public abstract double getPartitionBelief();

Fixed version (ground truth):
/** 
 * Gets the partition belief in the semiring of the inferencer. 
 */
public abstract double getPartitionBelief();
Program: 131268
Project: 131268
Buggy source:
/** 
 * Can be used for either sibling or grandparent features. 
 */
private static void addTripletFeatures(IntAnnoSentence sent,int p,int c,int s,FeatureVector feats,byte flags){
  short pWord=(p < 0) ? TOK_WALL_INT : sent.getWord(p);
  short cWord=(c < 0) ? TOK_WALL_INT : sent.getWord(c);
  short sWord=(s < 0) ? TOK_WALL_INT : sent.getWord(s);
  byte pPos=(p < 0) ? TOK_WALL_INT : sent.getCposTag(p);
  byte cPos=(c < 0) ? TOK_WALL_INT : sent.getCposTag(c);
  byte sPos=(s < 0) ? TOK_WALL_INT : sent.getCposTag(s);
  byte templ=0;
  addFeat(feats,encodeFeatureBBB_(templ++,flags,pPos,cPos,sPos));
  addFeat(feats,encodeFeatureBB__(templ++,flags,pPos,sPos));
  addFeat(feats,encodeFeatureBB__(templ++,flags,cPos,sPos));
  if (extraTriplets) {
    addFeat(feats,encodeFeatureBB__(templ++,flags,pPos,cPos));
  }
  addFeat(feats,encodeFeatureSB__(templ++,flags,sWord,pPos));
  addFeat(feats,encodeFeatureSB__(templ++,flags,sWord,cPos));
  addFeat(feats,encodeFeatureSB__(templ++,flags,pWord,sPos));
  addFeat(feats,encodeFeatureSB__(templ++,flags,cWord,sPos));
  if (extraTriplets) {
    addFeat(feats,encodeFeatureSB__(templ++,flags,cWord,pPos));
    addFeat(feats,encodeFeatureSB__(templ++,flags,pWord,cPos));
  }
  addFeat(feats,encodeFeatureSS__(templ++,flags,pWord,sWord));
  addFeat(feats,encodeFeatureSS__(templ++,flags,cWord,sWord));
  if (extraTriplets) {
    addFeat(feats,encodeFeatureSS__(templ++,flags,pWord,cWord));
  }
}

Fixed version (ground truth):
/** 
 * Can be used for either sibling or grandparent features. 
 */
private static void addTripletFeatures(IntAnnoSentence sent,int p,int c,int s,FeatureVector feats,byte flags){
  short pWord=(p < 0) ? TOK_WALL_INT : sent.getWord(p);
  short cWord=(c < 0) ? TOK_WALL_INT : sent.getWord(c);
  short sWord=(s < 0) ? TOK_WALL_INT : sent.getWord(s);
  byte pCpos=(p < 0) ? TOK_WALL_INT : sent.getCposTag(p);
  byte cCpos=(c < 0) ? TOK_WALL_INT : sent.getCposTag(c);
  byte sCpos=(s < 0) ? TOK_WALL_INT : sent.getCposTag(s);
  byte templ=0;
  addFeat(feats,encodeFeatureBBB_(templ++,flags,pCpos,cCpos,sCpos));
  addFeat(feats,encodeFeatureBB__(TriTs.HQ_SQ,flags,pCpos,sCpos));
  addFeat(feats,encodeFeatureBB__(TriTs.MQ_SQ,flags,cCpos,sCpos));
  if (extraTriplets) {
    addFeat(feats,encodeFeatureBB__(TriTs.HQ_MQ,flags,pCpos,cCpos));
  }
  addFeat(feats,encodeFeatureSB__(TriTs.SW_HQ,flags,sWord,pCpos));
  addFeat(feats,encodeFeatureSB__(TriTs.SW_MQ,flags,sWord,cCpos));
  addFeat(feats,encodeFeatureSB__(TriTs.HW_SQ,flags,pWord,sCpos));
  addFeat(feats,encodeFeatureSB__(TriTs.MW_SQ,flags,cWord,sCpos));
  if (extraTriplets) {
    addFeat(feats,encodeFeatureSB__(TriTs.MW_HQ,flags,cWord,pCpos));
    addFeat(feats,encodeFeatureSB__(TriTs.HW_MQ,flags,pWord,cCpos));
  }
  addFeat(feats,encodeFeatureSS__(TriTs.HW_SW,flags,pWord,sWord));
  addFeat(feats,encodeFeatureSS__(TriTs.MW_SW,flags,cWord,sWord));
  if (extraTriplets) {
    addFeat(feats,encodeFeatureSS__(TriTs.HW_MW,flags,pWord,cWord));
  }
}
Program: 131270
Project: 131270
Buggy source:
private AnnoSentence decode(UFgExample ex,MbrDecoder mbrDecoder,FgInferencer inf,AnnoSentence sent){
  JointNlpFactorGraph fg=(JointNlpFactorGraph)ex.getOriginalFactorGraph();
  int n=fg.getSentenceLength();
  VarConfig mbrVarConfig=mbrDecoder.getMbrVarConfig();
  AnnoSentence predSent=sent.getShallowCopy();
  SrlGraph srlGraph=SrlDecoder.getSrlGraphFromVarConfig(mbrVarConfig,n);
  if (srlGraph != null) {
    predSent.setSrlGraph(srlGraph);
  }
  int[] parents=(new DepParseDecoder()).decode(inf,ex,sent);
  if (parents != null) {
    DepParseDecoder.addDepParseAssignment(parents,fg.getDpBuilder(),mbrVarConfig);
    predSent.setParents(parents);
  }
  DepEdgeMask depEdgeMask=(new DepEdgeMaskDecoder(prm.maskPrm)).decode(inf,ex,sent);
  if (depEdgeMask != null) {
    predSent.setDepEdgeMask(depEdgeMask);
  }
  List<String> rels=RelationsDecoder.getRelLabelsFromVarConfig(mbrVarConfig);
  if (rels != null) {
    predSent.setRelLabels(rels);
  }
  return predSent;
}

Fixed version (ground truth):
private AnnoSentence decode(UFgExample ex,MbrDecoder mbrDecoder,FgInferencer inf,AnnoSentence sent){
  JointNlpFactorGraph fg=(JointNlpFactorGraph)ex.getOriginalFactorGraph();
  int n=fg.getSentenceLength();
  VarConfig mbrVarConfig=mbrDecoder.getMbrVarConfig();
  AnnoSentence predSent=sent.getShallowCopy();
  SrlGraph srlGraph=SrlDecoder.getSrlGraphFromVarConfig(mbrVarConfig,n);
  if (srlGraph != null) {
    predSent.setSrlGraph(srlGraph);
  }
  int[] parents=(new DepParseDecoder()).decode(inf,ex,sent);
  if (parents != null) {
    DepParseDecoder.addDepParseAssignment(parents,fg.getDpBuilder(),mbrVarConfig);
    predSent.setParents(parents);
  }
  List<String> rels=RelationsDecoder.getRelLabelsFromVarConfig(mbrVarConfig);
  if (rels != null) {
    predSent.setRelLabels(rels);
  }
  return predSent;
}
Program: 131272
Project: 131272
Buggy source:
public static int getNumBtwn(AnnoSentence sent,NerMention m1,NerMention m2){
  Span btwn=Span.getSpanBtwn(m1.getSpan(),m2.getSpan());
  int numMentsBtwn=0;
  for (  NerMention m : sent.getNamedEntities()) {
    if (m != m1 && m != m2 && btwn.contains(m.getSpan().start())) {
      numMentsBtwn++;
    }
  }
  return numMentsBtwn;
}

Fixed version (ground truth):
public static int getNumBtwn(AnnoSentence sent,NerMention m1,NerMention m2){
  int m1h=m1.getHead();
  int m2h=m2.getHead();
  Span btwn=new Span(Math.min(m1h,m2h),Math.max(m1h,m2h));
  int numMentsBtwn=0;
  for (  NerMention m : sent.getNamedEntities()) {
    if (m != m1 && m != m2 && btwn.contains(m.getSpan().start())) {
      numMentsBtwn++;
    }
  }
  return numMentsBtwn;
}
Program: 131273
Project: 131273
Buggy source:
@Override public void train(AnnoSentenceCollection trainInput,AnnoSentenceCollection trainGold,AnnoSentenceCollection devInput,AnnoSentenceCollection devGold){
  for (  Annotator anno : pipeline) {
    if (anno instanceof Trainable) {
      ((Trainable)anno).train(trainInput,trainGold,devInput,devGold);
    }
    anno.annotate(trainInput);
    anno.annotate(devInput);
  }
}

Fixed version (ground truth):
@Override public void train(AnnoSentenceCollection trainInput,AnnoSentenceCollection trainGold,AnnoSentenceCollection devInput,AnnoSentenceCollection devGold){
  for (  Annotator anno : pipeline) {
    if (anno instanceof Trainable) {
      ((Trainable)anno).train(trainInput,trainGold,devInput,devGold);
    }
    anno.annotate(trainInput);
    if (devInput != null) {
      anno.annotate(devInput);
    }
  }
}
Program: 131274
Project: 131274
Buggy source:
private void loadTest() throws IOException {
  AnnoSentenceReaderPrm prm=getDefaultReaderPrm();
  prm.name="String_Node_Str";
  prm.maxNumSentences=testMaxNumSentences;
  prm.maxSentenceLength=testMaxSentenceLength;
  AnnoSentenceReader reader=new AnnoSentenceReader(prm);
  reader.loadSents(test,testType);
  testGoldSents=reader.getData();
  testGoldSents=testGoldSents.getWithAtsRemoved(getRemoveAts());
  if (testGoldOut != null) {
    AnnoSentenceWriterPrm wPrm=new AnnoSentenceWriterPrm();
    wPrm.name="String_Node_Str";
    AnnoSentenceWriter writer=new AnnoSentenceWriter(wPrm);
    writer.write(testGoldOut,getTestTypeOut(),testGoldSents);
  }
  testInputSents=testGoldSents.getWithAtsRemoved(getGoldOnlyAts());
}

Fixed version (ground truth):
private void loadTest() throws IOException {
  AnnoSentenceReaderPrm prm=getDefaultReaderPrm();
  prm.name="String_Node_Str";
  prm.maxNumSentences=testMaxNumSentences;
  prm.maxSentenceLength=testMaxSentenceLength;
  AnnoSentenceReader reader=new AnnoSentenceReader(prm);
  reader.loadSents(test,testType);
  testGoldSents=reader.getData();
  testGoldSents=testGoldSents.getWithAtsRemoved(getRemoveAts());
  if (testGoldSents != null && testGoldOut != null) {
    AnnoSentenceWriterPrm wPrm=new AnnoSentenceWriterPrm();
    wPrm.name="String_Node_Str";
    AnnoSentenceWriter writer=new AnnoSentenceWriter(wPrm);
    writer.write(testGoldOut,getTestTypeOut(),testGoldSents);
  }
  testInputSents=testGoldSents.getWithAtsRemoved(getGoldOnlyAts());
}
Program: 131275
Project: 131275
Buggy source:
private void loadDev() throws IOException {
  if (dev != null && devType != null) {
    readDev();
  }
  if (hasTrain() && propTrainAsDev > 0) {
    loadTrainAsDev();
  }
  if (devGoldOut != null) {
    AnnoSentenceWriterPrm wPrm=new AnnoSentenceWriterPrm();
    wPrm.name="String_Node_Str";
    AnnoSentenceWriter writer=new AnnoSentenceWriter(wPrm);
    writer.write(devGoldOut,getDevTypeOut(),devGoldSents);
  }
}

Fixed version (ground truth):
private void loadDev() throws IOException {
  if (dev != null && devType != null) {
    readDev();
  }
  if (hasTrain() && propTrainAsDev > 0) {
    loadTrainAsDev();
  }
  if (devGoldSents != null && devGoldOut != null) {
    AnnoSentenceWriterPrm wPrm=new AnnoSentenceWriterPrm();
    wPrm.name="String_Node_Str";
    AnnoSentenceWriter writer=new AnnoSentenceWriter(wPrm);
    writer.write(devGoldOut,getDevTypeOut(),devGoldSents);
  }
}
Program: 131276
Project: 131276
Buggy source:
private Function getValidationFn(final AnnoSentenceCollection devInput,final AnnoSentenceCollection devGold){
  final Annotator anno=this;
  final Evaluator eval;
  if (CorpusHandler.getPredAts().equals(Lists.getList(AT.DEP_TREE))) {
    eval=new DepParseEvaluator();
  }
 else   if (CorpusHandler.getPredAts().equals(Lists.getList(AT.SRL))) {
    eval=new SrlEvaluator();
  }
 else   if (CorpusHandler.getPredAts().equals(Lists.getList(AT.REL_LABELS))) {
    eval=new RelationEvaluator();
  }
 else {
    log.warn("String_Node_Str");
    return null;
  }
  return new Function(){
    @Override public double getValue(    IntDoubleVector point){
      anno.annotate(devInput);
      return eval.evaluate(devInput,devGold,"String_Node_Str");
    }
    @Override public int getNumDimensions(){
      return -1;
    }
  }
;
}

Fixed version (ground truth):
private Function getValidationFn(final AnnoSentenceCollection devInput,final AnnoSentenceCollection devGold){
  if (devInput == null || devGold == null) {
    return null;
  }
  final Annotator anno=this;
  final Evaluator eval;
  if (CorpusHandler.getPredAts().equals(Lists.getList(AT.DEP_TREE))) {
    eval=new DepParseEvaluator();
  }
 else   if (CorpusHandler.getPredAts().equals(Lists.getList(AT.SRL))) {
    eval=new SrlEvaluator();
  }
 else   if (CorpusHandler.getPredAts().equals(Lists.getList(AT.REL_LABELS))) {
    eval=new RelationEvaluator();
  }
 else {
    log.warn("String_Node_Str");
    return null;
  }
  return new Function(){
    @Override public double getValue(    IntDoubleVector point){
      anno.annotate(devInput);
      return eval.evaluate(devInput,devGold,"String_Node_Str");
    }
    @Override public int getNumDimensions(){
      return -1;
    }
  }
;
}
Program: 131277
Project: 131277
Buggy source:
public FactorTemplate(VarSet vars,FeatureNames 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;
}

Fixed version (ground truth):
public FactorTemplate(VarSet vars,FeatureNames 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;
  Var[] tmpVars=new Var[vars.size()];
  int i=0;
  for (  Var v : vars) {
    tmpVars[i++]=new Var(v.getType(),v.getNumStates(),v.getName(),v.getStateNames());
  }
  this.vars=new VarSet(tmpVars);
}
Program: 131278
Project: 131278
Buggy source:
private void addEmbFeat(String fname,int i,FeatureNames alphabet,FeatureVector fv){
  if (i < 0 || sent.size() <= i) {
    return;
  }
  double[] embed=sent.getEmbed(i);
  for (int d=0; d < embed.length; d++) {
    int fidx=alphabet.lookupIndex(fname + "String_Node_Str" + d);
    fv.add(fidx,embed[d]);
  }
}

Fixed version (ground truth):
private void addEmbFeat(String fname,int i,FeatureNames alphabet,FeatureVector fv){
  if (i < 0 || sent.size() <= i) {
    return;
  }
  double[] embed=sent.getEmbed(i);
  for (int d=0; d < embed.length; d++) {
    int fidx=alphabet.lookupIndex(fname + "String_Node_Str" + d);
    if (fidx != -1) {
      fv.add(fidx,embed[d]);
    }
  }
}
Program: 131279
Project: 131279
Buggy source:
/** 
 * Prune to only the most likely K (e.g. 10) heads per token from the first-order model. Also for each token, prune any heads for which the marginal probability is less than propMaxMarg (e.g. 0.0001) times the maximum head marginal for that token. This follows footnote 10 in Martins et al. (2013).
 */
@Override public DepEdgeMask decode(FgInferencer inf,UFgExample ex,AnnoSentence sent){
  FactorGraph fg=ex.getFgLatPred();
  int n=sent.size();
  Pair<EdgeScores,Integer> pair=DepParseDecoder.getEdgeScores(inf,fg,n);
  EdgeScores scores=pair.get1();
  int linkVarCount=pair.get2();
  if (linkVarCount > 0) {
    return getDepEdgeMask(scores,prm.pruneMargProp,prm.maxPrunedHeads);
  }
 else {
    return null;
  }
}

Fixed version (ground truth):
/** 
 * Prune to only the most likely K (e.g. 10) heads per token from the first-order model. Also for each token, prune any heads for which the marginal probability is less than propMaxMarg (e.g. 0.0001) times the maximum head marginal for that token. This follows footnote 10 in Martins et al. (2013).
 */
@Override public DepEdgeMask decode(FgInferencer inf,UFgExample ex,AnnoSentence sent){
  FactorGraph fg=ex.getFgLatPred();
  int n=sent.size();
  Pair<EdgeScores,Integer> pair=DepParseDecoder.getEdgeScores(inf,fg,n);
  EdgeScores scores=pair.get1();
  int linkVarCount=pair.get2();
  if (linkVarCount > 0) {
    return getDepEdgeMask(scores,prm.pruneMargProp,prm.maxPrunedHeads,prm.includeMbrParse);
  }
 else {
    return null;
  }
}
Program: 131280
Project: 131280
Buggy source:
private static void checkValidMask(int n,DepEdgeMask mask){
  for (int c=0; c < n; c++) {
    if (mask.getParentCount(c) == 0) {
      String msg=String.format("String_Node_Str") + mask;
      throw new IllegalStateException(msg);
    }
  }
}

Fixed version (ground truth):
private static void checkValidMask(int n,DepEdgeMask mask){
  for (int c=0; c < n; c++) {
    if (mask.getParentCount(c) == 0) {
      String msg=String.format("String_Node_Str") + mask;
      throw new IllegalStateException(msg);
    }
  }
  if (InsideOutsideDepParse.singleRoot && !mask.allowsSingleRootTrees()) {
    log.warn("String_Node_Str");
  }
 else   if (!InsideOutsideDepParse.singleRoot && !mask.allowsMultiRootTrees()) {
    log.warn("String_Node_Str");
  }
}
Program: 131281
Project: 131281
Buggy source:
/** 
 * See   {@link #decode(FgInferencer,UFgExample,AnnoSentence)}. 
 */
public static DepEdgeMask getDepEdgeMask(EdgeScores scores,double propMaxMarg,int maxPrunedHeads){
  int n=scores.root.length;
  DepEdgeMask mask=new DepEdgeMask(n,true);
  pruneByCount(scores,maxPrunedHeads,mask);
  pruneByMaxMarginal(scores,propMaxMarg,mask);
  checkValidMask(n,mask);
  return mask;
}

Fixed version (ground truth):
/** 
 * See   {@link #decode(FgInferencer,UFgExample,AnnoSentence)}. 
 */
public static DepEdgeMask getDepEdgeMask(EdgeScores scores,double propMaxMarg,int maxPrunedHeads,boolean includeMbrParse){
  int n=scores.root.length;
  DepEdgeMask mask=new DepEdgeMask(n,true);
  pruneByCount(scores,maxPrunedHeads,mask);
  pruneByMaxMarginal(scores,propMaxMarg,mask);
  if (includeMbrParse) {
    mask.keepEdgesFromTree(DepParseDecoder.getParents(scores));
  }
  checkValidMask(n,mask);
  return mask;
}
Program: 131282
Project: 131282
Buggy source:
@Test public void testGetDepEdgeMaskCount(){
  DepEdgeMask mask=DepEdgeMaskDecoder.getDepEdgeMask(scores,0,99);
  System.out.println(mask);
  assertNoneArePruned(mask);
  mask=DepEdgeMaskDecoder.getDepEdgeMask(scores,0,1);
  System.out.println(mask);
  assertOnlyMostLikelyAreKept(mask);
}

Fixed version (ground truth):
@Test public void testGetDepEdgeMaskCount(){
  DepEdgeMask mask=DepEdgeMaskDecoder.getDepEdgeMask(scores,0,99,true);
  System.out.println(mask);
  assertNoneArePruned(mask);
  mask=DepEdgeMaskDecoder.getDepEdgeMask(scores,0,1,true);
  System.out.println(mask);
  assertOnlyMostLikelyAreKept(mask);
}
Program: 131283
Project: 131283
Buggy source:
@Test public void testGetDepEdgeMaskPropMaxMarg(){
  double propMaxMarg=0.1;
  DepEdgeMask mask=DepEdgeMaskDecoder.getDepEdgeMask(scores,propMaxMarg,99);
  System.out.println(mask);
  assertNoneArePruned(mask);
  propMaxMarg=0.5;
  mask=DepEdgeMaskDecoder.getDepEdgeMask(scores,propMaxMarg,99);
  System.out.println(mask);
  assertOnlyMostLikelyAreKept(mask);
}

Fixed version (ground truth):
@Test public void testGetDepEdgeMaskPropMaxMarg(){
  double propMaxMarg=0.1;
  DepEdgeMask mask=DepEdgeMaskDecoder.getDepEdgeMask(scores,propMaxMarg,99,true);
  System.out.println(mask);
  assertNoneArePruned(mask);
  propMaxMarg=0.5;
  mask=DepEdgeMaskDecoder.getDepEdgeMask(scores,propMaxMarg,99,true);
  System.out.println(mask);
  assertOnlyMostLikelyAreKept(mask);
}
Program: 131284
Project: 131284
Buggy source:
public static int[] getParents(EdgeScores scores){
  int n=scores.root.length;
  int[] parents=new int[n];
  Arrays.fill(parents,DepTree.EMPTY_POSITION);
  ProjectiveDependencyParser.parseSingleRoot(scores.root,scores.child,parents);
  return parents;
}

Fixed version (ground truth):
public static int[] getParents(EdgeScores scores){
  int n=scores.root.length;
  int[] parents=new int[n];
  Arrays.fill(parents,DepTree.EMPTY_POSITION);
  if (InsideOutsideDepParse.singleRoot) {
    ProjectiveDependencyParser.parseSingleRoot(scores.root,scores.child,parents);
  }
 else {
    ProjectiveDependencyParser.parseMultiRoot(scores.root,scores.child,parents);
  }
  return parents;
}
Program: 131287
Project: 131287
Buggy source:
public static Pair<List<LabeledSpan>,IntArrayList> getSpansFromBIO(List<String> tags){
}

Fixed version (ground truth):
public static Pair<List<LabeledSpan>,IntArrayList> getSpansFromBIO(List<String> tags,boolean includeOutside){
}
Program: 131288
Project: 131288
Buggy source:
private void addEmbFeat(String fname,int i,ObjFeatVec<String> fv){
  if (i < 0 || sent.size() <= i) {
    return;
  }
  double[] embed=sent.getEmbed(i);
  for (int d=0; d < embed.length; d++) {
    fv.add(fname + "String_Node_Str" + d,embed[d]);
  }
}

Fixed version (ground truth):
private void addEmbFeat(String fname,int i,ObjFeatVec<String> fv){
  if (i < 0 || sent.size() <= i) {
    return;
  }
  double[] embed=sent.getEmbed(i);
  if (embed != null) {
    for (int d=0; d < embed.length; d++) {
      fv.add(fname + "String_Node_Str" + d,embed[d]);
    }
  }
}
Program: 131289
Project: 131289
Buggy source:
private LFgExample getExample(AnnoSentence sent,int[] parents,boolean labeledExample){
  FeatureExtractor fe=prm.dpFePrm.onlyFast ? new FastDepParseFeatureExtractor(sent,cs,prm.dpFePrm.featureHashMod) : new DepParseFeatureExtractor(prm.dpFePrm,sent,cs,feAlphabet);
  fe=new FeatureCache(fe);
  FactorGraph fg=new FactorGraph();
  DepParseFactorGraphBuilder dp=new DepParseFactorGraphBuilder(prm.dpPrm);
  dp.build(sent.getWords(),sent.getDepEdgeMask(),fe,fg);
  VarConfig goldConfig=new VarConfig();
  addDepParseTrainAssignment(parents,dp,goldConfig);
  if (labeledExample) {
    return new LabeledFgExample(fg,goldConfig,fe);
  }
 else {
    return new UnlabeledFgExample(fg,goldConfig,fe);
  }
}

Fixed version (ground truth):
private LFgExample getExample(AnnoSentence sent,int[] parents,boolean labeledExample){
  FeatureExtractor fe=prm.dpFePrm.onlyFast ? new FastDepParseFeatureExtractor(sent,cs,prm.dpFePrm.featureHashMod,feAlphabet) : new DepParseFeatureExtractor(prm.dpFePrm,sent,cs,feAlphabet);
  fe=new FeatureCache(fe);
  FactorGraph fg=new FactorGraph();
  DepParseFactorGraphBuilder dp=new DepParseFactorGraphBuilder(prm.dpPrm);
  dp.build(sent.getWords(),sent.getDepEdgeMask(),fe,fg);
  VarConfig goldConfig=new VarConfig();
  addDepParseTrainAssignment(parents,dp,goldConfig);
  if (labeledExample) {
    return new LabeledFgExample(fg,goldConfig,fe);
  }
 else {
    return new UnlabeledFgExample(fg,goldConfig,fe);
  }
}
Program: 131290
Project: 131290
Buggy source:
public static UFgExample get1stOrderFg(AnnoSentence sent,CorpusStatistics cs,FeatureNames alphabet,int numParams,boolean onlyFast){
  FactorGraph fg=new FactorGraph();
  DepParseFeatureExtractorPrm fePrm=new DepParseFeatureExtractorPrm();
  fePrm.featureHashMod=numParams;
  fePrm.firstOrderTpls=TemplateSets.getFromResource(TemplateSets.mcdonaldDepFeatsResource);
  FeatureExtractor fe=onlyFast ? new FastDepParseFeatureExtractor(sent,cs,numParams) : new DepParseFeatureExtractor(fePrm,sent,cs,alphabet);
  DepParseFactorGraphBuilderPrm fgPrm=new DepParseFactorGraphBuilderPrm();
  fgPrm.grandparentFactors=false;
  fgPrm.siblingFactors=false;
  DepParseFactorGraphBuilder builder=new DepParseFactorGraphBuilder(fgPrm);
  builder.build(sent,fe,fg);
  UnlabeledFgExample ex=new UnlabeledFgExample(fg,new VarConfig());
  return ex;
}

Fixed version (ground truth):
public static UFgExample get1stOrderFg(AnnoSentence sent,CorpusStatistics cs,FeatureNames alphabet,int numParams,boolean onlyFast){
  FactorGraph fg=new FactorGraph();
  DepParseFeatureExtractorPrm fePrm=new DepParseFeatureExtractorPrm();
  fePrm.featureHashMod=numParams;
  fePrm.firstOrderTpls=TemplateSets.getFromResource(TemplateSets.mcdonaldDepFeatsResource);
  FeatureExtractor fe=onlyFast ? new FastDepParseFeatureExtractor(sent,cs,numParams,alphabet) : new DepParseFeatureExtractor(fePrm,sent,cs,alphabet);
  DepParseFactorGraphBuilderPrm fgPrm=new DepParseFactorGraphBuilderPrm();
  fgPrm.grandparentFactors=false;
  fgPrm.siblingFactors=false;
  DepParseFactorGraphBuilder builder=new DepParseFactorGraphBuilder(fgPrm);
  builder.build(sent,fe,fg);
  UnlabeledFgExample ex=new UnlabeledFgExample(fg,new VarConfig());
  return ex;
}
Program: 131291
Project: 131291
Buggy source:
public FastDepParseFeatureExtractor(AnnoSentence sent,CorpusStatistics cs,int featureHashMod){
  this.isent=new IntAnnoSentence(sent,cs.store);
  this.featureHashMod=featureHashMod;
}

Fixed version (ground truth):
public FastDepParseFeatureExtractor(AnnoSentence sent,CorpusStatistics cs,int featureHashMod,FeatureNames alphabet){
  this.isent=new IntAnnoSentence(sent,cs.store);
  this.featureHashMod=featureHashMod;
  int i=0;
  while (alphabet.size() < featureHashMod) {
    alphabet.lookupIndex(i++);
  }
}
Program: 131293
Project: 131293
Buggy source:
private void accum(IntDoubleVector params,int[] batch,final Accumulator ac){
  boolean isFullDataset=(batch.length == numExamples);
  if (isFullDataset) {
    ac.accumValue=true;
    ac.accumTrainLoss=true;
    ac.accumDevLoss=true;
    ac.accumWeight=true;
  }
  if (ac.accumGradient) {
    this.gradient.zero();
    ac.gradient=this.gradient;
  }
  model.setParams(params);
  if (numThreads == 1) {
    for (int i=0; i < batch.length; i++) {
      log.trace("String_Node_Str" + i);
      exObj.accum(model,batch[i],ac);
    }
  }
 else {
    TaskFactory<Object> factory=new TaskFactory<Object>(){
      public Callable<Object> getTask(      int i){
        return new AccumValueGradientOfExample(ac,i);
      }
    }
;
    Threads.safelyParallelizeBatch(pool,batch,factory);
  }
  if (ac.accumValue) {
    ac.value/=batch.length;
  }
  if (ac.accumGradient) {
    ac.gradient.scale(1.0 / batch.length);
  }
  if (isFullDataset) {
    log.info(String.format("String_Node_Str",ac.value,ac.trainLoss,ac.devLoss,ac.weight));
    exObj.report();
  }
}

Fixed version (ground truth):
private void accum(IntDoubleVector params,int[] batch,final Accumulator ac){
  boolean isFullDataset=(batch.length == numExamples);
  if (isFullDataset) {
    ac.accumValue=true;
    ac.accumTrainLoss=true;
    ac.accumDevLoss=true;
    ac.accumWeight=true;
  }
  if (ac.accumGradient) {
    if (isFullDataset) {
      this.gradient.zero();
      ac.gradient=this.gradient;
    }
 else {
      ac.gradient=this.gradient.getSparseZeroedCopy();
    }
  }
  model.setParams(params);
  if (numThreads == 1) {
    for (int i=0; i < batch.length; i++) {
      log.trace("String_Node_Str" + i);
      exObj.accum(model,batch[i],ac);
    }
  }
 else {
    TaskFactory<Object> factory=new TaskFactory<Object>(){
      public Callable<Object> getTask(      int i){
        return new AccumValueGradientOfExample(ac,i);
      }
    }
;
    Threads.safelyParallelizeBatch(pool,batch,factory);
  }
  if (ac.accumValue) {
    ac.value/=batch.length;
  }
  if (ac.accumGradient) {
    ac.gradient.scale(1.0 / batch.length);
  }
  if (isFullDataset) {
    log.info(String.format("String_Node_Str",ac.value,ac.trainLoss,ac.devLoss,ac.weight));
    exObj.report();
  }
}
Program: 131294
Project: 131294
Buggy source:
private void backwardGlobalFactorToVar(GlobalFactor globalFac){
  FgNode node=fg.getNode(globalFac);
  VarTensor[] inMsgs=getMsgs(node,msgs,CUR_MSG,IN_MSG);
  VarTensor[] inMsgsAdj=getMsgs(node,msgsAdj,CUR_MSG,IN_MSG);
  VarTensor[] outMsgsAdj=getMsgs(node,msgsAdj,NEW_MSG,OUT_MSG);
  globalFac.backwardCreateMessages(inMsgs,outMsgsAdj,inMsgsAdj);
}

Fixed version (ground truth):
private void backwardGlobalFactorToVar(GlobalFactor globalFac){
  if (globalFac.getVars().size() == 0) {
    return;
  }
  FgNode node=fg.getNode(globalFac);
  VarTensor[] inMsgs=getMsgs(node,msgs,CUR_MSG,IN_MSG);
  VarTensor[] inMsgsAdj=getMsgs(node,msgsAdj,CUR_MSG,IN_MSG);
  VarTensor[] outMsgsAdj=getMsgs(node,msgsAdj,NEW_MSG,OUT_MSG);
  globalFac.backwardCreateMessages(inMsgs,outMsgsAdj,inMsgsAdj);
}
Program: 131295
Project: 131295
Buggy source:
private void forwardGlobalFacToVar(GlobalFactor globalFac){
  log.trace("String_Node_Str");
  FgNode node=fg.getNode(globalFac);
  VarTensor[] inMsgs=getMsgs(node,msgs,CUR_MSG,IN_MSG);
  VarTensor[] outMsgs=getMsgs(node,msgs,NEW_MSG,OUT_MSG);
  globalFac.createMessages(inMsgs,outMsgs);
}

Fixed version (ground truth):
private void forwardGlobalFacToVar(GlobalFactor globalFac){
  if (globalFac.getVars().size() == 0) {
    return;
  }
  log.trace("String_Node_Str");
  FgNode node=fg.getNode(globalFac);
  VarTensor[] inMsgs=getMsgs(node,msgs,CUR_MSG,IN_MSG);
  VarTensor[] outMsgs=getMsgs(node,msgs,NEW_MSG,OUT_MSG);
  globalFac.createMessages(inMsgs,outMsgs);
}
Program: 131296
Project: 131296
Buggy source:
public int hashCode(){
  throw new RuntimeException("String_Node_Str");
}

Fixed version (ground truth):
@Override public int hashCode(){
  final int prime=31;
  int result=1;
  result=prime * result + ((entitySubType == null) ? 0 : entitySubType.hashCode());
  result=prime * result + ((entityType == null) ? 0 : entityType.hashCode());
  result=prime * result + head;
  result=prime * result + ((id == null) ? 0 : id.hashCode());
  result=prime * result + ((phraseType == null) ? 0 : phraseType.hashCode());
  result=prime * result + ((span == null) ? 0 : span.hashCode());
  return result;
}