versify

package
v0.0.0-...-86e9f11 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package versify implements an ion "versifier:" code that performs procedural data generation based on example input.

The Union value represents many ion values that have been superimposed in one structural position as part of training the output generation. Union.Add superimposes a new training value on the existing state, and Union.Generate draws from the existing distribution of superimposed values to generate a new value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Any

type Any struct {
	// contains filtered or unexported fields
}

Any is a generator that generates ion datums of different types based on their relative frequency of occurrence in the input corpus.

Note that a value being "missing" (returned as nil) is considered to be a distinct type in terms of drawing from the distribution of inputs.

func (*Any) Add

func (o *Any) Add(value ion.Datum) Union

func (*Any) Generate

func (o *Any) Generate(src *rand.Rand) ion.Datum

func (*Any) String

func (o *Any) String() string

type BlockGenerator

type BlockGenerator struct {
	// Input is the input stream used to
	// generate the output data
	Input Union
	// Rand is the random source
	// passed to Input.Generate
	Rand *rand.Rand
	// Align is the alignment of uncompressed chunks
	Align int
	// Comp is the compression type
	// passed to blockfmt.Compression
	Comp string
}

BlockGenerator generates blockfmt-formatted tables from a Union.

func (*BlockGenerator) Table

func (b *BlockGenerator) Table(blocks int) ([]byte, error)

Table produces a compressed table containing at least the provided number of blocks and returns the encoded table as a []byte. Table will return an error if one of the generated output objects does not fit in b.Align.

type Bool

type Bool struct {
	// contains filtered or unexported fields
}

Bool is a Generator that generates only boolean values.

func FromBool

func FromBool(value ion.Datum) *Bool

FromBool returns a Bool Generator that draws from a distribution of one value.

func (*Bool) Add

func (b *Bool) Add(value ion.Datum) Union

Add implements Union.Add

func (*Bool) Generate

func (b *Bool) Generate(src *rand.Rand) ion.Datum

Generate generates a random boolean value. The likelihood that the boolean value is true is determined by sampling from the distribution of input values passed to Add.

func (*Bool) String

func (b *Bool) String() string

type Float

type Float struct {
	// contains filtered or unexported fields
}

Float is a Generator that returns floating point values.

func FromFloat

func FromFloat(f float64) *Float

FromFloat returns a Float generator that always returns f.

func (*Float) Add

func (f *Float) Add(value ion.Datum) Union

Add implements Union.Add

func (*Float) Generate

func (f *Float) Generate(src *rand.Rand) ion.Datum

Generate generates a new floating point value drawn uniformly from the open interval from the lowest value passed to Add up to the highest.

func (*Float) String

func (f *Float) String() string

type Integer

type Integer struct {
	// contains filtered or unexported fields
}

Integer is a Generator that generates integer values.

Integer generates values that are uniformly distributed along the range of input values.

func FromInt64

func FromInt64(i int64) *Integer

FromInt64 returns an Integer that only generates i.

func FromUint64

func FromUint64(u uint64) *Integer

FromUint64 returns an Integer that only generates u.

func (*Integer) Add

func (i *Integer) Add(value ion.Datum) Union

Add implements Union.Add.

func (*Integer) Generate

func (i *Integer) Generate(src *rand.Rand) ion.Datum

Generate generates a new random integer.

The output integer is drawn from the uniform distribution along the open interval from the lowest integer passed to Add up to the highest.

func (*Integer) String

func (i *Integer) String() string

type List

type List struct {
	// contains filtered or unexported fields
}

List is a Generator that returns list values.

func FromList

func FromList(lst ion.List) *List

FromList returns a List Generator that always returns lst.

func (*List) Add

func (l *List) Add(value ion.Datum) Union

Add implements Union.Add

func (*List) Generate

func (l *List) Generate(src *rand.Rand) ion.Datum

Generate returns an ion.List that has a length drawn from the uniform distribution over the open interval of the lowest list length in the input corpus to the highest. The value at each position in the returned list is drawn from the distribution of input values at that position.

func (*List) String

