find_keywords 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/find_keywords.gemspec +25 -0
- data/lib/find_keywords/version.rb +3 -0
- data/lib/find_keywords.rb +83 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0a4277baab77ff4776252c7c37ce8f9588d45710
|
4
|
+
data.tar.gz: ac9adf2ce1ddb9b77d732958af824caf1d266e0c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a0b27073500e298c0cd9513aeb0722684295b8182b99a3f73f609a9ae46b5b9413c5931ac8a4dce1d8ba3d4097496177d529df24111999620b81617e0293d64
|
7
|
+
data.tar.gz: 75497b8673d5ab97afc6adcf1823a316c337e5f7818a18c274572e383dc4b45ae3d61ea8294387111f34fd37acfd45b92057061e4fd56a7e7e3586c1ae77553f
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kirk Jarvis
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# FindKeywords
|
2
|
+
|
3
|
+
Finds keywords in a sentence. Uses a stop word list and market word list to remove words that are not relevent.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'find_keywords'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install find_keywords
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Find keywords is used to take a string (sentence), list (array), or a hash and return only keyword. It removes the stop words and list of other words.
|
22
|
+
|
23
|
+
ruby```
|
24
|
+
sentence = "_the yellow__jeans_"
|
25
|
+
keywords = FindKeywords::Keywords.new(sentence).keywords
|
26
|
+
keywords => ["yellow", "jeans"]
|
27
|
+
```
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it ( https://github.com/[my-github-username]/find_keywords/fork )
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'find_keywords/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "find_keywords"
|
8
|
+
spec.version = FindKeywords::VERSION
|
9
|
+
spec.authors = ["Kirk Jarvis"]
|
10
|
+
spec.email = ["zuuzlo@yahoo.com"]
|
11
|
+
spec.summary = "Finds keywords in a sentence"
|
12
|
+
spec.description = "Finds keywords in a sentence. Uses a stop word list and market word list to remove words that are not relevent."
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require "find_keywords/version"
|
2
|
+
|
3
|
+
module FindKeywords
|
4
|
+
|
5
|
+
STOP_WORDS = [
|
6
|
+
'a','cannot','into','our','thus','about','co','is','ours','to','above',
|
7
|
+
'could','it','ourselves','together','across','down','its','out','too',
|
8
|
+
'after','during','itself','over','toward','afterwards','each','last','own',
|
9
|
+
'towards','again','eg','latter','per','under','against','either','latterly',
|
10
|
+
'perhaps','until','all','else','least','rather','up','almost','elsewhere',
|
11
|
+
'less','same','upon','alone','enough','ltd','seem','us','along','etc',
|
12
|
+
'many','seemed','very','already','even','may','seeming','via','also','ever',
|
13
|
+
'me','seems','was','although','every','meanwhile','several','we','always',
|
14
|
+
'everyone','might','she','well','among','everything','more','should','were',
|
15
|
+
'amongst','everywhere','moreover','since','what','an','except','most','so',
|
16
|
+
'whatever','and','few','mostly','some','when','another','first','much',
|
17
|
+
'somehow','whence','any','for','must','someone','whenever','anyhow',
|
18
|
+
'former','my','something','where','anyone','formerly','myself','sometime',
|
19
|
+
'whereafter','anything','from','namely','sometimes','whereas','anywhere',
|
20
|
+
'further','neither','somewhere','whereby','are','had','never','still',
|
21
|
+
'wherein','around','has','nevertheless','such','whereupon','as','have',
|
22
|
+
'next','than','wherever','at','he','no','that','whether','be','hence',
|
23
|
+
'nobody','the','whither','became','her','none','their','which','because',
|
24
|
+
'here','noone','them','while','become','hereafter','nor','themselves','who',
|
25
|
+
'becomes','hereby','not','then','whoever','becoming','herein','nothing',
|
26
|
+
'thence','whole','been','hereupon','now','there','whom','before','hers',
|
27
|
+
'nowhere','thereafter','whose','beforehand','herself','of','thereby','why',
|
28
|
+
'behind','him','off','therefore','will','being','himself','often','therein',
|
29
|
+
'with','below','his','on','thereupon','within','beside','how','once',
|
30
|
+
'these','without','besides','however','one','they','would','between','i',
|
31
|
+
'only','this','yet','beyond','ie','onto','those','you','both','if','or',
|
32
|
+
'though','your','but','in','other','through','yours','by','inc','others',
|
33
|
+
'throughout','yourself','can','indeed','otherwise','thru','yourselves'
|
34
|
+
]
|
35
|
+
|
36
|
+
MARKET_WORDS = [ 'select','styles','shop','reg','orig','set', 'sets', 'offer',
|
37
|
+
'valid','get','free','shipping','double','december','coupon','save','ends',
|
38
|
+
'january','affiliate','exclusive','buy','use','code','size','order','use',
|
39
|
+
'checkout','expires','purchase','just','plus','sales','tax','promo','holiday',
|
40
|
+
'delivery','ca','co','ma','mi','oh','ri','online','members','back','points',
|
41
|
+
'orders'
|
42
|
+
]
|
43
|
+
|
44
|
+
class Keywords
|
45
|
+
|
46
|
+
attr_accessor :sentence
|
47
|
+
|
48
|
+
def initialize (sentence)
|
49
|
+
if sentence.is_a?(String)
|
50
|
+
@sentence = sentence
|
51
|
+
elsif sentence.is_a?(Array)
|
52
|
+
@sentence = sentence.join(' ')
|
53
|
+
elsif sentence.is_a?(Hash)
|
54
|
+
@sentence = sentence.collect { |k, v| "#{k} #{v} " }.join
|
55
|
+
else
|
56
|
+
@sentence = ''
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def keywords
|
61
|
+
slug = @sentence
|
62
|
+
slug.gsub! /['`]/,""
|
63
|
+
slug.gsub! /\s*@\s*/, " at "
|
64
|
+
slug.gsub! /\s*&\s*/, " and "
|
65
|
+
slug.gsub! /\s*[^A-Za-z0-9\.\-]\s*/, ' '
|
66
|
+
#slug.gsub! /\ \d+/, ''
|
67
|
+
slug.gsub!(/[^a-zA-Z ]/,'')
|
68
|
+
slug.gsub!(/ +/,' ')
|
69
|
+
#convert double underscores to single
|
70
|
+
#slug.gsub! /_+/,"_"
|
71
|
+
#strip off leading/trailing underscore
|
72
|
+
#slug.gsub! /\A[_\.]+|[_\.]+\z/,""
|
73
|
+
words = slug.downcase.scan(/\w+/)
|
74
|
+
slug_words = words.select { |word| !STOP_WORDS.include?(word)}
|
75
|
+
slug_words = slug_words.select { |word| !MARKET_WORDS.include?(word)}
|
76
|
+
slug = slug_words.join(' ')
|
77
|
+
keywords = slug.scan(/\w+/)
|
78
|
+
keywords.delete_if { |word| word.size <= 2 }
|
79
|
+
keywords.uniq! if keywords.uniq
|
80
|
+
return keywords
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: find_keywords
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kirk Jarvis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Finds keywords in a sentence. Uses a stop word list and market word
|
70
|
+
list to remove words that are not relevent.
|
71
|
+
email:
|
72
|
+
- zuuzlo@yahoo.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- find_keywords.gemspec
|
83
|
+
- lib/find_keywords.rb
|
84
|
+
- lib/find_keywords/version.rb
|
85
|
+
homepage: ''
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.0.3
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Finds keywords in a sentence
|
109
|
+
test_files: []
|