find_keywords 0.0.1 → 0.0.2
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/.rspec +2 -0
- data/lib/find_keywords.rb +2 -0
- data/lib/find_keywords/version.rb +1 -1
- data/spec/find_keywords_spec.rb +104 -0
- data/spec/spec_helper.rb +12 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdbd8152551c10c81c3d5d51a4cbbb0e7209b655
|
4
|
+
data.tar.gz: e222324b1bafd7c655cad97117aa6c31d5e3e6fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f55ed7039965e2b670951b2771bf9eeafd8a02a1d8b3d909d531d59605cc2825d72d6939a28ea9b0df7b3e57d6b05d57a09e70b31835c861c2e767717978456
|
7
|
+
data.tar.gz: 8319c48e45811d31b796e2d62ed6adb15713f8a07ea6924fd61cf9e3a1409faf057e1353e020aae3c7b36cc4c67e40c7fc81b6136e49ca15af32dcc6d20def63
|
data/.rspec
ADDED
data/lib/find_keywords.rb
CHANGED
@@ -59,6 +59,8 @@ module FindKeywords
|
|
59
59
|
|
60
60
|
def keywords
|
61
61
|
slug = @sentence
|
62
|
+
slug.gsub!(/(\d{2}|\d{1})\/(\d{2}|\d{1})(-|.-.)(\d{2}|\d{1})\/(\d{2}|\d{1})/, "") #add rev 0.0.2 remove date
|
63
|
+
slug.gsub!(/(Sept|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug)(\s*)(\d*|)(-|.-.|)/, "") #add rev 0.0.2 remove date
|
62
64
|
slug.gsub! /['`]/,""
|
63
65
|
slug.gsub! /\s*@\s*/, " at "
|
64
66
|
slug.gsub! /\s*&\s*/, " and "
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "FindKeywords" do
|
4
|
+
|
5
|
+
context "errors" do
|
6
|
+
|
7
|
+
it "requires a string" do
|
8
|
+
expect {FindKeywords::Keywords.new}.to raise_error(ArgumentError)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns blank on nil input" do
|
12
|
+
sentence = nil
|
13
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
14
|
+
expect(keywords).to eq([])
|
15
|
+
end
|
16
|
+
|
17
|
+
it "splits an array to string" do
|
18
|
+
sentence = ["the", "fox", "shoes"]
|
19
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
20
|
+
expect(keywords).to eq(["fox", "shoes"])
|
21
|
+
end
|
22
|
+
|
23
|
+
it "convert hash to string" do
|
24
|
+
sentence = { the: "big dog", animal: "fox", wears: "shoes" }
|
25
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
26
|
+
expect(keywords).to eq(["big", "dog", "animal", "fox", "wears", "shoes"])
|
27
|
+
end
|
28
|
+
|
29
|
+
it "retuns no key words for numbers" do
|
30
|
+
sentence = 567
|
31
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
32
|
+
expect(keywords).to eq([])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "remove unneeded characters" do
|
37
|
+
|
38
|
+
it "removes apostrophes" do
|
39
|
+
sentence = "Kirk's"
|
40
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
41
|
+
expect(keywords).to eq(['kirks'])
|
42
|
+
end
|
43
|
+
|
44
|
+
it "removes symbols @ and &" do
|
45
|
+
sentence = "@kirk & jarvis"
|
46
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
47
|
+
expect(keywords).to eq(['kirk', 'jarvis'])
|
48
|
+
end
|
49
|
+
|
50
|
+
it "replace all non alphanumeric, underscore or periods with blank" do
|
51
|
+
sentence = "@kirk & jarvis_ the ship. $ %"
|
52
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
53
|
+
expect(keywords).to eq(['kirk', 'jarvis', 'ship'])
|
54
|
+
end
|
55
|
+
|
56
|
+
it "replace all numbers with nothing" do
|
57
|
+
sentence = "@kirk & jarvis_ the ship. $ 20 %"
|
58
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
59
|
+
expect(keywords).to eq(['kirk', 'jarvis', 'ship'])
|
60
|
+
end
|
61
|
+
|
62
|
+
it "downcases all words" do
|
63
|
+
sentence = "@kirk & JARVIS_ the ship. $ 20 %"
|
64
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
65
|
+
expect(keywords).to eq(['kirk', 'jarvis', 'ship'])
|
66
|
+
end
|
67
|
+
|
68
|
+
it "removes stop words" do
|
69
|
+
sentence = "The quick brown fox jump over the lazy dog."
|
70
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
71
|
+
expect(keywords).to eq(["quick", "brown", "fox", "jump", "lazy", "dog"])
|
72
|
+
end
|
73
|
+
|
74
|
+
it "removes industry specific words" do
|
75
|
+
sentence = "free shipping For women members"
|
76
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
77
|
+
expect(keywords).to eq(["women"])
|
78
|
+
end
|
79
|
+
|
80
|
+
it "removes duplicutes" do
|
81
|
+
sentence = "women women women"
|
82
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
83
|
+
expect(keywords).to eq(["women"])
|
84
|
+
end
|
85
|
+
|
86
|
+
it "removes words less than 2 characters" do
|
87
|
+
sentence = "ta vg the game"
|
88
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
89
|
+
expect(keywords).to eq(["game"])
|
90
|
+
end
|
91
|
+
|
92
|
+
it "removes leading and trailing underscore" do
|
93
|
+
sentence = "_the yellow__jeans_"
|
94
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
95
|
+
expect(keywords).to eq(["yellow", "jeans"])
|
96
|
+
end
|
97
|
+
|
98
|
+
it "removes date Oct - 25" do
|
99
|
+
sentence = "Dana Buchman Apparel with code DANA10. Sept 24 – Oct 4"
|
100
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
101
|
+
expect(keywords).to eq(["dana", "buchman", "apparel"])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'find_keywords'
|
4
|
+
#require_relative './support/fake_pepperjam_api'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
=begin
|
8
|
+
config.before(:each) do
|
9
|
+
stub_request(:any, /api.pepperjamnetwork.com/ ).to_rack( FakePepperjamApi )
|
10
|
+
end
|
11
|
+
=end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: find_keywords
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirk Jarvis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05
|
11
|
+
date: 2014-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,6 +75,7 @@ extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- .gitignore
|
78
|
+
- .rspec
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE.txt
|
80
81
|
- README.md
|
@@ -82,6 +83,8 @@ files:
|
|
82
83
|
- find_keywords.gemspec
|
83
84
|
- lib/find_keywords.rb
|
84
85
|
- lib/find_keywords/version.rb
|
86
|
+
- spec/find_keywords_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
85
88
|
homepage: ''
|
86
89
|
licenses:
|
87
90
|
- MIT
|
@@ -106,4 +109,6 @@ rubygems_version: 2.0.3
|
|
106
109
|
signing_key:
|
107
110
|
specification_version: 4
|
108
111
|
summary: Finds keywords in a sentence
|
109
|
-
test_files:
|
112
|
+
test_files:
|
113
|
+
- spec/find_keywords_spec.rb
|
114
|
+
- spec/spec_helper.rb
|