lewismc closed pull request #29: SDAP-81
URL: https://github.com/apache/incubator-sdap-mudrod/pull/29
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/core/src/main/java/org/apache/sdap/mudrod/ssearch/ranking/SparkFormatter.java 
b/core/src/main/java/org/apache/sdap/mudrod/ssearch/ranking/SparkFormatter.java
index ad61607..8c7fa7f 100644
--- 
a/core/src/main/java/org/apache/sdap/mudrod/ssearch/ranking/SparkFormatter.java
+++ 
b/core/src/main/java/org/apache/sdap/mudrod/ssearch/ranking/SparkFormatter.java
@@ -16,40 +16,32 @@ public void toSparkSVMformat(String inputCSVFileName, 
String outputTXTFileName)
     }
     try {
       file.createNewFile();
-      FileWriter fw = new FileWriter(outputTXTFileName);
-      BufferedWriter bw = new BufferedWriter(fw);
 
-      BufferedReader br = new BufferedReader(new FileReader(inputCSVFileName));
-      br.readLine();
-      String line = br.readLine();
-      while (line != null) {
-        String[] list = line.split(",");
-        String output = "";
-        Double label = Double.parseDouble(list[list.length - 1].replace("\"", 
""));
-        if (label == -1.0) {
-          output = "0 ";
-        } else if (label == 1.0) {
-          output = "1 ";
+      try (FileWriter fw = new FileWriter(outputTXTFileName); 
+          BufferedWriter bw = new BufferedWriter(fw);
+          BufferedReader br = new BufferedReader(new 
FileReader(inputCSVFileName));) {
+
+        String line = null;
+        line = br.readLine(); //header
+        while ((line = br.readLine())!= null) {
+          String[] list = line.split(",");
+          String output = "";
+          Double label = Double.parseDouble(list[list.length - 
1].replace("\"", ""));
+          if (label == -1.0) {
+            output = "0 ";
+          } else if (label == 1.0) {
+            output = "1 ";
+          }
+
+          for (int i = 0; i < list.length - 1; i++) {
+            int index = i + 1;
+            output += index + ":" + 
NDForm.format(Double.parseDouble(list[i].replace("\"", ""))) + " ";
+          }
+          bw.write(output + "\n");
         }
-
-        for (int i = 0; i < list.length - 1; i++) {
-          int index = i + 1;
-          output += index + ":" + 
NDForm.format(Double.parseDouble(list[i].replace("\"", ""))) + " ";
-        }
-        bw.write(output + "\n");
-
-        line = br.readLine();
       }
-      br.close();
-      bw.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
-
-  public static void main(String[] args) {
-    SparkFormatter sf = new SparkFormatter();
-    
sf.toSparkSVMformat("C:/mudrodCoreTestData/rankingResults/inputDataForSVM.csv", 
"C:/mudrodCoreTestData/rankingResults/inputDataForSVM_spark.txt");
-  }
-
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to