csv

package
v0.0.0-...-dbea759 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadSet

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

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

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

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

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.

Types

type SetGenerator

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

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL