Skip to content

Commit

Permalink
minor tweaks so that LSI plays well with modern gems and GSL.
Browse files Browse the repository at this point in the history
Thanks to suggestions by Matthew Berk and Matt Williams.


git-svn-id: http://classifier.rubyforge.org/svn/trunk@29 269f9a14-6e07-0410-8508-e51bd802de05
  • Loading branch information
cmcbride committed Sep 22, 2007
1 parent 8cd11c0 commit eb7965c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bin/bayes.rb
Expand Up @@ -2,7 +2,7 @@

begin
require 'rubygems'
require_gem 'classifier'
require 'classifier'
rescue
require 'classifier'
end
Expand Down
2 changes: 1 addition & 1 deletion bin/summarize.rb
Expand Up @@ -2,7 +2,7 @@

begin
require 'rubygems'
require_gem 'classifier'
require 'classifier'
rescue
require 'classifier'
end
Expand Down
20 changes: 10 additions & 10 deletions install.rb
Expand Up @@ -25,13 +25,13 @@

Dir.chdir("lib")
begin
require 'rubygems'
require 'rake'
require 'rubygems'
require 'rake'
rescue LoadError
puts
puts "Please install Gem and Rake from http://rubyforge.org/projects/rubygems and http://rubyforge.org/projects/rake"
puts
exit(-1)
puts
puts "Please install Gem and Rake from http://rubyforge.org/projects/rubygems and http://rubyforge.org/projects/rake"
puts
exit(-1)
end

files = FileList["**/*"]
Expand All @@ -42,9 +42,9 @@
}

begin
require_gem 'stemmer'
require 'stemmer'
rescue LoadError
puts
puts "Please install Stemmer from http://rubyforge.org/projects/stemmer or via 'gem install stemmer'"
puts
puts
puts "Please install Stemmer from http://rubyforge.org/projects/stemmer or via 'gem install stemmer'"
puts
end
4 changes: 2 additions & 2 deletions lib/classifier/extensions/string.rb
Expand Up @@ -3,7 +3,7 @@
# License:: LGPL

begin
require_gem 'stemmer'
require 'stemmer'
rescue LoadError
puts "Please install stemmer from http://rubyforge.org/projects/stemmer or 'gem install stemmer'"
exit(-1)
Expand All @@ -13,4 +13,4 @@

class Object
def prepare_category_name; to_s.gsub("_"," ").capitalize.intern end
end
end
4 changes: 2 additions & 2 deletions lib/classifier/extensions/vector_serialize.rb
Expand Up @@ -7,7 +7,7 @@ def _dump(v)

def self._load(arr)
arry = Marshal.load(arr)
return GSL::Vector.new(arry)
return GSL::Vector.alloc(arry)
end

end
Expand All @@ -17,4 +17,4 @@ class <<self
alias :diag :diagonal
end
end
end
end
4 changes: 2 additions & 2 deletions lib/classifier/lsi.rb
Expand Up @@ -123,11 +123,11 @@ def build_index( cutoff=0.75 )
tda = doc_list.collect { |node| node.raw_vector_with( @word_list ) }

if $GSL
tdm = GSL::Matrix.new(*tda).trans
tdm = GSL::Matrix.alloc(*tda).trans
ntdm = build_reduced_matrix(tdm, cutoff)

ntdm.size[1].times do |col|
vec = GSL::Vector.new( ntdm.column(col) ).row
vec = GSL::Vector.alloc( ntdm.column(col) ).row
doc_list[col].lsi_vector = vec
doc_list[col].lsi_norm = vec.normalize
end
Expand Down
2 changes: 1 addition & 1 deletion lib/classifier/lsi/content_node.rb
Expand Up @@ -34,7 +34,7 @@ def search_norm
# key for mapping the vector space.
def raw_vector_with( word_list )
if $GSL
vec = Vector.new(word_list.size)
vec = GSL::Vector.alloc(word_list.size)
else
vec = Array.new(word_list.size, 0)
end
Expand Down

0 comments on commit eb7965c

Please sign in to comment.