ingest

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ingest reads tabular and record data — CSV, TSV, JSON and JSON Lines — into the feature values it assigns to model elements, one row per element.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Literal

func Literal(c Cell, class Class, enum string) (string, error)

Literal writes a cell as the notation of the value it assigns a feature of class; enum qualifies the literal an enumeration cell names.

func SplitHeader

func SplitHeader(header string) (name, unit string)

SplitHeader takes a unit written in brackets off a column name: `mass [kg]` names column mass in kilograms.

Types

type Cell

type Cell struct {
	Feature string
	Text    string
	Kind    Kind
	// Type is the mapping's declared type for the value, "" to follow the feature's.
	Type string
	Unit string
	// Where locates the value in the input, for a diagnostic.
	Where string
}

Cell is one value a row assigns to a feature of its element.

type Class

type Class int

Class is the kind of value a feature's declared type admits.

const (
	// ClassUnknown follows what the cell is: a boolean, a number, else a string.
	ClassUnknown Class = iota
	ClassString
	ClassBoolean
	ClassInteger
	ClassReal
	// ClassEnum is an enumeration whose literals a cell names.
	ClassEnum
)

type Field

type Field struct {
	Column string `json:"column,omitempty"`
	Path   string `json:"path,omitempty"`
	// Prefix is written before an element name the record gives.
	Prefix     string `json:"prefix,omitempty"`
	Unit       string `json:"unit,omitempty"`
	UnitColumn string `json:"unitColumn,omitempty"`
	UnitPath   string `json:"unitPath,omitempty"`
	// Type is string, boolean, integer, real or number; "" follows the feature.
	Type string `json:"type,omitempty"`
}

Field locates one value in a record: a column, or a JSON Pointer path.

type Format

type Format string

Format is a representation the data is read from.

const (
	FormatCSV   Format = "csv"
	FormatTSV   Format = "tsv"
	FormatJSON  Format = "json"
	FormatJSONL Format = "jsonl"
)

func FormatOfPath

func FormatOfPath(path string) (Format, bool)

FormatOfPath is the format a data file's extension names.

func ParseFormat

func ParseFormat(name string) (Format, error)

ParseFormat reads a format name; ndjson is JSON Lines.

type Kind

type Kind int

Kind is what a cell's source says of its value.

const (
	// KindText is a delimited cell, whose type the feature it sets decides.
	KindText Kind = iota
	KindNumber
	KindBoolean
	KindString
)

type Map

type Map struct {
	// As is what the data is imported as; "values" sets feature values.
	As string `json:"as,omitempty"`
	// Format overrides the format the data file's extension names.
	Format string `json:"format,omitempty"`
	// Delimiter is the one character a delimited file's cells are split on.
	Delimiter string `json:"delimiter,omitempty"`
	// Records is a JSON Pointer to the array of records in a JSON document.
	Records  string           `json:"records,omitempty"`
	Element  Field            `json:"element,omitempty"`
	Features map[string]Field `json:"features,omitempty"`
	// Ignore names columns or top-level fields that set nothing.
	Ignore []string `json:"ignore,omitempty"`
}

Map says how input columns and JSON fields map onto elements and features. Every field is optional: a column or field names the feature it sets, a bracketed suffix its unit, and the element column names the element.

func ParseMap

func ParseMap(data []byte) (*Map, error)

ParseMap reads a mapping file, refusing a key it does not define.

type Row

type Row struct {
	Element string
	Cells   []Cell
	Where   string
}

Row is one record: the element it describes and the values it assigns.

func Read

func Read(name string, data []byte, format Format, m *Map) ([]Row, error)

Read reads the rows of data, named name in diagnostics, as format under the mapping m, which may be nil. An empty cell or a JSON null assigns nothing.

Jump to

Keyboard shortcuts

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