func newClusterNode(fmtr lattice.Formatter, n lattice.Node, attr string) (*clusterNode, error) { items, err := itemset(n, attr) if err != nil { return nil, err } labels, err := labelset(n) if err != nil { return nil, err } cn := &clusterNode{n.Pattern(), fmtr.PatternName(n), items, labels} return cn, nil }
func NewDir(c *config.Config, fmtr lattice.Formatter, showPr bool, dirname string) (*Dir, error) { samples := c.OutputFile(dirname) err := os.MkdirAll(samples, 0775) if err != nil { return nil, err } var prfmtr lattice.PrFormatter if showPr { prfmtr = fmtr.PrFormatter() } r := &Dir{ config: c, fmtr: fmtr, prfmtr: prfmtr, dir: samples, } return r, nil }
func (r *PrFormatter) FormatMatrices(w io.Writer, fmtr lattice.Formatter, n lattice.Node, m interface{}) error { QRu := m.(*Matrices) bytes, err := json.Marshal(map[string]interface{}{ "Name": fmtr.PatternName(n), "Q": QRu.Q, "R": QRu.R, "u": QRu.U, "startingPoints": 1, }) if err != nil { return err } _, err = w.Write(bytes) if err != nil { return err } _, err = w.Write([]byte("\n")) if err != nil { return err } return nil }
func NewFile(c *config.Config, fmtr lattice.Formatter, showPr bool, patternsFilename, embeddingsFilename, namesFilename, matricesFilename, prsFilename string) (*File, error) { patterns, err := os.Create(c.OutputFile(patternsFilename + fmtr.FileExt())) if err != nil { return nil, err } embeddings, err := os.Create(c.OutputFile(embeddingsFilename + fmtr.FileExt())) if err != nil { return nil, err } names, err := os.Create(c.OutputFile(namesFilename)) if err != nil { return nil, err } var matrices io.WriteCloser var prs io.WriteCloser var prfmtr lattice.PrFormatter if showPr { prfmtr = fmtr.PrFormatter() if prfmtr != nil { prs, err = os.Create(c.OutputFile(prsFilename)) if err != nil { return nil, err } matrices, err = os.Create(c.OutputFile(matricesFilename)) if err != nil { return nil, err } } } r := &File{ config: c, fmtr: fmtr, prfmtr: prfmtr, patterns: patterns, embeddings: embeddings, names: names, matrices: matrices, prs: prs, } return r, nil }