src/main/java/org/thegalactic/context/io/ContextSerializerCsv.java
public void write(Context context, BufferedWriter file) throws IOException {
        CSVPrinter printer = new CSVPrinter(file, CSVFormat.RFC4180);

        // Get the observations and the attributes
        TreeSet<Comparable> observations = context.getObservations();
        TreeSet<Comparable> attributes = context.getAttributes();

        // Prepare the attribute line
        printer.print("");

        for (Comparable attribute : attributes) {
            // Write each attribute
            printer.print(attribute);
        }

        printer.println();

        for (Comparable observation : observations) {
            // Write the observation
            printer.print(observation);

            // Write the extent/intents
            for (Comparable attribute : attributes) {
                if (context.getIntent(observation).contains(attribute)) {
                    printer.print(1);
                } else {
                    printer.print(0);
                }
            }

            printer.println();
        }

        printer.close();
    }
/**
     * Write a context to a csv file.
     *
     * The following format is respected:
     *
     * The first line contains the attribute names, the other lines contains the
     * observations identifier followed by boolean values
     *
     * ~~~
     * "",a,b,c,d,e
     * 1,1,0,1,0,0
     * 2,1,1,0,0,0
     * 3,0,1,0,1,1
     * 4,0,0,1,0,1
     * ~~~
     *
     * @param context a context to write
     * @param file    a file
     *
     * @throws IOException When an IOException occurs
     */
Write a context to a csv file.
The following format is respected.

The first line contains the attribute names, the other lines contains the
observations identifier followed by boolean values



@param context a context to write
@param file    a file


Write a context to a csv file . The following format is respected . The first line contains the attribute names the other lines contains the observations identifier followed by boolean values @param context a context to write @param file a file
public void write(Context context, BufferedWriter file) throws IOException {
        CSVPrinter printer = new CSVPrinter(file, CSVFormat.RFC4180);
        TreeSet<Comparable> observations = context.getObservations();
        TreeSet<Comparable> attributes = context.getAttributes();
        printer.print("");
        for (Comparable attribute : attributes) {
            printer.print(attribute);
        }
        printer.println();
        for (Comparable observation : observations) {
            printer.print(observation);
            for (Comparable attribute : attributes) {
                if (context.getIntent(observation).contains(attribute)) {
                    printer.print(1);
                } else {
                    printer.print(0);
                }
            }
            printer.println();
        }
        printer.close();
    }
public void write ( Context context , BufferedWriter file ) throws IOException { CSVPrinter printer = new CSVPrinter ( file , CSVFormat . RFC4180 ) ; TreeSet < Comparable > observations = context . getObservations ( ) ; TreeSet < Comparable > attributes = context . getAttributes ( ) ; printer . print ( "" ) ; for ( Comparable attribute : attributes ) { printer . print ( attribute ) ; } printer . println ( ) ; for ( Comparable observation : observations ) { printer . print ( observation ) ; for ( Comparable attribute : attributes ) { if ( context . getIntent ( observation ) . contains ( attribute ) ) { printer . print ( 1 ) ; } else { printer . print ( 0 ) ; } } printer . println ( ) ; } printer . close ( ) ; }
Write a context to a csv file.
Write a context to a csv file .
// Get the observations and the attributes // Prepare the attribute line // Write each attribute // Write the observation // Write the extent/intents