Program: 9906
Project: 9906
Buggy source:
/** 
 * The main matching method. The matching is directed from DBpedia to LGD, i.e. given a POI in DBpedia, we try to find a match in LGD.
 * @param dbpediaPoint The DBpedia point.
 * @return The URI of the matched LGD point or null if no match was found.
 * @throws IOException Thrown if a query or linked data access does not work.
 */
public static URI findGeoDataMatch(DBpediaPoint dbpediaPoint) throws IOException {
  double distanceThresholdMeters=dbpediaPoint.getPoiClass().getMaxBox();
  boolean quiet=true;
  if (useSparqlForGettingNearbyPoints) {
    double minLat=dbpediaPoint.getGeoLat() - (distanceThresholdMeters / 1000 / 111);
    double maxLat=dbpediaPoint.getGeoLat() + (distanceThresholdMeters / 1000 / 111);
    double minLong=dbpediaPoint.getGeoLong() - (distanceThresholdMeters / 1000) / Math.abs(Math.cos(Math.toRadians(dbpediaPoint.getGeoLat())) * 111);
    double maxLong=dbpediaPoint.getGeoLong() + (distanceThresholdMeters / 1000) / Math.abs(Math.cos(Math.toRadians(dbpediaPoint.getGeoLat())) * 111);
    String queryStr="String_Node_Str";
    queryStr+=LGDPoint.getSPARQLRestriction(dbpediaPoint.getPoiClass(),"String_Node_Str");
    queryStr+="String_Node_Str";
    queryStr+="String_Node_Str" + usedDatatype + "String_Node_Str"+ minLat+ "String_Node_Str";
    queryStr+="String_Node_Str" + usedDatatype + "String_Node_Str"+ maxLat+ "String_Node_Str";
    queryStr+="String_Node_Str";
    queryStr+="String_Node_Str" + usedDatatype + "String_Node_Str"+ minLong+ "String_Node_Str";
    queryStr+="String_Node_Str" + usedDatatype + "String_Node_Str"+ maxLong+ "String_Node_Str";
    queryStr+="String_Node_Str";
    queryStr+="String_Node_Str";
    queryStr+="String_Node_Str";
    queryStr+="String_Node_Str";
    queryStr+="String_Node_Str";
    ResultSet rs=lgd.queryAsResultSet(queryStr);
    double highestScore=0;
    String bestURI=null;
    String bestLabel=null;
    while (rs.hasNext()) {
      QuerySolution qs=rs.nextSolution();
      String lgdURI=qs.getResource("String_Node_Str").toString();
      double stringSimilarity;
      String dbpediaLabel1=dbpediaPoint.getLabel();
      String dbpediaLabel2=dbpediaPoint.getPlainLabel();
      String lgdLabel1=qs.getLiteral("String_Node_Str").toString();
      stringSimilarity=distance.score(dbpediaLabel1,lgdLabel1);
      stringSimilarity=Math.max(distance.score(dbpediaLabel2,lgdLabel1),stringSimilarity);
      if (qs.contains("String_Node_Str")) {
        String lgdLabel2=qs.getLiteral("String_Node_Str").toString();
        stringSimilarity=distance.score(dbpediaLabel1,lgdLabel2);
        stringSimilarity=Math.max(distance.score(dbpediaLabel2,lgdLabel2),stringSimilarity);
        System.out.println(qs.getResource("String_Node_Str").getURI());
        System.exit(0);
      }
      if (qs.contains("String_Node_Str")) {
        String lgdLabel3=qs.getLiteral("String_Node_Str").toString();
        stringSimilarity=distance.score(dbpediaLabel1,lgdLabel3);
        stringSimilarity=Math.max(distance.score(dbpediaLabel2,lgdLabel3),stringSimilarity);
      }
      double lat=qs.getLiteral("String_Node_Str").getDouble();
      double lon=qs.getLiteral("String_Node_Str").getDouble();
      double distance=spatialDistance(dbpediaPoint.getGeoLat(),dbpediaPoint.getGeoLong(),lat,lon);
      double frac=Math.min(1,distance / dbpediaPoint.getPoiClass().getMaxBox());
      double distanceScore=Math.pow(frac - 1,2);
      double score=0.8 * stringSimilarity + 0.2 * distanceScore;
      if (score > highestScore) {
        highestScore=score;
        bestURI=lgdURI;
        bestLabel=lgdLabel1;
      }
    }
    if (highestScore > scoreThreshold) {
      logger.info("String_Node_Str" + highestScore + "String_Node_Str"+ bestLabel+ "String_Node_Str"+ dbpediaPoint.getUri()+ "String_Node_Str"+ bestURI+ "String_Node_Str");
      return URI.create(bestURI);
    }
 else {
      logger.info("String_Node_Str" + highestScore + "String_Node_Str"+ bestLabel+ "String_Node_Str"+ dbpediaPoint.getUri()+ "String_Node_Str"+ bestURI+ "String_Node_Str");
      return null;
    }
  }
 else {
    if (!quiet)     System.out.println(dbpediaPoint.getLabel());
    URL linkedGeoDataURL=new URL("String_Node_Str" + dbpediaPoint.getGeoLat() + "String_Node_Str"+ dbpediaPoint.getGeoLong()+ "String_Node_Str"+ distanceThresholdMeters);
    double highestScore=0;
    String bestURI=null;
    String bestLabel=null;
    URLConnection conn=linkedGeoDataURL.openConnection();
    BufferedReader rd=new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String line="String_Node_Str";
    while ((line=rd.readLine()) != null) {
      if (line.contains("String_Node_Str") || line.contains("String_Node_Str") || line.contains("String_Node_Str")) {
        int first=line.indexOf("String_Node_Str") + 1;
        int last=line.lastIndexOf("String_Node_Str");
        String label=line.substring(first,last);
        double score=distance.score(label,dbpediaPoint.getLabel());
        if (score > highestScore) {
          highestScore=score;
          bestURI=line.substring(1,line.indexOf("String_Node_Str") - 1);
          bestLabel=label;
        }
      }
    }
    rd.close();
    if (!quiet) {
      System.out.println("String_Node_Str" + linkedGeoDataURL);
      System.out.println("String_Node_Str" + highestScore);
      System.out.println("String_Node_Str" + bestURI);
      System.out.println("String_Node_Str" + bestLabel);
    }
    if (highestScore > scoreThreshold) {
      return URI.create(bestURI);
    }
 else {
      return null;
    }
  }
}