func (l *List) String() string

type None

type None struct {
	// contains filtered or unexported fields
}

None is the missing value.

func (*None) Add

func (n *None) Add(value ion.Datum) Union

Add implments Union.Add

func (*None) Generate

func (n *None) Generate(src *rand.Rand) ion.Datum

Generate implements Union.Generate

Generate always returns nil

func (*None) String

func (n *None) String() string

type Null

type Null struct {
	// contains filtered or unexported fields
}

Null is the null value.

func (*Null) Add

func (n *Null) Add(value ion.Datum) Union

Add implements Union.Add

func (*Null) Generate

func (n *Null) Generate(src *rand.Rand) ion.Datum

Generate implements Union.Generate

func (*Null) String

func (n *Null) String() string

type String

type String struct {
	// contains filtered or unexported fields
}

String is a Generator String value that returns a string value drawn from a set of input strings.

func FromString

func FromString(s string) *String

FromString returns a Generator that only returns the string s.

func (*String) Add

func (s *String) Add(value ion.Datum) Union

Add implements Union.Add

func (*String) Generate

func (s *String) Generate(src *rand.Rand) ion.Datum

Generate returns a string drawn pseudorandomly from the distribution of input strings. Currently, every input string is equiprobable as an output datum.

NOTE: This should be fixed to generate strings based on the histogram of input values rather than just making each input string equiprobable!

func (*String) String

func (s *String) String() string

type Struct

type Struct struct {
	// contains filtered or unexported fields
}

Struct is Generator that represents a superposition of structures.

The Struct generator generates a set of struture fields based on the input corpus of structure fields by computing the union of all the structure fields it sees.

func FromStruct

func FromStruct(s ion.Struct) *Struct

FromStruct returns a Struct Generator that only returns s.

func (*Struct) Add

func (s *Struct) Add(value ion.Datum) Union

Add implements Union.Add

func (*Struct) Generate

func (s *Struct) Generate(src *rand.Rand) ion.Datum

Generate generates an ion.Struct by drawing from the set of observed fields in the test corpus.

The likelihood that any particular field is present is equal to the likelihood that the field was present in the input, and similarly the type of the structure field is determined by drawing from the distribution of input field types weighted by their relative likelihoods.

func (*Struct) String

func (s *Struct) String() string

type Symbol

type Symbol struct {
	// contains filtered or unexported fields
}

Symbol is a collection of ion.Symbol

func FromSymbol

func FromSymbol(datum ion.Datum) *Symbol

func (*Symbol) Add

func (s *Symbol) Add(value ion.Datum) Union

Add implements Union.Add

func (*Symbol) Generate

func (s *Symbol) Generate(src *rand.Rand) ion.Datum

func (*Symbol) String

func (s *Symbol) String() string

type Time

type Time struct {
	// contains filtered or unexported fields
}

Time is a Generator that generates timestamp datums.

func FromTime

func FromTime(t date.Time) *Time

FromTime returns a Time Generator that only returns t.

func (*Time) Add

func (t *Time) Add(value ion.Datum) Union

Add implements Union.Add

func (*Time) Generate

func (t *Time) Generate(src *rand.Rand) ion.Datum

Generate draws a new timestamp value that lives uniformly in the open time interval between the earliest and latest times passed to Add.

func (*Time) String

func (t *Time) String() string

type Union

type Union interface {
	// Add returns a new Union that
	// superimposes the value on the receiver
	Add(value ion.Datum) Union

	// Generate generates a new value based
	// on the template implied by the superposition
	// of values.
	Generate(src *rand.Rand) ion.Datum

	// String describes the union
	String() string
}

Union represents the superposition of multiple values.

func FromJSON

func FromJSON(d *json.Decoder) (Union, *ion.Symtab, error)

FromJSON computes a Union from all the objects that it is able to read from d.

func Single

func Single(value ion.Datum) Union

Single constructs a Union from a single value. The returned Union is constrained to generating a value identical (or in some cases just very similar) to the input value.

Jump to

Keyboard shortcuts

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