Skip to content

Commit

Permalink
bugfix: after adding @stemmer on Classifier/LSI the objects couldnt b…
Browse files Browse the repository at this point in the history
…e marshalled.
  • Loading branch information
luisparravicini committed Dec 26, 2009
1 parent aaa634f commit 55d89fa
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/classifier/bayes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ def add_category(category)
end

alias append_category add_category

def marshal_dump
[@categories, @total_words, @options ]
end

def marshal_load(data)
@categories, @total_words, @options = data
end

end

end
11 changes: 11 additions & 0 deletions lib/classifier/lsi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ def highest_ranked_stems( doc, count=3 )
return top_n.collect { |x| @word_list.word_for_index(arr.index(x))}
end

def marshal_dump
[ @auto_rebuild, @word_list, @items, @version, @built_at_version,
@options,
]
end

def marshal_load(data)
@auto_rebuild, @word_list, @items, @version, @built_at_version,
@options = data
end

private
def build_reduced_matrix( matrix, cutoff=0.75 )
# TODO: Check that M>=N on these dimensions! Transpose helps assure this
Expand Down
2 changes: 1 addition & 1 deletion luisparravicini-classifier.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Gem::Specification.new do |s|
s.name = %q{luisparravicini-classifier}
s.version = "1.3.7"
s.version = "1.3.8"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Yury Korolev"]
Expand Down
10 changes: 10 additions & 0 deletions test/bayes/bayesian_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,14 @@ def test_case_insensitive
assert_equal c.classifications("ХОРОШО"), c.classifications("хорошо")
assert_equal c.classifications("плОХО"), c.classifications("плохо")
end

def test_serialize
txt = "this can be serialized"
b = Classifier::Bayes.new(:categories => ['Interesting', 'Uninteresting'])
b.train_interesting(txt)
b.train_uninteresting("really uninteresting")

b2 = Marshal::load(Marshal::dump(b))
assert_equal b.classify(txt), b2.classify(txt)
end
end

0 comments on commit 55d89fa

Please sign in to comment.