Program: 177728
Project: 177728
Buggy source:
public static void main(String[] args) throws NumberFormatException, TException, UnsupportedEncodingException {
  ParameterBroker params=new ParameterBroker("String_Node_Str");
  PrintStream out=new PrintStream(System.out,true,"String_Node_Str");
  PrintStream err=new PrintStream(System.err,true,"String_Node_Str");
  GQueries trainingQueries=new GQueriesJsonImpl();
  trainingQueries.setMetadataField("String_Node_Str");
  trainingQueries.read(params.getParamValue(TRAINING_QUERIES));
  GQueries queries=new GQueriesJsonImpl();
  queries.setMetadataField("String_Node_Str");
  queries.read(params.getParamValue(QUERIES_OPTION));
  Qrels qrels=new Qrels(params.getParamValue(QRELS_OPTION),false,1);
  int numResults=1000;
  try {
    if (params.getParamValue(NUM_RESULTS_OPTION) != null) {
      numResults=Integer.parseInt(params.getParamValue(NUM_RESULTS_OPTION));
    }
  }
 catch (  NumberFormatException e) {
    err.println("String_Node_Str" + NUM_RESULTS_OPTION + "String_Node_Str"+ params.getParamValue(NUM_RESULTS_OPTION));
    System.exit(-1);
  }
  String group=params.getParamValue(GROUP_OPTION);
  if (group == null) {
    err.println("String_Node_Str" + GROUP_OPTION + "String_Node_Str");
    System.exit(-1);
  }
  String token=params.getParamValue(TOKEN_OPTION);
  if (group == null) {
    err.println("String_Node_Str" + TOKEN_OPTION + "String_Node_Str");
    System.exit(-1);
  }
  int trainingPort=9090;
  try {
    if (params.getParamValue(TRAINING_PORT) != null) {
      trainingPort=Integer.parseInt(params.getParamValue(TRAINING_PORT));
    }
  }
 catch (  NumberFormatException e) {
    err.println("String_Node_Str" + TRAINING_PORT + "String_Node_Str"+ params.getParamValue(TRAINING_PORT));
    System.exit(-1);
  }
  int testingPort=9091;
  try {
    if (params.getParamValue(TESTING_PORT) != null) {
      testingPort=Integer.parseInt(params.getParamValue(TESTING_PORT));
    }
  }
 catch (  NumberFormatException e) {
    err.println("String_Node_Str" + TESTING_PORT + "String_Node_Str"+ params.getParamValue(TESTING_PORT));
    System.exit(-1);
  }
  String runTag=params.getParamValue(RUNTAG_OPTION);
  if (runTag == null) {
    runTag=DEFAULT_RUNTAG;
  }
  double stepSize=0.1;
  try {
    if (params.getParamValue(JACCARD_STEP_SIZE) != null) {
      stepSize=Double.parseDouble(params.getParamValue(JACCARD_STEP_SIZE));
    }
  }
 catch (  NumberFormatException e) {
    err.println("String_Node_Str" + JACCARD_STEP_SIZE + "String_Node_Str"+ params.getParamValue(JACCARD_STEP_SIZE));
    System.exit(-1);
  }
  String evalType="String_Node_Str";
  try {
    if (params.getParamValue(EVALUATION_OPTION) != null) {
      evalType=params.getParamValue(EVALUATION_OPTION);
    }
  }
 catch (  Exception e) {
    err.println("String_Node_Str" + EVALUATION_OPTION + "String_Node_Str"+ params.getParamValue(EVALUATION_OPTION));
    System.exit(-1);
  }
  DecimalFormat df=new DecimalFormat("String_Node_Str");
  String trainingFile=params.getParamValue(TRAINING_CLUSTERS);
  if (trainingFile == null) {
    err.println("String_Node_Str" + TRAINING_CLUSTERS + "String_Node_Str");
    System.exit(-1);
  }
  Map<String,Clusters> clusterMembership=new HashMap<String,Clusters>();
  JSONParser parser=new JSONParser();
  try {
    JSONObject parseObj=(JSONObject)parser.parse(new FileReader(trainingFile));
    JSONObject topicObj=(JSONObject)parseObj.get("String_Node_Str");
    Set<String> topics=topicObj.keySet();
    Iterator<String> topicIt=topics.iterator();
    while (topicIt.hasNext()) {
      String topic=topicIt.next();
      clusterMembership.put(topic,new Clusters());
      JSONArray clusters=(JSONArray)((JSONObject)topicObj.get(topic)).get("String_Node_Str");
      Iterator<JSONArray> clusterIt=clusters.iterator();
      while (clusterIt.hasNext()) {
        JSONArray cluster=(JSONArray)clusterIt.next();
        Cluster c=new Cluster();
        Iterator<String> clusterMemberIt=cluster.iterator();
        while (clusterMemberIt.hasNext()) {
          String member=clusterMemberIt.next();
          long memberId=Long.parseLong(member);
          c.add(memberId);
        }
        clusterMembership.get(topic).add(c);
      }
    }
  }
 catch (  Exception e) {
    err.println("String_Node_Str");
    e.printStackTrace();
    System.exit(-1);
  }
  TrecSearchThriftClient client=new TrecSearchThriftClient(params.getParamValue(HOST_OPTION),trainingPort,group,token);
  SimpleSearcher searcher=new SimpleSearcher(client,numResults);
  err.println("String_Node_Str");
  List<Double> thresholds=new ArrayList<Double>();
  double averageThreshold=0;
  Iterator<GQuery> queryIterator=trainingQueries.iterator();
  while (queryIterator.hasNext()) {
    GQuery query=queryIterator.next();
    Map<Long,TResult> seenResults=searcher.search(query);
    SimpleJaccardClusterer clusterer=new SimpleJaccardClusterer(new ArrayList<TResult>(seenResults.values()));
    double maxF1=0;
    double maxF1Threshold=1;
    for (double j=1.0; j >= 0.0; j-=stepSize) {
      Clusters clusters=clusterer.cluster(j);
      Set<Long> allResults=new HashSet<Long>(seenResults.keySet());
      allResults.removeAll(clusters.getAllClusteredResults());
      for (      Cluster c : clusters) {
        allResults.add(c.getFirstMember());
      }
      Clusters seenClusters=new Clusters();
      Clusters trueClusters=clusterMembership.get(query.getTitle());
      Iterator<Long> resultIt=allResults.iterator();
      while (resultIt.hasNext()) {
        long result=resultIt.next();
        Cluster trueCluster=trueClusters.findCluster(result);
        if (trueCluster != null) {
          seenClusters.add(trueCluster);
        }
      }
      int numRetrievedClusters=seenClusters.size();
      int numResultsReturned=allResults.size();
      int numTrueClusters=trueClusters.size();
      double precision=0;
      double recall=0;
      double f1=0;
      if (evalType.equals("String_Node_Str")) {
        precision=numRetrievedClusters / (double)numResultsReturned;
        recall=numRetrievedClusters / (double)numTrueClusters;
        f1=2 * precision * recall / (precision + recall);
      }
 else {
        int retrievedWeight=0;
        for (        Cluster cluster : seenClusters) {
          int w=cluster.getWeight(query,qrels);
          retrievedWeight+=w;
        }
        int resultsWeight=0;
        for (        long result : allResults) {
          int w=0;
          if (seenClusters.findCluster(result) == null)           resultsWeight+=w;
        }
        int trueWeight=0;
        for (        Cluster cluster : trueClusters) {
          int w=cluster.getWeight(query,qrels);
          trueWeight+=w;
        }
        precision=retrievedWeight / (double)resultsWeight;
        recall=retrievedWeight / (double)trueWeight;
        f1=2 * precision * recall / (precision + recall);
      }
      if (f1 > maxF1) {
        maxF1=f1;
        maxF1Threshold=j;
      }
    }
    thresholds.add(maxF1);
    err.println("String_Node_Str" + df.format(maxF1) + "String_Node_Str"+ df.format(maxF1Threshold));
  }
  for (  double threshold : thresholds) {
    averageThreshold+=threshold;
  }
  averageThreshold/=thresholds.size();
  err.println("String_Node_Str" + averageThreshold);
  err.println("String_Node_Str");
  queryIterator=queries.iterator();
  while (queryIterator.hasNext()) {
    GQuery query=queryIterator.next();
    err.println(query.getTitle());
    client=new TrecSearchThriftClient(params.getParamValue(HOST_OPTION),testingPort,group,token);
    searcher=new SimpleSearcher(client,numResults);
    Map<Long,TResult> seenResults=searcher.search(query);
    SimpleJaccardClusterer clusterer=new SimpleJaccardClusterer(new ArrayList<TResult>(seenResults.values()));
    Clusters clusters=clusterer.cluster(averageThreshold);
    Set<Long> allResults=new HashSet<Long>(seenResults.keySet());
    allResults.removeAll(clusters.getAllClusteredResults());
    for (    Cluster c : clusters) {
      allResults.add(c.getFirstMember());
    }
    int i=0;
    for (    long result : allResults) {
      TResult hit=seenResults.get(result);
      out.println(String.format("String_Node_Str",query.getTitle(),hit.getId(),i,hit.getRsv(),runTag));
      i++;
    }
  }
  out.close();
  err.close();
}

