mirror of
https://github.com/thewesker/twitter_ebooks.git
synced 2025-12-20 04:11:08 -05:00
Test that models save and load correctly
This commit is contained in:
@@ -113,7 +113,7 @@ module Ebooks
|
|||||||
@mentions = mass_tikify(mention_text)
|
@mentions = mass_tikify(mention_text)
|
||||||
|
|
||||||
log "Ranking keywords"
|
log "Ranking keywords"
|
||||||
@keywords = NLP.keywords(text)
|
@keywords = NLP.keywords(text).top(200).map(&:to_s)
|
||||||
|
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,12 +22,28 @@ describe Ebooks::Model do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not use a ridiculous amount of memory" do
|
it "consumes, saves and loads models correctly" do
|
||||||
|
model = nil
|
||||||
|
|
||||||
report = MemoryUsage.report do
|
report = MemoryUsage.report do
|
||||||
model = Ebooks::Model.consume(path("data/0xabad1dea.json"))
|
model = Ebooks::Model.consume(path("data/0xabad1dea.json"))
|
||||||
end
|
end
|
||||||
|
expect(report.total_memsize).to be < 200000000
|
||||||
|
|
||||||
expect(report.total_memsize).to be < 1000000000
|
file = Tempfile.new("0xabad1dea")
|
||||||
|
model.save(file.path)
|
||||||
|
|
||||||
|
report2 = MemoryUsage.report do
|
||||||
|
model = Ebooks::Model.load(file.path)
|
||||||
|
end
|
||||||
|
expect(report2.total_memsize).to be < 3000000
|
||||||
|
|
||||||
|
expect(model.tokens[0]).to be_a String
|
||||||
|
expect(model.sentences[0][0]).to be_a Fixnum
|
||||||
|
expect(model.mentions[0][0]).to be_a Fixnum
|
||||||
|
expect(model.keywords[0]).to be_a String
|
||||||
|
|
||||||
|
puts "0xabad1dea.model uses #{report2.total_memsize} bytes in memory"
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.consume' do
|
describe '.consume' do
|
||||||
|
|||||||
Reference in New Issue
Block a user