rundown 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/README.md +3 -3
- data/lib/rundown.rb +2 -0
- data/lib/rundown/parser.rb +1 -10
- data/lib/rundown/processor.rb +8 -0
- data/lib/rundown/processors/links.rb +12 -0
- data/lib/rundown/processors/twitter.rb +9 -0
- data/lib/rundown/version.rb +1 -1
- data/spec/processor_spec.rb +7 -0
- data/spec/processors/twitter_spec.rb +19 -0
- data/spec/rundown_spec.rb +11 -2
- data/spec/spec_helper.rb +8 -1
- metadata +22 -16
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Rundown
|
2
2
|
=======
|
3
3
|
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/rundown.png)](http://badge.fury.io/rb/rundown) [![Build Status](https://travis-ci.org/modsognir/rundown.png)](https://travis-ci.org/modsognir/rundown)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/rundown.png)](http://badge.fury.io/rb/rundown) [![Build Status](https://travis-ci.org/modsognir/rundown.png)](https://travis-ci.org/modsognir/rundown) [![Code Climate](https://codeclimate.com/github/modsognir/rundown.png)](https://codeclimate.com/github/modsognir/rundown) [![Coverage Status](https://coveralls.io/repos/modsognir/rundown/badge.png)](https://coveralls.io/r/modsognir/rundown)
|
5
5
|
|
6
6
|
Rundown is a simple Natural Language Processor built with Ruby, inspired by [Knwl.js](https://github.com/loadfive/Knwl.js). Rundown scans through text, user data, or just about anything for likely data of interest, phone numbers, dates, locations, emails, times, as well as likelyhood of spam and overall emotion.
|
7
7
|
|
@@ -9,7 +9,7 @@ Rundown is a simple Natural Language Processor built with Ruby, inspired by [Knw
|
|
9
9
|
|
10
10
|
Add this line to your application's Gemfile:
|
11
11
|
|
12
|
-
gem '
|
12
|
+
gem 'rundown'
|
13
13
|
|
14
14
|
And then execute:
|
15
15
|
|
@@ -17,7 +17,7 @@ And then execute:
|
|
17
17
|
|
18
18
|
Or install it yourself as:
|
19
19
|
|
20
|
-
$ gem install
|
20
|
+
$ gem install rundown
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
data/lib/rundown.rb
CHANGED
@@ -8,8 +8,10 @@ require 'rundown/parser'
|
|
8
8
|
require 'rundown/processor'
|
9
9
|
require 'rundown/processors/email'
|
10
10
|
require 'rundown/processors/dates'
|
11
|
+
require 'rundown/processors/links'
|
11
12
|
require 'rundown/processors/phone'
|
12
13
|
require 'rundown/processors/sentiment'
|
14
|
+
require 'rundown/processors/twitter'
|
13
15
|
|
14
16
|
module Rundown
|
15
17
|
module_function
|
data/lib/rundown/parser.rb
CHANGED
@@ -1,20 +1,11 @@
|
|
1
1
|
module Rundown
|
2
2
|
class Parser
|
3
3
|
attr_accessor :text
|
4
|
-
|
4
|
+
|
5
5
|
def initialize(text)
|
6
6
|
@text = text
|
7
7
|
end
|
8
8
|
|
9
|
-
# def processors
|
10
|
-
# [
|
11
|
-
# ,
|
12
|
-
# Processors::Email,
|
13
|
-
# Processors::Phone,
|
14
|
-
# Processors::Sentiment
|
15
|
-
# ]
|
16
|
-
# end
|
17
|
-
|
18
9
|
def dates
|
19
10
|
@dates ||= Processors::Dates.new(text).process
|
20
11
|
end
|
data/lib/rundown/processor.rb
CHANGED
@@ -2,8 +2,16 @@ module Rundown
|
|
2
2
|
class Processor
|
3
3
|
attr_accessor :words
|
4
4
|
|
5
|
+
PUNCTUATION = /[\s`!()\[\]{};:'".,<>?]/
|
6
|
+
|
5
7
|
def initialize(words)
|
6
8
|
@words = words.to_s.split(/\s/)
|
7
9
|
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def strip_punctuation(word)
|
14
|
+
word.gsub(/^#{PUNCTUATION}/, '').gsub(/#{PUNCTUATION}$/, '')
|
15
|
+
end
|
8
16
|
end
|
9
17
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Rundown
|
2
|
+
module Processors
|
3
|
+
class Links < Rundown::Processor
|
4
|
+
REGEX = /^([a-z][a-z0-9\*\-\.]*):\/\/(?:(?:(?:[\w\.\-\+!$&'\(\)*\+,;=]|%[0-9a-f]{2})+:)*(?:[\w\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]{2})+@)?(?:(?:[a-z0-9\-\.]|%[0-9a-f]{2})+|(?:\[(?:[0-9a-f]{0,4}:)*(?:[0-9a-f]{0,4})\]))(?::[0-9]+)?(?:[\/|\?](?:[\w#!:\.\?\+=&@!$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})*)?$/xi
|
5
|
+
|
6
|
+
def process
|
7
|
+
words.select { |word| word.match(REGEX) }.map {|word| strip_punctuation(word) }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
data/lib/rundown/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Rundown
|
4
|
+
module Processors
|
5
|
+
describe Twitter do
|
6
|
+
describe 'month' do
|
7
|
+
{
|
8
|
+
"follow me on @modsognir" => "@modsognir",
|
9
|
+
" I don't know what @parndt is doing" => "@parndt"
|
10
|
+
}.each do |input, expected|
|
11
|
+
it "parse '#{input}' to '#{expected}'" do
|
12
|
+
expect(Rundown::Processors::Twitter.new(input).process.first).to eql(expected)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/rundown_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Rundown do
|
4
4
|
subject {
|
5
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.
|
6
|
-
If you've got enough time, they have some more information on their website, http://theevent.com.
|
6
|
+
If you've got enough time, they have some more information on their website, http://theevent.com. @modsognir has tickets already.
|
7
7
|
Regards,
|
8
8
|
David (david32@gmail.com)"
|
9
9
|
}
|
@@ -14,7 +14,8 @@ David (david32@gmail.com)"
|
|
14
14
|
|
15
15
|
describe 'dates' do
|
16
16
|
# FIXME: remove dependence on start date knowledge
|
17
|
-
|
17
|
+
year = Time.now.year
|
18
|
+
it { expect(Rundown::Processors::Dates.new(subject).process.map(&:start_date).map(&:date)).to include "#{year}1228"}
|
18
19
|
end
|
19
20
|
|
20
21
|
describe 'phones' do
|
@@ -25,6 +26,14 @@ David (david32@gmail.com)"
|
|
25
26
|
it { expect(Rundown::Processors::Sentiment.new(subject).process.floor).to eql(2) }
|
26
27
|
end
|
27
28
|
|
29
|
+
describe 'twitter' do
|
30
|
+
it { expect(Rundown::Processors::Twitter.new(subject).process.first).to eql('@modsognir') }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'links' do
|
34
|
+
it { expect(Rundown::Processors::Links.new(subject).process.first).to eql('http://theevent.com') }
|
35
|
+
end
|
36
|
+
|
28
37
|
context 'basic string' do
|
29
38
|
subject { Rundown.parse("I'll see you on the 18th, give me a ring on 07912 345 678. - Jerertt, me@example.com") }
|
30
39
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,17 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
|
2
3
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
3
4
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
4
5
|
# Require this file using `require "spec_helper"` to ensure that it is only
|
5
6
|
# loaded once.
|
6
7
|
#
|
7
8
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
9
|
+
|
10
|
+
require 'coveralls'
|
11
|
+
Coveralls.wear!
|
12
|
+
|
13
|
+
require 'rundown'
|
14
|
+
|
8
15
|
RSpec.configure do |config|
|
9
16
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
17
|
config.run_all_when_everything_filtered = true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,14 +9,14 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nickel
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- - '>='
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- - '>='
|
27
|
+
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- - '>='
|
35
|
+
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
38
|
type: :runtime
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- - '>='
|
43
|
+
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
@@ -48,7 +48,7 @@ dependencies:
|
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- - '>='
|
51
|
+
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
type: :runtime
|
@@ -56,7 +56,7 @@ dependencies:
|
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- - '>='
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
83
|
-
- - '>='
|
83
|
+
- - ! '>='
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
86
|
type: :development
|
@@ -88,7 +88,7 @@ dependencies:
|
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
89
|
none: false
|
90
90
|
requirements:
|
91
|
-
- - '>='
|
91
|
+
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
- !ruby/object:Gem::Dependency
|
@@ -96,7 +96,7 @@ dependencies:
|
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|
99
|
-
- - '>='
|
99
|
+
- - ! '>='
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
102
|
type: :development
|
@@ -104,7 +104,7 @@ dependencies:
|
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
|
-
- - '>='
|
107
|
+
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
description: Extracts dates, phone numbers, sentiment and other items from naturally
|
@@ -126,15 +126,19 @@ files:
|
|
126
126
|
- lib/rundown/processor.rb
|
127
127
|
- lib/rundown/processors/dates.rb
|
128
128
|
- lib/rundown/processors/email.rb
|
129
|
+
- lib/rundown/processors/links.rb
|
129
130
|
- lib/rundown/processors/phone.rb
|
130
131
|
- lib/rundown/processors/sentiment.rb
|
132
|
+
- lib/rundown/processors/twitter.rb
|
131
133
|
- lib/rundown/version.rb
|
132
134
|
- lib/rundown/words.rb
|
133
135
|
- rundown.gemspec
|
136
|
+
- spec/processor_spec.rb
|
134
137
|
- spec/processors/dates_spec.rb
|
135
138
|
- spec/processors/email_spec.rb
|
136
139
|
- spec/processors/phone_spec.rb
|
137
140
|
- spec/processors/sentiment_spec.rb
|
141
|
+
- spec/processors/twitter_spec.rb
|
138
142
|
- spec/rundown_spec.rb
|
139
143
|
- spec/spec_helper.rb
|
140
144
|
homepage: ''
|
@@ -147,21 +151,21 @@ require_paths:
|
|
147
151
|
required_ruby_version: !ruby/object:Gem::Requirement
|
148
152
|
none: false
|
149
153
|
requirements:
|
150
|
-
- - '>='
|
154
|
+
- - ! '>='
|
151
155
|
- !ruby/object:Gem::Version
|
152
156
|
version: '0'
|
153
157
|
segments:
|
154
158
|
- 0
|
155
|
-
hash:
|
159
|
+
hash: 788386041267809090
|
156
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
161
|
none: false
|
158
162
|
requirements:
|
159
|
-
- - '>='
|
163
|
+
- - ! '>='
|
160
164
|
- !ruby/object:Gem::Version
|
161
165
|
version: '0'
|
162
166
|
segments:
|
163
167
|
- 0
|
164
|
-
hash:
|
168
|
+
hash: 788386041267809090
|
165
169
|
requirements: []
|
166
170
|
rubyforge_project:
|
167
171
|
rubygems_version: 1.8.25
|
@@ -169,9 +173,11 @@ signing_key:
|
|
169
173
|
specification_version: 3
|
170
174
|
summary: Natural Language Processor
|
171
175
|
test_files:
|
176
|
+
- spec/processor_spec.rb
|
172
177
|
- spec/processors/dates_spec.rb
|
173
178
|
- spec/processors/email_spec.rb
|
174
179
|
- spec/processors/phone_spec.rb
|
175
180
|
- spec/processors/sentiment_spec.rb
|
181
|
+
- spec/processors/twitter_spec.rb
|
176
182
|
- spec/rundown_spec.rb
|
177
183
|
- spec/spec_helper.rb
|