From 927efe7f07555b1ddc83585dce00fc50cf2eb2e2 Mon Sep 17 00:00:00 2001 From: Paul Friedman Date: Sun, 19 Oct 2014 22:33:17 -0700 Subject: [PATCH] Fix parser swapping mentions and sentences --- lib/twitter_ebooks/model.rb | 4 ++-- spec/model_spec.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/twitter_ebooks/model.rb b/lib/twitter_ebooks/model.rb index 6d4af13..03f4fe5 100644 --- a/lib/twitter_ebooks/model.rb +++ b/lib/twitter_ebooks/model.rb @@ -63,9 +63,9 @@ module Ebooks next if l.include?('RT') || l.include?('MT') # Remove soft retweets if l.include?('@') - statements << NLP.normalize(l) - else mentions << NLP.normalize(l) + else + statements << NLP.normalize(l) end end diff --git a/spec/model_spec.rb b/spec/model_spec.rb index 8fdc82d..4837735 100644 --- a/spec/model_spec.rb +++ b/spec/model_spec.rb @@ -1,5 +1,6 @@ require 'spec_helper' require 'memory_profiler' +require 'tempfile' def Process.rss; `ps -o rss= -p #{Process.pid}`.chomp.to_i; end @@ -11,4 +12,30 @@ describe Ebooks::Model do expect(report.total_memsize).to be < 1000000000 end + + describe '.consume' do + it 'interprets lines with @ as mentions' do + file = Tempfile.new('mentions') + file.write('@m1spy hello!') + file.close + + model = Ebooks::Model.consume(file.path) + expect(model.sentences.count).to eq 0 + expect(model.mentions.count).to eq 1 + + file.unlink + end + + it 'interprets lines without @ as statements' do + file = Tempfile.new('statements') + file.write('hello!') + file.close + + model = Ebooks::Model.consume(file.path) + expect(model.mentions.count).to eq 0 + expect(model.sentences.count).to eq 1 + + file.unlink + end + end end