Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions bayes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
)

var (
smoother = 1 // laplace
smoother = 1 // laplace
defaultMinClassSize = 5
)

type Classifier struct {
Tokenizer *tokenizer `json:"-"`
Matrix *sparseMatrix `json:"matrix"`
MinClassSize int
Tokenizer *tokenizer `json:"-"`
Matrix *sparseMatrix `json:"matrix"`
MinClassSize int `json:"minClassSize"`
}

// Create a new multibayes classifier.
Expand All @@ -24,8 +24,8 @@ func NewClassifier() *Classifier {
sparse := newSparseMatrix()

return &Classifier{
Tokenizer: tokenize,
Matrix: sparse,
Tokenizer: tokenize,
Matrix: sparse,
MinClassSize: defaultMinClassSize,
}
}
Expand Down
6 changes: 4 additions & 2 deletions encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
)

type jsonableClassifier struct {
Matrix *sparseMatrix `json:"matrix"`
Matrix *sparseMatrix `json:"matrix"`
MinClassSize int `json:"minClassSize"`
}

func (c *Classifier) MarshalJSON() ([]byte, error) {
return json.Marshal(&jsonableClassifier{c.Matrix})
return json.Marshal(&jsonableClassifier{c.Matrix, c.MinClassSize})
}

func (c *Classifier) UnmarshalJSON(buf []byte) error {
Expand All @@ -23,6 +24,7 @@ func (c *Classifier) UnmarshalJSON(buf []byte) error {

*c = *NewClassifier()
c.Matrix = j.Matrix
c.MinClassSize = j.MinClassSize

return nil
}
Expand Down