Skip to content

Commit c8cd045

Browse files
committed
removed error signature from Tokenize function
1 parent 9360666 commit c8cd045

4 files changed

Lines changed: 7 additions & 21 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=0.1.0
1+
version=0.2.0

classifier.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,15 @@ type Classifier interface {
1515
}
1616

1717
// Tokenize extracts and normalizes all words from a text corpus
18-
func Tokenize(doc string) ([]string, error) {
18+
func Tokenize(doc string) []string {
1919
tokenizer := regexp.MustCompile("\\W+")
2020
tokens := tokenizer.Split(doc, -1)
21-
return Map(Filter(tokens, IsNotStopWord), strings.ToLower), nil
21+
return Map(Filter(tokens, IsNotStopWord), strings.ToLower)
2222
}
2323

2424
// WordCounts extracts term frequencies from a text corpus
2525
func WordCounts(doc string) (map[string]int, error) {
26-
tokens, err := Tokenize(doc)
27-
if err != nil {
28-
return nil, err
29-
}
30-
26+
tokens := Tokenize(doc)
3127
wc := make(map[string]int)
3228
for _, token := range tokens {
3329
wc[token] = wc[token] + 1

classifier_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ var (
88
)
99

1010
func TestTokenize(t *testing.T) {
11-
tokens, err := Tokenize(text)
12-
13-
if err != nil {
14-
t.Error("failed to tokenize text:", err)
15-
}
11+
tokens := Tokenize(text)
1612

1713
if len(tokens) != expected {
1814
t.Errorf("Expected %d tokens; actual: %d", expected, len(tokens))

naive/naive.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ func New() *Classifier {
2727

2828
// Train provides supervisory training to the classifier
2929
func (c *Classifier) Train(doc string, category string) error {
30-
features, err := classifier.Tokenize(doc)
31-
if err != nil {
32-
return err
33-
}
30+
features := classifier.Tokenize(doc)
3431

3532
c.Lock()
3633
defer c.Unlock()
@@ -139,10 +136,7 @@ func (c *Classifier) probability(doc string, category string) (float64, error) {
139136
}
140137

141138
func (c *Classifier) docProbability(doc string, category string) (float64, error) {
142-
features, err := classifier.Tokenize(doc)
143-
if err != nil {
144-
return 0.0, err
145-
}
139+
features := classifier.Tokenize(doc)
146140
probability := 1.0
147141
for _, feature := range features {
148142
probability *= c.weightedProbability(feature, category)

0 commit comments

Comments
 (0)