Skip to content

Commit

Permalink
Renamed NewTFIDF to New, exported Doc
Browse files Browse the repository at this point in the history
  • Loading branch information
chewxy committed Dec 12, 2017
1 parent 4d4d9f4 commit cd4539d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions tfidf.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type TFIDF struct {
// Inverse Document Frequency
IDF map[int]float64

// docs is the count of documents
docs int
// Docs is the count of documents
Docs int

sync.Mutex
}
Expand All @@ -27,8 +27,8 @@ type Document interface {
IDs() []int
}

// NewTFIDF creates a new TFIDF structure
func NewTFIDF() *TFIDF {
// New creates a new TFIDF structure
func New() *TFIDF {
return &TFIDF{
TF: make(map[int]float64),
IDF: make(map[int]float64),
Expand All @@ -47,12 +47,12 @@ func (tf *TFIDF) Add(doc Document) {
tf.TF[w]++
}
tf.Unlock()
tf.docs++
tf.Docs++
}

// CalculateIDF calculates the inverse document frequency
func (tf *TFIDF) CalculateIDF() {
docs := float64(tf.docs)
docs := float64(tf.Docs)
tf.Lock()
for t, f := range tf.TF {
tf.IDF[t] = math.Log(docs / f)
Expand Down
2 changes: 1 addition & 1 deletion tfidf_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func makeDocuments(a []string, c map[string]int) []Document {
func Example() {
corpus, invCorpus := makeCorpus(mobydick)
docs := makeDocuments(mobydick, corpus)
tf := NewTFIDF()
tf := New()

for _, doc := range docs {
tf.Add(doc)
Expand Down

0 comments on commit cd4539d

Please sign in to comment.