lewismc commented on a change in pull request #31: SDAP-118 create a new 
ranking module
URL: 
https://github.com/apache/incubator-sdap-mudrod/pull/31#discussion_r199279501
 
 

 ##########
 File path: 
ranking/src/main/java/org/apache/sdap/mudrod/ranking/ranksvm/SparkFormatter.java
 ##########
 @@ -0,0 +1,55 @@
+package org.apache.sdap.mudrod.ranking.ranksvm;
+
+import java.io.*;
+import java.text.DecimalFormat;
+
+public class SparkFormatter {
+  DecimalFormat NDForm = new DecimalFormat("#.###");
+
+  public SparkFormatter() {
+  }
+
+  public void toSparkSVMformat(String inputCSVFileName, String 
outputTXTFileName) {
+    File file = new File(outputTXTFileName);
+    if (file.exists()) {
+      file.delete();
+    }
+    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 ";
+        }
+
+        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");
 
 Review comment:
   This cannot be hardcoded. 

----------------------------------------------------------------
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