Skip to content

Commit 07d5b8b

Browse files
author
James Somers
committed
Use the more concise version of this pattern
1 parent 49e5461 commit 07d5b8b

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

Diff for: create_semantic_map_for_notes.rb

+3-11
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ def count(t)
3434
index[id] = words
3535

3636
words.each do |term|
37-
if reverse_index[term]
38-
reverse_index[term] << id
39-
else
40-
reverse_index[term] = [id]
41-
end
37+
(reverse_index[term] ||= []) << id
4238
end
4339
end
4440

@@ -66,12 +62,8 @@ def tf_idf(term, doc, index, reverse_index)
6662
words.uniq.collect {|w| [tf_idf(w, doc, index, reverse_index), w]}.each do |pair|
6763
word = pair[1]
6864
weight = pair[0]
69-
if semantics[word]
70-
semantics[word] << [weight, doc]
71-
else
72-
semantics[word] = [[weight, doc]]
73-
end
65+
(semantics[word] ||= []) << [weight, doc]
7466
end
7567
end
7668

77-
ObjectStash.store semantics, './semantics.stash'
69+
ObjectStash.store semantics, './semantics.stash'

0 commit comments

Comments
 (0)