Package au.com.bytecode.opencsv

Examples of au.com.bytecode.opencsv.CSVWriter


     * @param ds The data set.
     */
    public static void save(final OutputStream os, final DataSet ds) {
        try {
            final Writer writer = new OutputStreamWriter(os);
            final CSVWriter csv = new CSVWriter(writer);

            csv.writeNext(ds.getHeaders());
            final String[] items2 = new String[ds.getHeaderCount()];

            for (final Object[] item : ds.getData()) {
                for (int i = 0; i < ds.getHeaderCount(); i++) {
                    items2[i] = item[i].toString();
                }
                csv.writeNext(items2);
            }
            csv.close();
        } catch (IOException ex) {
            throw new AIFHError(ex);
        }
    }
View Full Code Here


     * @param ds The data set.
     */
    public static void save(final OutputStream os, final DataSet ds) {
        try {
            final Writer writer = new OutputStreamWriter(os);
            final CSVWriter csv = new CSVWriter(writer);

            csv.writeNext(ds.getHeaders());
            final String[] items2 = new String[ds.getHeaderCount()];

            for (final Object[] item : ds.getData()) {
                for (int i = 0; i < ds.getHeaderCount(); i++) {
                    items2[i] = item[i].toString();
                }
                csv.writeNext(items2);
            }
            csv.close();
        } catch (IOException ex) {
            throw new AIFHError(ex);
        }
    }
View Full Code Here

            pw.println(Arrays.toString(bestNetwork.getLongTermMemory()));
            pw.close();


            FileOutputStream fos = new FileOutputStream(submitPath);
            CSVWriter csv = new CSVWriter(new OutputStreamWriter(fos));
            csv.writeNext(new String[]{"PassengerId", "Survived"});

            TitanicStats stats = new TitanicStats();
            NormalizeTitanic.analyze(stats, trainingPath);
            NormalizeTitanic.analyze(stats, testPath);

            List<String> ids = new ArrayList<String>();
            List<BasicData> training = NormalizeTitanic.normalize(stats, testPath, ids,
                    TitanicConfig.InputNormalizeLow,
                    TitanicConfig.InputNormalizeHigh,
                    TitanicConfig.PredictSurvive,
                    TitanicConfig.PredictPerish);

            int idx = 0;
            for (BasicData data : training) {
                double[] output = bestNetwork.computeRegression(data.getInput());
                int survived = output[0] > 0.5 ? 1 : 0;

                String[] line = {ids.get(idx), "" + survived};
                csv.writeNext(line);
                idx++;
            }

            csv.close();
            fos.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
View Full Code Here

                    TitanicConfig.PredictPerish);

            // Write out the normalized file, mainly so that you can examine it.
            // This file is not actually used by the program.
            FileOutputStream fos = new FileOutputStream(normalizePath);
            CSVWriter csv = new CSVWriter(new OutputStreamWriter(fos));

            csv.writeNext(new String[]{
                    "id",
                    "age", "sex-male", "pclass", "sibsp", "parch", "fare",
                    "embarked-c", "embarked-q", "embarked-s", "name-mil", "name-nobility", "name-dr", "name-clergy"
            });

            int idx = 0;
            for (BasicData data : training) {
                String[] line = {
                        ids.get(idx++),
                        FormatNumeric.formatDouble(data.getInput()[0], 5),
                        FormatNumeric.formatDouble(data.getInput()[1], 5),
                        FormatNumeric.formatDouble(data.getInput()[2], 5),
                        FormatNumeric.formatDouble(data.getInput()[3], 5),
                        FormatNumeric.formatDouble(data.getInput()[4], 5),
                        FormatNumeric.formatDouble(data.getInput()[5], 5),
                        FormatNumeric.formatDouble(data.getInput()[6], 5),
                        FormatNumeric.formatDouble(data.getInput()[7], 5),
                        FormatNumeric.formatDouble(data.getInput()[8], 5),
                        FormatNumeric.formatDouble(data.getInput()[9], 5),
                        FormatNumeric.formatDouble(data.getInput()[10], 5),
                        FormatNumeric.formatDouble(data.getInput()[11], 5),
                        FormatNumeric.formatDouble(data.getInput()[12], 5),
                        FormatNumeric.formatDouble(data.getIdeal()[0], 5)

                };

                csv.writeNext(line);
            }

            csv.close();
            fos.close();

        } catch (IOException ex) {
            ex.printStackTrace();
        }
