Skip to content

Instantly share code, notes, and snippets.

@jcomello
Last active November 26, 2015 17:11
Show Gist options
  • Save jcomello/3595d8e4db753e1dabc4 to your computer and use it in GitHub Desktop.
Save jcomello/3595d8e4db753e1dabc4 to your computer and use it in GitHub Desktop.
Failure/Error: expect(other_sugestion.classify("Ruby é uma linguagem interessante")).to eq("interessante")
TypeError:
wrong argument type GSL::Vector (expected Data)
# /Users/my/path/classifier-reborn/lib/classifier-reborn/lsi/content_node.rb:31:in `trans'
# /Users/my/path/classifier-reborn/lib/classifier-reborn/lsi/content_node.rb:31:in `transposed_search_vector'
# /Users/my/path/classifier-reborn/lib/classifier-reborn/lsi.rb:186:in `block in proximity_array_for_content'
# /Users/my/path/classifier-reborn/lib/classifier-reborn/lsi.rb:184:in `collect'
# /Users/my/path/classifier-reborn/lib/classifier-reborn/lsi.rb:184:in `proximity_array_for_content'
# /Users//my/path/classifier-reborn/lib/classifier-reborn/lsi.rb:267:in `scored_categories'
# /Users/my/path/classifier-reborn/lib/classifier-reborn/lsi.rb:253:in `classify'
# ./app/models/sugestion.rb:17:in `classify'
# ./spec/models/sugestion_spec.rb:60:in `block (4 levels) in <top (required)>'
class Sugestion
def initialize
if content_directory.empty?
@classifier = SnapshotMadeleine.new(directory_name, YAML) do
ClassifierReborn::LSI.new(language: "pt")
end
else
@classifier = SnapshotMadeleine.new(directory_name, YAML)
end
end
def train(category, text)
@classifier.system.add_item text, category
end
def classify(text)
@classifier.system.classify text
end
def classifications(text)
@classifier.system.scored_categories(text).map(&:first)
end
def take_snapshot
@classifier.take_snapshot
end
def word_list
@classifier.system.word_list
end
private
def directory_name
"#{Rails.env} sugestion".parameterize
end
def content_directory
Dir.glob("#{directory_name}/*")
end
end
describe Sugestion do
let(:sugestion) { Sugestion.new }
context "#classify" do
before do
sugestion.train("interessante", "Ruby é interessante")
sugestion.train("desinteressante", "Programação funcional não tá com nada e isso é modinha")
end
it "classifies a given text" do
expect(sugestion.classify("Ruby é uma linguagem interessante")).to eq("interessante")
end
context "when there is an snapshot" do
before do
sugestion.take_snapshot
end
it "classifies a given text" do
other_sugestion = Sugestion.new
expect(other_sugestion.classify("Ruby é uma linguagem interessante")).to eq("interessante")
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment