<commit_before>package org.opencompare.api.java.io;

import com.opencsv.CSVWriter;
import org.opencompare.api.java.*;

import java.io.IOException;
import java.io.StringWriter;
import java.util.*;

/**
 * Created by gbecan on 3/19/15.
 */
public class CSVExporter implements PCMExporter {

    PCMMetadata currentMetadata = null;

    @Override
    public String export(PCMContainer container) {
        currentMetadata = container.getMetadata();
        return export(container.getPcm());
    }

    private String export(PCM pcm) {
        StringWriter stringWriter = new StringWriter();
        CSVWriter csvWriter = new CSVWriter(stringWriter);

        // Export features
        if (currentMetadata  == null) currentMetadata = new PCMMetadata(pcm);

        List<Feature> features = currentMetadata.getSortedFeatures();
        List<Product> products = currentMetadata.getSortedProducts();
        List<String> featureLine = new ArrayList<>();

        featureLine.add("Product");

        for (Feature feature : features) {
            featureLine.add(feature.getName());
        }

        csvWriter.writeNext(featureLine.toArray(new String[featureLine.size()]));

        // Export products
        for (Product product : products) {
            List<String> productLine = new ArrayList<>();

            productLine.add(product.getName());
            for (Feature feature : features) {
                Cell cell = product.findCell(feature);
                if (cell == null) {
                    productLine.add("");
                } else {
                    productLine.add(cell.getContent());
                }
<commit_msg>Add separator and quote option in CSVExporter<commit_after>package org.opencompare.api.java.io;

import com.opencsv.CSVWriter;
import org.opencompare.api.java.*;

import java.io.IOException;
import java.io.StringWriter;
import java.util.*;

/**
 * Created by gbecan on 3/19/15.
 */
public class CSVExporter implements PCMExporter {

    PCMMetadata currentMetadata = null;
    char separator = ',';
    char quote = '"';

    public CSVExporter setSeparator(char separator) {
        this.separator = separator;
        return this;
    }

    public CSVExporter setQuote(char quote) {
        this.quote = quote;
        return this;
    }

    @Override
    public String export(PCMContainer container) {
        currentMetadata = container.getMetadata();
        return export(container.getPcm());
    }

    private String export(PCM pcm) {
        StringWriter stringWriter = new StringWriter();
        CSVWriter csvWriter = new CSVWriter(stringWriter, separator, quote);

        // Export features
        if (currentMetadata  == null) currentMetadata = new PCMMetadata(pcm);

        List<Feature> features = currentMetadata.getSortedFeatures();
        List<Product> products = currentMetadata.getSortedProducts();
        List<String> featureLine = new ArrayList<>();

        featureLine.add("Product");

        for (Feature feature : features) {
            featureLine.add(feature.getName());
        }

        csvWriter.writeNext(featureLine.toArray(new String[featureLine.size()]));

        // Export products
        for (Product product : products) {
            List<String> productLine = new ArrayList<>();

            productLine.add(product.getName());
            for (Feature feature : features) {
                Cell cell = product.findCell(feature);
                if (cell == null) {
                    productLine.add("");
                } else {
                    productLine.add(cell.getContent());
                }

{'fraction_non_alphanumeric': 0.10734149054505006, 'fraction_numerical': 0.0027808676307007787, 'mean_word_length': 2.415954415954416, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '683307', 'n_tokens_mistral': 963, 'n_tokens_neox': 906, 'n_words': 220}