Class: Fragmentizer

Inherits:
Object
  • Object
show all
Defined in:
lib/seasy/fragmentizer.rb

Instance Method Summary collapse

Instance Method Details

#fragmentize(str, weights = Hash.new( 0 )) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/seasy/fragmentizer.rb', line 2

def fragmentize str, weights = Hash.new( 0 )
  str = str.downcase
  split = str.split

  if split.size > 1
    split.each do |one|
      fragmentize one, weights
    end
    weights
  else
    length = str.length

    # loop over all possible intervals
    (1..length).each do |interval|
      fragmentize_in_interval str, interval, weights
      #interval += 1
    end
    weights
  end
end

#fragmentize_in_interval(str, interval, weights) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/seasy/fragmentizer.rb', line 23

def fragmentize_in_interval str, interval, weights
  length = str.length
  (0..length-interval).each do |i|
    current = str[i, interval ]
    weights[current] += 1
  end
end