Fixed version (ground truth):
public static void main(String[] args) throws NumberFormatException, TException, UnsupportedEncodingException {
  ParameterBroker params=new ParameterBroker("String_Node_Str");
  PrintStream out=new PrintStream(System.out,true,"String_Node_Str");
  PrintStream err=new PrintStream(System.err,true,"String_Node_Str");
  GQueries trainingQueries=new GQueriesJsonImpl();
  trainingQueries.setMetadataField("String_Node_Str");
  trainingQueries.read(params.getParamValue(TRAINING_QUERIES));
  GQueries queries=new GQueriesJsonImpl();
  queries.setMetadataField("String_Node_Str");
  queries.read(params.getParamValue(QUERIES_OPTION));
  Qrels qrels=new Qrels(params.getParamValue(QRELS_OPTION),false,1);
  int numResults=1000;
  try {
    if (params.getParamValue(NUM_RESULTS_OPTION) != null) {
      numResults=Integer.parseInt(params.getParamValue(NUM_RESULTS_OPTION));
    }
  }
 catch (  NumberFormatException e) {
    err.println("String_Node_Str" + NUM_RESULTS_OPTION + "String_Node_Str"+ params.getParamValue(NUM_RESULTS_OPTION));
    System.exit(-1);
  }
  String group=params.getParamValue(GROUP_OPTION);
  if (group == null) {
    err.println("String_Node_Str" + GROUP_OPTION + "String_Node_Str");
    System.exit(-1);
  }
  String token=params.getParamValue(TOKEN_OPTION);
  if (group == null) {
    err.println("String_Node_Str" + TOKEN_OPTION + "String_Node_Str");
    System.exit(-1);
  }
  int trainingPort=9090;
  try {
    if (params.getParamValue(TRAINING_PORT) != null) {
      trainingPort=Integer.parseInt(params.getParamValue(TRAINING_PORT));
    }
  }
 catch (  NumberFormatException e) {
    err.println("String_Node_Str" + TRAINING_PORT + "String_Node_Str"+ params.getParamValue(TRAINING_PORT));
    System.exit(-1);
  }
  int testingPort=9091;
  try {
    if (params.getParamValue(TESTING_PORT) != null) {
      testingPort=Integer.parseInt(params.getParamValue(TESTING_PORT));
    }
  }
 catch (  NumberFormatException e) {
    err.println("String_Node_Str" + TESTING_PORT + "String_Node_Str"+ params.getParamValue(TESTING_PORT));
    System.exit(-1);
  }
  String runTag=params.getParamValue(RUNTAG_OPTION);
  if (runTag == null) {
    runTag=DEFAULT_RUNTAG;
  }
  double stepSize=0.1;
  try {
    if (params.getParamValue(JACCARD_STEP_SIZE) != null) {
      stepSize=Double.parseDouble(params.getParamValue(JACCARD_STEP_SIZE));
    }
  }
 catch (  NumberFormatException e) {
    err.println("String_Node_Str" + JACCARD_STEP_SIZE + "String_Node_Str"+ params.getParamValue(JACCARD_STEP_SIZE));
    System.exit(-1);
  }
  String evalType="String_Node_Str";
  try {
    if (params.getParamValue(EVALUATION_OPTION) != null) {
      evalType=params.getParamValue(EVALUATION_OPTION);
    }
  }
 catch (  Exception e) {
    err.println("String_Node_Str" + EVALUATION_OPTION + "String_Node_Str"+ params.getParamValue(EVALUATION_OPTION));
    System.exit(-1);
  }
  DecimalFormat df=new DecimalFormat("String_Node_Str");
  String trainingFile=params.getParamValue(TRAINING_CLUSTERS);
  if (trainingFile == null) {
    err.println("String_Node_Str" + TRAINING_CLUSTERS + "String_Node_Str");
    System.exit(-1);
  }
  Map<String,Clusters> clusterMembership=new HashMap<String,Clusters>();
  JSONParser parser=new JSONParser();
  try {
    JSONObject parseObj=(JSONObject)parser.parse(new FileReader(trainingFile));
    JSONObject topicObj=(JSONObject)parseObj.get("String_Node_Str");
    Set<String> topics=topicObj.keySet();
    Iterator<String> topicIt=topics.iterator();
    while (topicIt.hasNext()) {
      String topic=topicIt.next();
      clusterMembership.put(topic,new Clusters());
      JSONArray clusters=(JSONArray)((JSONObject)topicObj.get(topic)).get("String_Node_Str");
      Iterator<JSONArray> clusterIt=clusters.iterator();
      while (clusterIt.hasNext()) {
        JSONArray cluster=(JSONArray)clusterIt.next();
        Cluster c=new Cluster();
        Iterator<String> clusterMemberIt=cluster.iterator();
        while (clusterMemberIt.hasNext()) {
          String member=clusterMemberIt.next();
          long memberId=Long.parseLong(member);
          c.add(memberId);
        }
        clusterMembership.get(topic).add(c);
      }
    }
  }
 catch (  Exception e) {
    err.println("String_Node_Str");
    e.printStackTrace();
    System.exit(-1);
  }
  TrecSearchThriftClient client=new TrecSearchThriftClient(params.getParamValue(HOST_OPTION),trainingPort,group,token);
  SimpleSearcher searcher=new SimpleSearcher(client,numResults);
  err.println("String_Node_Str");
  List<Double> thresholds=new ArrayList<Double>();
  double averageThreshold=0;
  Iterator<GQuery> queryIterator=trainingQueries.iterator();
  while (queryIterator.hasNext()) {
    GQuery query=queryIterator.next();
    Map<Long,TResult> seenResults=searcher.search(query);
    SimpleJaccardClusterer clusterer=new SimpleJaccardClusterer(new ArrayList<TResult>(seenResults.values()));
    double maxF1=0;
    double maxF1Threshold=1;
    for (double j=1.0; j >= 0.0; j-=stepSize) {
      Clusters clusters=clusterer.cluster(j);
      Set<Long> allResults=new HashSet<Long>(seenResults.keySet());
      allResults.removeAll(clusters.getAllClusteredResults());
      for (      Cluster c : clusters) {
        allResults.add(c.getFirstMember());
      }
      Clusters seenClusters=new Clusters();
      Clusters trueClusters=clusterMembership.get(query.getTitle());
      Iterator<Long> resultIt=allResults.iterator();
      while (resultIt.hasNext()) {
        long result=resultIt.next();
        Cluster trueCluster=trueClusters.findCluster(result);
        if (trueCluster != null) {
          seenClusters.add(trueCluster);
        }
      }
      int numRetrievedClusters=seenClusters.size();
      int numResultsReturned=allResults.size();
      int numTrueClusters=trueClusters.size();
      double precision=0;
      double recall=0;
      double f1=0;
      if (evalType.equals("String_Node_Str")) {
        precision=numRetrievedClusters / (double)numResultsReturned;
        recall=numRetrievedClusters / (double)numTrueClusters;
        f1=2 * precision * recall / (precision + recall);
      }
 else {
        int retrievedWeight=0;
        for (        Cluster cluster : seenClusters) {
          int w=cluster.getWeight(query,qrels);
          retrievedWeight+=w;
        }
        int resultsWeight=0;
        for (        long result : allResults) {
          int w=0;
          if (seenClusters.findCluster(result) == null)           resultsWeight+=w;
        }
        int trueWeight=0;
        for (        Cluster cluster : trueClusters) {
          int w=cluster.getWeight(query,qrels);
          trueWeight+=w;
        }
        precision=retrievedWeight / (double)resultsWeight;
        recall=retrievedWeight / (double)trueWeight;
        f1=2 * precision * recall / (precision + recall);
      }
      if (f1 > maxF1) {
        maxF1=f1;
        maxF1Threshold=j;
      }
    }
    thresholds.add(maxF1Threshold);
    err.println("String_Node_Str" + df.format(maxF1) + "String_Node_Str"+ df.format(maxF1Threshold));
  }
  for (  double threshold : thresholds) {
    averageThreshold+=threshold;
  }
  averageThreshold/=thresholds.size();
  err.println("String_Node_Str" + averageThreshold);
  err.println("String_Node_Str");
  queryIterator=queries.iterator();
  while (queryIterator.hasNext()) {
    GQuery query=queryIterator.next();
    err.println(query.getTitle());
    client=new TrecSearchThriftClient(params.getParamValue(HOST_OPTION),testingPort,group,token);
    searcher=new SimpleSearcher(client,numResults);
    Map<Long,TResult> seenResults=searcher.search(query);
    SimpleJaccardClusterer clusterer=new SimpleJaccardClusterer(new ArrayList<TResult>(seenResults.values()));
    Clusters clusters=clusterer.cluster(averageThreshold);
    Set<Long> allResults=new HashSet<Long>(seenResults.keySet());
    allResults.removeAll(clusters.getAllClusteredResults());
    for (    Cluster c : clusters) {
      allResults.add(c.getFirstMember());
    }
    int i=0;
    for (    long result : allResults) {
      TResult hit=seenResults.get(result);
      out.println(String.format("String_Node_Str",query.getTitle(),hit.getId(),i,hit.getRsv(),runTag));
      i++;
    }
  }
  out.close();
  err.close();
}