-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
formalized api for string and io.Reader
- Loading branch information
1 parent
2716ce5
commit e449119
Showing
10 changed files
with
188 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version=0.2.0 | ||
version=0.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
package classifier | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
) | ||
import "io" | ||
|
||
// Classifier provides a simple interface for different text classifiers | ||
type Classifier interface { | ||
// Train allows clients to train the classifier | ||
Train(doc string, category string) error | ||
Train(io.Reader, string) error | ||
// TrainString allows clients to train the classifier using a string | ||
TrainString(string, string) error | ||
// Classify performs a classification on the input corpus and assumes that | ||
// the underlying classifier has been trained. | ||
Classify(doc string) (string, error) | ||
Classify(io.Reader) (string, error) | ||
// ClassifyString performs text classification using a string | ||
ClassifyString(string) (string, error) | ||
} | ||
|
||
// WordCounts extracts term frequencies from a text corpus | ||
func WordCounts(doc string) (map[string]int, error) { | ||
tokens := Tokenize(doc) | ||
func WordCounts(r io.Reader) (map[string]int, error) { | ||
instream := NewTokenizer().Tokenize(r) | ||
wc := make(map[string]int) | ||
for _, token := range tokens { | ||
for token := range instream { | ||
wc[token] = wc[token] + 1 | ||
} | ||
|
||
return wc, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.