rundown 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rundown.rb +1 -0
- data/lib/rundown/processors/frequency.rb +40 -0
- data/lib/rundown/version.rb +1 -1
- data/rundown.gemspec +1 -0
- data/spec/processors/frequency_spec.rb +41 -0
- data/spec/rundown_spec.rb +15 -1
- data/spec/spec_helper.rb +1 -0
- metadata +19 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1fcd7089261e9b5744c151011025ea7a1c00991e
|
|
4
|
+
data.tar.gz: d80f58134c95cdb18482ff398bb315269f8c01ce
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9525faeba11849f6ce52d1ff94c5a56debdd94d9f63543a8d09ecea9125c0df60c3489cfa45f0724886eacbadd7406981d3e2eba7340604553627a867a847247
|
|
7
|
+
data.tar.gz: 2ee25733bf9f51825a4985abd4a38898f503d414bb705c0eaffddc0da80ef483ecc5eae7045bd7667af7239a44b9f8202ad14db7a56d3977c26806f7140a4fa3
|
data/lib/rundown.rb
CHANGED
|
@@ -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
|
data/lib/rundown/version.rb
CHANGED
data/rundown.gemspec
CHANGED
|
@@ -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
|
data/spec/rundown_spec.rb
CHANGED
|
@@ -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,
|
|
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
|
|
data/spec/spec_helper.rb
CHANGED
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.
|
|
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
|
+
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
|