Skip to content

Commit

Permalink
Moved text/ models over to using arbitrary io.Writer for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cdipaolo committed Feb 28, 2016
1 parent 0dfbff0 commit c948131
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions text/bayes.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Example Online Naive Bayes Text Classifier (multiclass):
for {
err, more := <- errors
if err != nil {
fmt.Printf("Error passed: %v", err)
fmt.Fprintf(b.Output, "Error passed: %v", err)
} else {
// training is done!
break
Expand All @@ -74,6 +74,7 @@ package text
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"math"
"os"
Expand Down Expand Up @@ -153,6 +154,10 @@ type NaiveBayes struct {

// stream holds the datastream
stream <-chan base.TextDatapoint

// Output is the io.Writer used for logging
// and printing. Defaults to os.Stdout.
Output io.Writer
}

// Word holds the structural
Expand Down Expand Up @@ -193,6 +198,8 @@ func NewNaiveBayes(stream <-chan base.TextDatapoint, classes uint8, sanitize fun

sanitize: transform.RemoveFunc(sanitize),
stream: stream,

Output: os.Stdout,
}
}

Expand Down Expand Up @@ -295,7 +302,7 @@ func (b *NaiveBayes) OnlineLearn(errors chan<- error) {
return
}

fmt.Printf("Training:\n\tModel: Multinomial Naïve Bayes\n\tClasses: %v\n", len(b.Count))
fmt.Fprintf(b.Output, "Training:\n\tModel: Multinomial Naïve Bayes\n\tClasses: %v\n", len(b.Count))

var point base.TextDatapoint
var more bool
Expand Down Expand Up @@ -359,7 +366,7 @@ func (b *NaiveBayes) OnlineLearn(errors chan<- error) {
b.Words[term] = tmp
}
} else {
fmt.Printf("Training Completed.\n%v\n\n", b)
fmt.Fprintf(b.Output, "Training Completed.\n%v\n\n", b)
close(errors)
return
}
Expand Down

0 comments on commit c948131

Please sign in to comment.