Program: 9594
Project: 9594
Buggy source:
private Set<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){
  double alpha=0.7;
  double beta=1 - alpha;
  Map<Slot,Set<Allocation>> slot2Allocations=new HashMap<Slot,Set<Allocation>>();
  Set<WeightedQuery> allQueries=new TreeSet<WeightedQuery>();
  Set<Allocation> allAllocations;
  for (  Template t : templates) {
    allAllocations=new HashSet<Allocation>();
    for (    Slot slot : t.getSlots()) {
      Set<Allocation> allocations=computeAllocation(slot);
      allAllocations.addAll(allocations);
      slot2Allocations.put(slot,allocations);
    }
    int min=Integer.MAX_VALUE;
    int max=Integer.MIN_VALUE;
    for (    Allocation a : allAllocations) {
      if (a.getInDegree() < min) {
        min=a.getInDegree();
      }
      if (a.getInDegree() > max) {
        max=a.getInDegree();
      }
    }
    for (    Allocation a : allAllocations) {
      double prominence=a.getInDegree() / (max - min);
      a.setProminence(prominence);
      double score=alpha * a.getSimilarity() + beta * a.getProminence();
      a.setScore(score);
    }
    Set<WeightedQuery> queries=new HashSet<WeightedQuery>();
    Query cleanQuery=t.getQuery();
    queries.add(new WeightedQuery(cleanQuery));
    Set<WeightedQuery> tmp=new HashSet<WeightedQuery>();
    for (    Slot slot : t.getSlots()) {
      for (      Allocation a : slot2Allocations.get(slot)) {
        for (        WeightedQuery query : queries) {
          if (slot.getSlotType() == SlotType.SYMPROPERTY) {
            Query reversedQuery=new Query(query.getQuery());
            reversedQuery.getTriplesWithVar(slot.getAnchor()).iterator().next().reverse();
            reversedQuery.replaceVarWithURI(slot.getAnchor(),a.getUri());
            WeightedQuery w=new WeightedQuery(reversedQuery);
            double newScore=query.getScore() + a.getScore();
            w.setScore(newScore);
            tmp.add(w);
          }
          Query q=new Query(query.getQuery());
          q.replaceVarWithURI(slot.getAnchor(),a.getUri());
          WeightedQuery w=new WeightedQuery(q);
          double newScore=query.getScore() + a.getScore();
          w.setScore(newScore);
          tmp.add(w);
        }
      }
      queries.clear();
      queries.addAll(tmp);
      tmp.clear();
    }
    for (    WeightedQuery q : queries) {
      q.setScore(q.getScore() / t.getSlots().size());
    }
    allQueries.addAll(queries);
  }
  return allQueries;
}

Fixed version (ground truth):
private Set<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){
  double alpha=0.7;
  double beta=1 - alpha;
  Map<Slot,Set<Allocation>> slot2Allocations=new HashMap<Slot,Set<Allocation>>();
  Set<WeightedQuery> allQueries=new TreeSet<WeightedQuery>();
  Set<Allocation> allAllocations;
  for (  Template t : templates) {
    allAllocations=new HashSet<Allocation>();
    for (    Slot slot : t.getSlots()) {
      Set<Allocation> allocations=computeAllocation(slot);
      allAllocations.addAll(allocations);
      slot2Allocations.put(slot,allocations);
    }
    int min=Integer.MAX_VALUE;
    int max=Integer.MIN_VALUE;
    for (    Allocation a : allAllocations) {
      if (a.getInDegree() < min) {
        min=a.getInDegree();
      }
      if (a.getInDegree() > max) {
        max=a.getInDegree();
      }
    }
    for (    Allocation a : allAllocations) {
      double prominence=a.getInDegree() / (max - min);
      a.setProminence(prominence);
      double score=alpha * a.getSimilarity() + beta * a.getProminence();
      a.setScore(score);
    }
    Set<WeightedQuery> queries=new HashSet<WeightedQuery>();
    Query cleanQuery=t.getQuery();
    queries.add(new WeightedQuery(cleanQuery));
    Set<WeightedQuery> tmp=new HashSet<WeightedQuery>();
    for (    Slot slot : t.getSlots()) {
      for (      Allocation a : slot2Allocations.get(slot)) {
        for (        WeightedQuery query : queries) {
          if (slot.getSlotType() == SlotType.SYMPROPERTY) {
            Query reversedQuery=new Query(query.getQuery());
            reversedQuery.getTriplesWithVar(slot.getAnchor()).iterator().next().reverse();
            reversedQuery.replaceVarWithURI(slot.getAnchor(),a.getUri());
            WeightedQuery w=new WeightedQuery(reversedQuery);
            double newScore=query.getScore() + a.getScore();
            w.setScore(newScore);
            tmp.add(w);
          }
          Query q=new Query(query.getQuery());
          q.replaceVarWithURI(slot.getAnchor(),a.getUri());
          WeightedQuery w=new WeightedQuery(q);
          double newScore=query.getScore() + a.getScore();
          w.setScore(newScore);
          tmp.add(w);
        }
      }
      queries.clear();
      queries.addAll(tmp);
      tmp.clear();
    }
    for (    WeightedQuery q : queries) {
      q.setScore(q.getScore() / t.getSlots().size());
    }
    allQueries.addAll(queries);
    List<Query> qList=new ArrayList<Query>();
    for (    WeightedQuery wQ : queries) {
      qList.add(wQ.getQuery());
    }
    template2Queries.put(t,qList);
  }
  return allQueries;
}