Permalink
Browse files

+ index specific memoization

  • Loading branch information...
1 parent 905d0ea commit 12e4526cc1ef6908f55ac29cd056423e1fb01b8e @floere committed Nov 17, 2012
Showing with 9 additions and 10 deletions.
  1. +9 −10 server/lib/picky/splitters/automatic.rb
View
19 server/lib/picky/splitters/automatic.rb
@@ -33,19 +33,18 @@ def initialize category, options = {}
reset_memoization
end
- # Split the given text into its most
- # likely constituents.
+ # Reset the memoization.
#
- def split text
- result = segment text, @with_partial
- reset_memoization
- result.first
+ def reset_memoization
+ @exact_memo = {}
+ @partial_memo = {}
end
- # Reset the memoization.
+ # Split the given text into its most
+ # likely constituents.
#
- def reset_memoization
- @memo = {}
+ def split text
+ segment(text, @with_partial).first
end
# Return all splits of a given string.
@@ -60,7 +59,7 @@ def splits text
#
#
def segment text, use_partial = false
- @memo[text] ||= splits(text).inject([[], nil]) do |(current, heaviest), (head, tail)|
+ (use_partial ? @partial_memo : @exact_memo)[text] ||= splits(text).inject([[], nil]) do |(current, heaviest), (head, tail)|
tail_weight = use_partial ? @partial.weight(tail) : @exact.weight(tail)
segments, head_weight = segment head

0 comments on commit 12e4526

Please sign in to comment.