rundown 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8db399e2fd88907131320b11e76975860b2846e7
4
- data.tar.gz: 2682980cb36f89988452d5acd91230ad37af88c4
3
+ metadata.gz: 1fcd7089261e9b5744c151011025ea7a1c00991e
4
+ data.tar.gz: d80f58134c95cdb18482ff398bb315269f8c01ce
5
5
  SHA512:
6
- metadata.gz: 54f953847ceac8cccf1e3c4683c0ea5601f4e2d718f97b6a020afca5888525117dedd61b2a4055097fe9de56bf5d310c70ed71705b3cb52c54101364f18cb6f5
7
- data.tar.gz: b95cccc3284cf64b08cd06fafc9cdaa1d510afaa167556d7da2b89938869a2bb3dd1ef1b1fecaf9259984839781acde90be992d6c95efa53e7c45b3763d7a4de
6
+ metadata.gz: 9525faeba11849f6ce52d1ff94c5a56debdd94d9f63543a8d09ecea9125c0df60c3489cfa45f0724886eacbadd7406981d3e2eba7340604553627a867a847247
7
+ data.tar.gz: 2ee25733bf9f51825a4985abd4a38898f503d414bb705c0eaffddc0da80ef483ecc5eae7045bd7667af7239a44b9f8202ad14db7a56d3977c26806f7140a4fa3
@@ -8,6 +8,7 @@ require 'rundown/parser'
8
8
  require 'rundown/processor'
9
9
  require 'rundown/processors/dates'
10
10
  require 'rundown/processors/email'
11
+ require 'rundown/processors/frequency'
11
12
  require 'rundown/processors/hashtags'
12
13
  require 'rundown/processors/links'
13
14
  require 'rundown/processors/phone'
@@ -0,0 +1,40 @@
1
+ module Rundown
2
+ module Processors
3
+ class Frequency < Rundown::Processor
4
+ attr_accessor :length
5
+
6
+ def initialize(words, length=1)
7
+ super(words)
8
+ @length = length
9
+ end
10
+
11
+ def cleanup_words!
12
+ @words = words.map {|w| w.gsub(/[^\w]/, '').downcase }.reject {|w| w.strip == '' }
13
+ end
14
+
15
+ def process
16
+ cleanup_words!
17
+ frequencies = {}
18
+
19
+ words.length.times do
20
+ phrase = words[0..length-1]
21
+
22
+ if phrase.join('').length >= 1
23
+ frequencies[phrase] ||= 0
24
+ frequencies[phrase] += 1
25
+ end
26
+
27
+ @words = words.rotate
28
+ end
29
+
30
+ totals = {}
31
+ frequencies.each do |phrase, freq|
32
+ totals[freq] ||= []
33
+ totals[freq] << phrase
34
+ end
35
+
36
+ totals
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module Rundown
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "bundler", "~> 1.3"
26
26
  spec.add_development_dependency "rake"
27
27
  spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "pry"
28
29
  end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ module Rundown
