You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sdap.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/06/05 19:03:00 UTC

[jira] [Commented] (SDAP-81) Fix bugs in SparkFormatter.java

    [ https://issues.apache.org/jira/browse/SDAP-81?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16502325#comment-16502325 ] 

ASF GitHub Bot commented on SDAP-81:
------------------------------------

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:
users@infra.apache.org


> Fix bugs in SparkFormatter.java
> -------------------------------
>
>                 Key: SDAP-81
>                 URL: https://issues.apache.org/jira/browse/SDAP-81
>             Project: Apache Science Data Analytics Platform
>          Issue Type: Bug
>          Components: mudrod
>            Reporter: Yun Li
>            Priority: Major
>             Fix For: 0.1
>
>
> Fix bugs in SparkFormatter.java @[~lewismc] 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)