package sssj.io;

import sssj.Vector;

import com.google.common.base.Function;

public enum Format {
  SSSJ {
    @Override
    public Function<String, Vector> getRecordParser() {
      return new Function<String, Vector>() {
        public Vector apply(String input) {
          String[] tokens = input.split(" ");
          Long ts = Long.parseLong(tokens[0]);
          Vector result = new Vector(ts);
          for (int i = 1; i < tokens.length; i += 2) {
            int key = Integer.parseInt(tokens[i]);
            double val = Double.parseDouble(tokens[i + 1]);
            result.put(key, val);
          }
          return result;
        }
      };
    }
  },

  SVMLIB {
    @Override
    public Function<String, Vector> getRecordParser() {
      return new Function<String, Vector>() {
        public Vector apply(String input) {
          String[] tokens = input.split("\\s");
          // ignore class label tokens[0]
          Vector result = new Vector();
          for (int i = 1; i < tokens.length; i++) {
            String[] parts = tokens[i].split(":");
            int key = Integer.parseInt(parts[0]);
            double val = Double.parseDouble(parts[1]);
            result.put(key, val);
          }
          return result;
        }
      };
    }
  };

  abstract public Function<String, Vector> getRecordParser();
}
@@ -1274,16 +1274,651 @@
    %7D%0A  %7D
+,%0A%0A  VW %7B%0A    @Override%0A    public Function%3CString, Vector%3E getRecordParser() %7B%0A      return new Function%3CString, Vector%3E() %7B%0A        public Vector apply(String input) %7B%0A          String%5B%5D tokens = input.split(%22%5C%5Cs%22);%0A          // ignore class label tokens%5B0%5D and namespace tokens%5B1%5D%0A          Vector result = new Vector();%0A          for (int i = 2; i %3C tokens.length; i++) %7B%0A            String%5B%5D parts = tokens%5Bi%5D.split(%22:%22);%0A            int key = Integer.parseInt(parts%5B0%5D);%0A            double val = Double.parseDouble(parts%5B1%5D);%0A            result.put(key, val);%0A          %7D%0A          return result;%0A        %7D%0A      %7D;%0A    %7D%0A  %7D;%0A  
 ;%0A%0A  abs

Add VW format