Fixed version (ground truth):
/** 
 * The main matching method. The matching is directed from DBpedia to LGD, i.e. given a POI in DBpedia, we try to find a match in LGD.
 * @param dbpediaPoint The DBpedia point.
 * @return The URI of the matched LGD point or null if no match was found.
 * @throws IOException Thrown if a query or linked data access does not work.
 */
public static URI findGeoDataMatch(DBpediaPoint dbpediaPoint) throws IOException {
  double distanceThresholdMeters=dbpediaPoint.getPoiClass().getMaxBox();
  boolean quiet=true;
  if (useSparqlForGettingNearbyPoints) {
    double minLat=dbpediaPoint.getGeoLat() - (distanceThresholdMeters / 1000 / 111);
    double maxLat=dbpediaPoint.getGeoLat() + (distanceThresholdMeters / 1000 / 111);
    double minLong=dbpediaPoint.getGeoLong() - (distanceThresholdMeters / 1000) / Math.abs(Math.cos(Math.toRadians(dbpediaPoint.getGeoLat())) * 111);
    double maxLong=dbpediaPoint.getGeoLong() + (distanceThresholdMeters / 1000) / Math.abs(Math.cos(Math.toRadians(dbpediaPoint.getGeoLat())) * 111);
    String queryStr="String_Node_Str";
    queryStr+=LGDPoint.getSPARQLRestriction(dbpediaPoint.getPoiClass(),"String_Node_Str");
    queryStr+="String_Node_Str";
    queryStr+="String_Node_Str" + usedDatatype + "String_Node_Str"+ minLat+ "String_Node_Str";
    queryStr+="String_Node_Str" + usedDatatype + "String_Node_Str"+ maxLat+ "String_Node_Str";
    queryStr+="String_Node_Str";
    queryStr+="String_Node_Str" + usedDatatype + "String_Node_Str"+ minLong+ "String_Node_Str";
    queryStr+="String_Node_Str" + usedDatatype + "String_Node_Str"+ maxLong+ "String_Node_Str";
    queryStr+="String_Node_Str";
    queryStr+="String_Node_Str";
    queryStr+="String_Node_Str";
    queryStr+="String_Node_Str";
    ResultSet rs=lgd.queryAsResultSet(queryStr);
    double highestScore=0;
    String bestURI=null;
    String bestLabel=null;
    while (rs.hasNext()) {
      QuerySolution qs=rs.nextSolution();
      String lgdURI=qs.getResource("String_Node_Str").toString();
      double stringSimilarity;
      String dbpediaLabel1=dbpediaPoint.getLabel();
      String dbpediaLabel2=dbpediaPoint.getPlainLabel();
      String lgdLabel1=qs.getLiteral("String_Node_Str").toString();
      stringSimilarity=distance.score(dbpediaLabel1,lgdLabel1);
      stringSimilarity=Math.max(distance.score(dbpediaLabel2,lgdLabel1),stringSimilarity);
      if (qs.contains("String_Node_Str")) {
        String lgdLabel2=qs.getLiteral("String_Node_Str").toString();
        stringSimilarity=distance.score(dbpediaLabel1,lgdLabel2);
        stringSimilarity=Math.max(distance.score(dbpediaLabel2,lgdLabel2),stringSimilarity);
        System.out.println(qs.getResource("String_Node_Str").getURI());
        System.exit(0);
      }
      if (qs.contains("String_Node_Str")) {
        String lgdLabel3=qs.getLiteral("String_Node_Str").toString();
        stringSimilarity=distance.score(dbpediaLabel1,lgdLabel3);
        stringSimilarity=Math.max(distance.score(dbpediaLabel2,lgdLabel3),stringSimilarity);
      }
      double lat=qs.getLiteral("String_Node_Str").getDouble();
      double lon=qs.getLiteral("String_Node_Str").getDouble();
      double distance=spatialDistance(dbpediaPoint.getGeoLat(),dbpediaPoint.getGeoLong(),lat,lon);
      double frac=Math.min(1,distance / dbpediaPoint.getPoiClass().getMaxBox());
      double distanceScore=Math.pow(frac - 1,2);
      double score=0.8 * stringSimilarity + 0.2 * distanceScore;
      if (lgdURI.contains("String_Node_Str")) {
        score-=0.02;
      }
      if (score > highestScore) {
        highestScore=score;
        bestURI=lgdURI;
        bestLabel=lgdLabel1;
      }
    }
    if (highestScore > scoreThreshold) {
      logger.info("String_Node_Str" + highestScore + "String_Node_Str"+ bestLabel+ "String_Node_Str"+ dbpediaPoint.getUri()+ "String_Node_Str"+ bestURI+ "String_Node_Str");
      return URI.create(bestURI);
    }
 else {
      logger.info("String_Node_Str" + highestScore + "String_Node_Str"+ bestLabel+ "String_Node_Str"+ dbpediaPoint.getUri()+ "String_Node_Str"+ bestURI+ "String_Node_Str");
      return null;
    }
  }
 else {
    if (!quiet)     System.out.println(dbpediaPoint.getLabel());
    URL linkedGeoDataURL=new URL("String_Node_Str" + dbpediaPoint.getGeoLat() + "String_Node_Str"+ dbpediaPoint.getGeoLong()+ "String_Node_Str"+ distanceThresholdMeters);
    double highestScore=0;
    String bestURI=null;
    String bestLabel=null;
    URLConnection conn=linkedGeoDataURL.openConnection();
    BufferedReader rd=new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String line="String_Node_Str";
    while ((line=rd.readLine()) != null) {
      if (line.contains("String_Node_Str") || line.contains("String_Node_Str") || line.contains("String_Node_Str")) {
        int first=line.indexOf("String_Node_Str") + 1;
        int last=line.lastIndexOf("String_Node_Str");
        String label=line.substring(first,last);
        double score=distance.score(label,dbpediaPoint.getLabel());
        if (score > highestScore) {
          highestScore=score;
          bestURI=line.substring(1,line.indexOf("String_Node_Str") - 1);
          bestLabel=label;
        }
      }
    }
    rd.close();
    if (!quiet) {
      System.out.println("String_Node_Str" + linkedGeoDataURL);
      System.out.println("String_Node_Str" + highestScore);
      System.out.println("String_Node_Str" + bestURI);
      System.out.println("String_Node_Str" + bestLabel);
    }
    if (highestScore > scoreThreshold) {
      return URI.create(bestURI);
    }
 else {
      return null;
    }
  }
}