项目作者: bsm

项目描述 :
高级语言: Go
项目地址: git://github.com/bsm/arff.git
创建时间: 2016-06-14T08:58:15Z
项目社区:https://github.com/bsm/arff

开源协议:Other

下载


ARFF

Build Status
GoDoc
Go Report Card
License

Small utility for reading Attribute-Relation File Format (ARFF) data. For now, only a subset of
features is supported.

Supported:

  • Numeric attributes
  • String attributes
  • Nominal attributes
  • Date attributes (ISO-8601 UTC only)
  • Weighted data
  • Unicode

Not-supported:

  • Relational attributes
  • Sparse format

Example: Reader

  1. import(
  2. "bytes"
  3. "fmt"
  4. "github.com/bsm/arff"
  5. )
  6. func main() {
  7. data, err := arff.Open("./testdata/weather.arff")
  8. if err != nil {
  9. panic("failed to open file: " + err.Error())
  10. }
  11. defer data.Close()
  12. for data.Next() {
  13. fmt.Println(data.Row().Values...)
  14. }
  15. if err := data.Err(); err != nil {
  16. panic("failed to read file: " + err.Error())
  17. }
  18. }

Example: Writer

  1. import (
  2. "bytes"
  3. "fmt"
  4. "github.com/bsm/arff"
  5. )
  6. func main() {
  7. buf := new(bytes.Buffer)
  8. w, err := arff.NewWriter(buf, &arff.Relation{
  9. Name: "data relation",
  10. Attributes: []arff.Attribute{
  11. {Name: "outlook", DataType: arff.DataTypeNominal, NominalValues: []string{"sunny", "overcast", "rainy"}},
  12. {Name: "temperature", DataType: arff.DataTypeNumeric},
  13. {Name: "humidity", DataType: arff.DataTypeNumeric},
  14. {Name: "windy", DataType: arff.DataTypeNominal, NominalValues: []string{"TRUE", "FALSE"}},
  15. {Name: "play", DataType: arff.DataTypeNominal, NominalValues: []string{"yes", "no"}},
  16. },
  17. })
  18. if err != nil {
  19. panic("failed to create writer: " + err.Error())
  20. }
  21. if err := w.Append(&arff.DataRow{Values: []interface{}{"sunny", 85, 85, "FALSE", "no"}}); err != nil {
  22. panic("failed to append row: " + err.Error())
  23. }
  24. if err := w.Append(&arff.DataRow{Values: []interface{}{"overcast", 83, 86, "FALSE", "yes"}}); err != nil {
  25. panic("failed to append row: " + err.Error())
  26. }
  27. if err := w.Append(&arff.DataRow{Values: []interface{}{"rainy", 65, 70, "TRUE", "no"}}); err != nil {
  28. panic("failed to append row: " + err.Error())
  29. }
  30. if err := w.Close(); err != nil {
  31. panic("failed to close writer: " + err.Error())
  32. }
  33. fmt.Println(buf.String())
  34. }