View Full Code Here

    pBenchmarks.add(new Dsaupd());

    for (Benchmark b : benchmarks) {
      File file = new File(getTarget(b) + ".csv");
      log.info("writing to " + file);
      @Cleanup CSVWriter csv = new CSVWriter(new FileWriter(file));
      for (int i = 0; i < sets; i++) {
        long result = b.benchmark();
        csv.writeNext(new String[]{Long.toString(result)});
      }
    }

    double factor = 6 / 100.0;
    for (Benchmark.Parameterised b : pBenchmarks) {
      File file = new File(getTarget(b) + ".csv");
      log.info("writing to " + file);
      @Cleanup CSVWriter csv = new CSVWriter(new FileWriter(file));
      for (int i = 0; i < reps; i++) {
        log.info(file + " rep " + i);
        for (int j = sets; j > 0; j--) {
          int size = (int) Math.pow(10, factor * j);
          if (size < 10) continue;
          try {
            long result = b.benchmark(size);
            csv.writeNext(new String[]{Integer.toString(size), Long.toString(result)});
          } catch (IllegalArgumentException e) {
            log.info("skipping a datum...");
          }
        }
      }
View Full Code Here

  @Override
  public void writeTo(Metadata metadata, Class<?> type, Type genericType, Annotation[] annotations,
      MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException,
      WebApplicationException {

    CSVWriter writer = new CSVWriter(new OutputStreamWriter(entityStream, "UTF-8"));

    for (String name : metadata.names()) {
      String[] values = metadata.getValues(name);
      ArrayList<String> list = new ArrayList<String>(values.length + 1);
      list.add(name);
      list.addAll(Arrays.asList(values));
      writer.writeNext(list.toArray(values));
    }
    // don't close, just flush the stream
    writer.flush();
  }
View Full Code Here

      }
    };
  }

  public static void metadataToCsv(Metadata metadata, OutputStream outputStream) throws IOException {
    CSVWriter writer = new CSVWriter(new OutputStreamWriter(outputStream, "UTF-8"));

    for (String name : metadata.names()) {
      String[] values = metadata.getValues(name);
      ArrayList<String> list = new ArrayList<String>(values.length+1);
      list.add(name);
      list.addAll(Arrays.asList(values));
      writer.writeNext(list.toArray(values));
    }

    writer.close();
  }
View Full Code Here

    parser.parse(is, new DefaultHandler(), metadata);

    return new StreamingOutput() {
      public void write(OutputStream outputStream) throws IOException, WebApplicationException {
        CSVWriter writer = new CSVWriter(new OutputStreamWriter(outputStream));
        for (String name : metadata.names()) {
          String[] values = metadata.getValues(name);
          ArrayList<String> list = new ArrayList<String>(values.length+1);
          list.add(name);
          list.addAll(Arrays.asList(values));
          writer.writeNext(list.toArray(values));
        }
        writer.close();
      }
    };
  }
View Full Code Here

    this.fieldAccessors = fieldAccessors;
    this.iterable = iterable;
  }
 
  public void writeTo(PrintWriter printWriter) throws IOException {
    CSVWriter csvWriter = new CSVWriter(printWriter, '\t', CSVWriter.NO_QUOTE_CHARACTER);
   
    String[] headerLine = getHeaderLineFor();
   
    csvWriter.writeNext(headerLine);
   
    for (T record : iterable) {
      String[] recordLine = getRecordLineFor(record);
     
      csvWriter.writeNext(recordLine);     
    }
   
    csvWriter.close();
  }
View Full Code Here

  @SuppressWarnings("resource")
  public void writeTo(Metadata metadata, Class<?> type, Type genericType, Annotation[] annotations,
      MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException,
      WebApplicationException {

    CSVWriter writer = new CSVWriter(new OutputStreamWriter(entityStream, "UTF-8"));

    for (String name : metadata.names()) {
      String[] values = metadata.getValues(name);
      ArrayList<String> list = new ArrayList<String>(values.length + 1);
      list.add(name);
      list.addAll(Arrays.asList(values));
      writer.writeNext(list.toArray(values));
    }
   
    // Don't close, just flush the stream
    writer.flush();
  }
View Full Code Here

TOP

Related Classes of au.com.bytecode.opencsv.CSVWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.