botanic: github.com/pbanos/botanic/set/csv Index | Files

package csv

import "github.com/pbanos/botanic/set/csv"

Package csv provides functions to read/write a set.Set as CSV

Index

Package Files

csv.go

func ReadSet Uses

func ReadSet(reader io.Reader, features []feature.Feature, sg SetGenerator) (set.Set, error)

ReadSet takes an io.Reader for a CSV stream, a slice of features and a SetGenerator and returns set.Set built with the SetGenerator and the samples parsed from the reader or an error.

The header or first row of the CSV content is expected to consist of the names of the features in the given slice. The rest of the rows should consist of valid values for the all features and/or the '?' string to indicate an undefined value.

func ReadSetBySample Uses

func ReadSetBySample(reader io.Reader, features []feature.Feature, lambda func(int, set.Sample) (bool, error)) error

ReadSetBySample takes an io.Reader for a CSV stream, a slice of features and a lambda function on an integer and a set.Sample that returns a boolean value. It parses the samples from the reader and for each it calls the lambda function with the sample and its index as parameters. If the lambda function returns true, it will continue processing the next sample, otherwise it will stop. An error is returned if something goes wrong when reading the file or parsing a sample.

The header or first row of the CSV content is expected to consist of the names of the features in the given slice. The rest of the rows should consist of valid values for the all features and/or the '?' string to indicate an undefined value.

func ReadSetBySampleFromFilePath Uses

func ReadSetBySampleFromFilePath(filepath string, features []feature.Feature, lambda func(int, set.Sample) (bool, error)) error

ReadSetBySampleFromFilePath takes an filepath string for a CSV stream, a slice of features and a lambda function on an integer and a set.Sample that returns a boolean value. It opens the file for reading (if the filapath is "" os.Stdin is used instead), parses the samples from the reader and for each it calls the lambda function with the sample and its index as parameters. If the lambda function returns true, it will continue processing the next sample, otherwise it will stop. An error is returned if something goes wrong when reading the file or parsing a sample.

The header or first row of the CSV content is expected to consist of the names of the features in the given slice. The rest of the rows should consist of valid values for the all features and/or the '?' string to indicate an undefined value.

func ReadSetFromFilePath Uses

func ReadSetFromFilePath(filepath string, features []feature.Feature, sg SetGenerator) (set.Set, error)

ReadSetFromFilePath takes a filepath string, a slice of features and a SetGenerator, opens the file to which the filepath points to and uses ReadSet to return a set.Set or an error read from it. It will return an error if the given filepath cannot be opened for reading.

func WriteCSVSet Uses

func WriteCSVSet(ctx context.Context, writer io.Writer, s set.Set, features []feature.Feature) error

WriteCSVSet takes a writer, a set.Set and a slice of features and dumps to the writer the set in CSV format, specifying only the features in the given slice for the samples. It returns an error if something went wrong when wrting to the writer, or codifying the samples.

type SetGenerator Uses

type SetGenerator func([]set.Sample) set.Set

SetGenerator is a function that takes a slice of samples and generates a set with them.

type Writer Uses

type Writer interface {
    // Write will attempt to write the given number
    // of samples and will return the actually written
    // number of samples and an error (if not all samples
    // could be written)
    Write(context.Context, []set.Sample) (int, error)
    // Count returns the total number of samples written
    // to the writer
    Count() int
    // Flush ensures any pending written operations finish
    // before returning. It returns an error if that cannot
    // be ensured.
    Flush() error
}

Writer is an interface for a set to which samples can be written to.

func NewWriter Uses

func NewWriter(writer io.Writer, features []feature.Feature) (Writer, error)

NewWriter takes an io.Writer and a slice of feature.Features and returns a Writer that will write any samples on the io.Writer.

Package csv imports 8 packages (graph) and is imported by 1 packages. Updated 2018-01-24. Refresh now. Tools for package owners.