55begin
66 raise LoadError if ENV [ 'NATIVE_VECTOR' ] == 'true' # to test the native vector class, try `rake test NATIVE_VECTOR=true`
77
8- require 'gsl' # requires http ://rb-gsl.rubyforge.org/
8+ require 'gsl' # requires https ://github.com/blackwinter/ rb-gsl
99 require_relative 'extensions/vector_serialize'
1010 $GSL = true
1111
@@ -78,7 +78,7 @@ def add_item(item, *categories, &block)
7878 # will be duck typed via to_s .
7979 #
8080 def <<( item )
81- add_item item
81+ add_item ( item )
8282 end
8383
8484 # Returns the categories for a given indexed items. You are free to add and remove
@@ -280,17 +280,16 @@ def scored_categories(doc, cutoff = 0.30, &block)
280280 # it's supposed to.
281281 def highest_ranked_stems ( doc , count = 3 )
282282 raise 'Requested stem ranking on non-indexed content!' unless @items [ doc ]
283- arr = node_for_content ( doc ) . lsi_vector . to_a
284- top_n = arr . sort . reverse [ 0 ..count - 1 ]
285- top_n . collect { |x | @word_list . word_for_index ( arr . index ( x ) ) }
283+ content_vecotr_array = node_for_content ( doc ) . lsi_vector . to_a
284+ top_n = content_vecotr_array . sort . reverse [ 0 ..count - 1 ]
285+ top_n . collect { |x | @word_list . word_for_index ( content_vecotr_array . index ( x ) ) }
286286 end
287287
288288 private
289289
290290 def build_reduced_matrix ( matrix , cutoff = 0.75 )
291291 # TODO: Check that M>=N on these dimensions! Transpose helps assure this
292292 u , v , s = matrix . SV_decomp
293-
294293 # TODO: Better than 75% term, please. :\
295294 s_cutoff = s . sort . reverse [ ( s . size * cutoff ) . round - 1 ]
296295 s . size . times do |ord |
@@ -306,20 +305,20 @@ def node_for_content(item, &block)
306305 else
307306 clean_word_hash = Hasher . clean_word_hash ( ( block ? block . call ( item ) : item . to_s ) , @language )
308307
309- cn = ContentNode . new ( clean_word_hash , &block ) # make the node and extract the data
308+ content_node = ContentNode . new ( clean_word_hash , &block ) # make the node and extract the data
310309
311310 unless needs_rebuild?
312- cn . raw_vector_with ( @word_list ) # make the lsi raw and norm vectors
311+ content_node . raw_vector_with ( @word_list ) # make the lsi raw and norm vectors
313312 end
314313 end
315314
316- cn
315+ content_node
317316 end
318317
319318 def make_word_list
320319 @word_list = WordList . new
321320 @items . each_value do |node |
322- node . word_hash . each_key { |key | @word_list . add_word key }
321+ node . word_hash . each_key { |key | @word_list . add_word ( key ) }
323322 end
324323 end
325324 end
0 commit comments