Commit 8f90ef69c4dd38d0e5d298af9f6d7f50b8376bc2
1 parent
b506940c3f
Exists in
master
calls to the count_words method of Document are no more allowed
Showing 1 changed file with 4 additions and 5 deletions Side-by-side Diff
lib/mirimiri/document.rb
| ... | ... | @@ -80,11 +80,9 @@ |
| 80 | 80 | # entropy("dillinger escape plan") #=> 0.265862076325102 |
| 81 | 81 | def entropy(s) |
| 82 | 82 | en = 0.0 |
| 83 | - # TODO: count_words as an attribute? | |
| 84 | - counts = self.count_words | |
| 85 | 83 | |
| 86 | 84 | s.split.each do |w| |
| 87 | - p_wi = counts[w].to_f/@words.count.to_f | |
| 85 | + p_wi = @count_words[w].to_f/@words.count.to_f | |
| 88 | 86 | en += p_wi*Math.log2(p_wi) |
| 89 | 87 | end |
| 90 | 88 | |
| 91 | 89 | |
| 92 | 90 | |
| ... | ... | @@ -96,16 +94,17 @@ |
| 96 | 94 | # |
| 97 | 95 | # tf("guitar") #=> 0.000380372765310004 |
| 98 | 96 | def tf(s) |
| 99 | - self.count_words[s].to_f/@words.size.to_f | |
| 97 | + @count_words[s].to_f/@words.size.to_f | |
| 100 | 98 | end |
| 101 | 99 | |
| 102 | 100 | |
| 103 | 101 | def initialize(content="") |
| 104 | 102 | @doc_content = content |
| 105 | 103 | @words = format_words |
| 104 | + @count_words = count_words | |
| 106 | 105 | end |
| 107 | 106 | |
| 108 | - protected :format_words | |
| 107 | + protected :format_words, :count_words | |
| 109 | 108 | end |
| 110 | 109 | |
| 111 | 110 | # A WebDocument is a Document with a +url+. |