4
+ module Processors
5
+ describe Frequency do
6
+ let(:text) do
7
+ %q(
8
+ Recursion is the process of repeating items in a self-similar way. For
9
+ instance, when the surfaces of two mirrors are exactly parallel with
10
+ each other, the nested images that occur are a form of infinite recursion.
11
+ The term has a variety of meanings specific to a variety of disciplines
12
+ ranging from linguistics to logic. The most common application of recursion
13
+ is in mathematics and computer science, in which it refers to a method of
14
+ defining functions in which the function being defined is applied within
15
+ its own definition. Specifically, this defines an infinite number of
16
+ instances (function values), using a finite expression that for some
17
+ instances may refer to other instances, but in such a way that no loop or
18
+ infinite chain of references can occur. The term is also used more
19
+ generally to describe a process of repeating objects in a self-similar way.
20
+ )
21
+ end
22
+
23
+ describe '1 word phrase frequency' do
24
+ subject { described_class.new(text, 1).process }
25
+
26
+ it 'should be like this' do
27
+ expect(subject[10]).to eql([['of']])
28
+ expect(subject[3]).to eql([['recursion'], ['way'], ['that'], ['infinite'], ['instances']])
29
+ end
30
+ end
31
+
32
+ describe '2 word phrase frequency' do
33
+ subject { described_class.new(text, 2).process }
34
+
35
+ it 'should be like this' do
36
+ expect(subject[2]).to eql([["recursion", "is"], ["process", "of"], ["of", "repeating"], ["in", "a"], ["a", "selfsimilar"], ["selfsimilar", "way"], ["the", "term"], ["a", "variety"], ["variety", "of"], ["to", "a"], ["in", "which"]])
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -2,7 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe Rundown do
4
4
  subject {
5
- "I'm sorry, I'm extremely busy right now. I just looked at the clock, and it's 12:54 AM, I've still got a lot of work to do. Don't worry about the event tomorrow, it's been moved ahead a week, the 28th of december. Remember though, you've got to call to get a ticket soon, their # is 1-212-323-1239. Their website says it costs $23 per person.
5
+ "I'm sorry, I'm extremely busy right now. I just looked at the clock, and it's 12:54 AM,
6
+ I've still got a lot of work to do. Don't worry about the event tomorrow,
7
+ it's been moved ahead a week, the 28th of december. Remember though,
8
+ you've got to call to get a ticket soon, their # is 1-212-323-1239. Their website says it costs $23 per person.
6
9
  If you've got enough time, they have some more information on their website, http://theevent.com. @modsognir has tickets already. #prepared
7
10
  Regards,
8
11
  David (david32@gmail.com)"
@@ -43,6 +46,17 @@ David (david32@gmail.com)"
43
46
  it { expect(Rundown::Processors::ReadingGrade.new(subject).score.round(2)).to eql(6.46) }
44
47
  end
45
48
 
49
+ describe 'frequency (1)' do
50
+ let(:result) { [["im"], ["its"], ["of"], ["youve"], ["website"]] }
51
+ it { expect(Rundown::Processors::Frequency.new(subject).process[2]).to eql(result) }
52
+ end
53
+
54
+ describe 'frequency (2)' do
55
+ let(:result) { [["youve", "got"], ["their", "website"]] }
56
+ it { expect(Rundown::Processors::Frequency.new(subject, 2).process[2]).to eql(result) }
57
+ end
58
+
59
+
46
60
  context 'basic string' do
47
61
  subject { Rundown.parse("I'll see you on the 18th, give me a ring on 07912 345 678. - Jerertt, me@example.com") }
48
62
 
@@ -11,6 +11,7 @@ require 'coveralls'
11
11
  Coveralls.wear!
12
12
 
13
13
  require 'rundown'
14
+ require 'pry'
14
15
 
15
16
  RSpec.configure do |config|
16
17
  config.treat_symbols_as_metadata_keys_with_true_values = true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rundown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Fraser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-13 00:00:00.000000000 Z
11
+ date: 2014-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nickel
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Extracts dates, phone numbers, sentiment and other items from naturally
98
112
  worded text.
99
113
  email:
@@ -114,6 +128,7 @@ files:
114
128
  - lib/rundown/processor.rb
115
129
  - lib/rundown/processors/dates.rb
116
130
  - lib/rundown/processors/email.rb
131
+ - lib/rundown/processors/frequency.rb
117
132
  - lib/rundown/processors/hashtags.rb
118
133
  - lib/rundown/processors/links.rb
119
134
  - lib/rundown/processors/phone.rb
@@ -127,6 +142,7 @@ files:
127
142
  - spec/processor_spec.rb
128
143
  - spec/processors/dates_spec.rb
129
144
  - spec/processors/email_spec.rb
145
+ - spec/processors/frequency_spec.rb
130
146
  - spec/processors/phone_spec.rb
131
147
  - spec/processors/reading_time_spec.rb
132
148
  - spec/processors/sentiment_spec.rb
@@ -161,6 +177,7 @@ test_files:
161
177
  - spec/processor_spec.rb
162
178
  - spec/processors/dates_spec.rb
163
179
  - spec/processors/email_spec.rb
180
+ - spec/processors/frequency_spec.rb
164
181
  - spec/processors/phone_spec.rb
165
182
  - spec/processors/reading_time_spec.rb
166
183
  - spec/processors/sentiment_spec.rb