cloud_text 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 983b4f884b5029e10005ae1e89c31d2c97f16ace
4
+ data.tar.gz: 88cea0d72ea1fde97fb59cc552552c3efebb8adf
5
+ SHA512:
6
+ metadata.gz: 4e9f961744d2d31dd61a075029c53746161c723e588199995a2dbd8a36b9f80abb19c50b3fe0345a0d118310a82c27ccbd8a32662487910cab9c8eec5590ab65
7
+ data.tar.gz: 064e0468f37ebc8ba528f2f27d6fafcba6b102bfda2b42823ccd17b1bee3020f1899f674e561a0cd46e3d03755517e397617082ff88873b335194df215b77732
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at recepinancc@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in cloud_text.gemspec
6
+ gemspec
7
+ gem 'unicode_utils'
8
+ gem 'stopwords-filter'
9
+ gem 'ruby-stemmer'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Twentify
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # CloudText
2
+
3
+ This gem removes punctuation and digits(optional), filters stopwords for the chosen language ('tr', 'en' or 'fr'), does stemming on the words and outputs an array of words with their frequencies.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cloud_text'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cloud_text
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'cloud_text'
25
+
26
+ # Default options
27
+ # remove_digits => false
28
+ # language => "en"
29
+ # stemming => false
30
+
31
+ options = { remove_digits: false, language: "en", stemming: true }
32
+ cleaner = CloudText.clean_text("Your text to be cleaned, will come here1!1", options)
33
+ # => [["come", 1], ["will", 1], ["clean", 1], ["text", 1]]
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/twentify/cloud_text. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
39
+
40
+ ## Code of Conduct
41
+
42
+ Everyone interacting in the CloudText project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/twentify/cloud_text/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cloud_text"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cloud_text/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cloud_text"
8
+ spec.version = CloudText::VERSION
9
+ spec.authors = ["recepinanc"]
10
+ spec.email = ["recepinancc@gmail.com"]
11
+
12
+ spec.summary = "Cleans the given text for the given language."
13
+ spec.description = "This gem removes punctuation and digits(optional), filters stopwords for the chosen language ('tr', 'en' or 'fr'), does stemming on the words and outputs an array of words with their frequencies."
14
+ spec.homepage = "https://github.com/twentify/cloud_text"
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
@@ -0,0 +1,3 @@
1
+ module CloudText
2
+ VERSION = "0.1.0"
3
+ end
data/lib/cloud_text.rb ADDED
@@ -0,0 +1,56 @@
1
+ require "cloud_text/version"
2
+ require "unicode_utils"
3
+ require "stopwords"
4
+ require "lingua/stemmer"
5
+
6
+ module CloudText
7
+
8
+ def self.clean_text(input, options = {})
9
+ @input = input
10
+ @options = options
11
+
12
+ # Remove punctuation and/or digits
13
+ remove_digits = @options.fetch(:remove_digits, false)
14
+ if remove_digits
15
+ @input = input.gsub(/[^A-Za-z0-9^şŞıİçÇöÖüÜĞğ\s]|_|\d/, ' ')
16
+ else
17
+ @input = input.gsub(/[^A-Za-z0-9^şŞıİçÇöÖüÜĞğ\s]|_/, ' ')
18
+ end
19
+ # Reduce multiple whitespaces into single whitespace
20
+ @input = @input.gsub(/\s+/, ' ')
21
+
22
+ # Lowercase all tokens
23
+ @language = @options.fetch(:language, "en")
24
+ @input = UnicodeUtils.downcase(@input, @language.to_sym)
25
+
26
+ # Filter stopwords
27
+ @cutsom_stopwords = @options.fetch(:stopwords, [])
28
+ if @language == "tr"
29
+ stopword_filter = Stopwords::Filter.new tr_stopwords
30
+ else
31
+ stopword_filter = Stopwords::Snowball::Filter.new @language
32
+ end
33
+
34
+ # Here we intentionally do not downcase custom_stopwords
35
+ # since we want to filter only capitalized version of a word
36
+ stopword_filter.stopwords << @cutsom_stopwords
37
+ @input = stopword_filter.filter(@input.split)
38
+
39
+ # Stemming
40
+ stemming_enabled = @options.fetch(:stemming, false)
41
+ if stemming_enabled
42
+ stemmer = Lingua::Stemmer.new(language: @language)
43
+ @input = @input.map do |word|
44
+ stemmer.stem(word)
45
+ end
46
+ end
47
+
48
+ # Counting the words, generate array for each element like => [word, frequency]
49
+ @result = @input.each_with_object(Hash.new(0)) { |token, hash| hash[token] += 1 }.sort_by {|k,v| v}.reverse
50
+ end
51
+
52
+ private
53
+ def self.tr_stopwords
54
+ ['a','acaba','altı','altmış','ama','ancak','arada','artık','asla','aslında','aslında','ayrıca','az','bana','bazen','bazı','bazıları','belki','ben','benden','beni','benim','beri','beş','bile','bilhassa','bin','bir','biraz','birçoğu','birçok','biri','birisi','birkaç','birşey','biz','bizden','bize','bizi','bizim','böyle','böylece','bu','buna','bunda','bundan','bunlar','bunları','bunların','bunu','bunun','burada','bütün','çoğu','çoğunu','çok','çünkü','da','daha','dahi','dan','de','defa','değil','diğer','diğeri','diğerleri','diye','doksan','dokuz','dolayı','dolayısıyla','dört','e','edecek','eden','ederek','edilecek','ediliyor','edilmesi','ediyor','eğer','elbette','elli','en','etmesi','etti','ettiği','ettiğini','fakat','falan','filan','gene','gereği','gerek','gibi','göre','hala','halde','halen','hangi','hangisi','hani','hatta','hem','henüz','hep','hepsi','her','herhangi','herkes','herkese','herkesi','herkesin','hiç','hiçbir','hiçbiri','i','ı','için','içinde','iki','ile','ilgili','ise','işte','itibaren','itibariyle','kaç','kadar','karşın','kendi','kendilerine','kendine','kendini','kendisi','kendisine','kendisini','kez','ki','kim','kime','kimi','kimin','kimisi','kimse','kırk','madem','mi','mı','milyar','milyon','mu','mü','nasıl','ne','neden','nedenle','nerde','nerede','nereye','neyse','niçin','nin','nın','niye','nun','nün','o','öbür','olan','olarak','oldu','olduğu','olduğunu','olduklarını','olmadı','olmadığı','olmak','olması','olmayan','olmaz','olsa','olsun','olup','olur','olur','olursa','oluyor','on','ön','ona','önce','ondan','onlar','onlara','onlardan','onları','onların','onu','onun','orada','öte','ötürü','otuz','öyle','oysa','pek','rağmen','sana','sanki','sanki','şayet','şekilde','sekiz','seksen','sen','senden','seni','senin','şey','şeyden','şeye','şeyi','şeyler','şimdi','siz','siz','sizden','sizden','size','sizi','sizi','sizin','sizin','sonra','şöyle','şu','şuna','şunları','şunu','ta','tabii','tam','tamam','tamamen','tarafından','trilyon','tüm','tümü','u','ü','üç','un','ün','üzere','var','vardı','ve','veya','ya','yani','yapacak','yapılan','yapılması','yapıyor','yapmak','yaptı','yaptığı','yaptığını','yaptıkları','ye','yedi','yerine','yetmiş','yi','yı','yine','yirmi','yoksa','yu','yüz','zaten','zira']
55
+ end
56
+ end
@@ -0,0 +1 @@
1
+ ['a','acaba','altı','altmış','ama','ancak','arada','artık','asla','aslında','aslında','ayrıca','az','bana','bazen','bazı','bazıları','belki','ben','benden','beni','benim','beri','beş','bile','bilhassa','bin','bir','biraz','birçoğu','birçok','biri','birisi','birkaç','birşey','biz','bizden','bize','bizi','bizim','böyle','böylece','bu','buna','bunda','bundan','bunlar','bunları','bunların','bunu','bunun','burada','bütün','çoğu','çoğunu','çok','çünkü','da','daha','dahi','dan','de','defa','değil','diğer','diğeri','diğerleri','diye','doksan','dokuz','dolayı','dolayısıyla','dört','e','edecek','eden','ederek','edilecek','ediliyor','edilmesi','ediyor','eğer','elbette','elli','en','etmesi','etti','ettiği','ettiğini','fakat','falan','filan','gene','gereği','gerek','gibi','göre','hala','halde','halen','hangi','hangisi','hani','hatta','hem','henüz','hep','hepsi','her','herhangi','herkes','herkese','herkesi','herkesin','hiç','hiçbir','hiçbiri','i','ı','için','içinde','iki','ile','ise','işte','itibaren','itibariyle','kaç','kadar','karşın','kendi','kendilerine','kendine','kendini','kendisi','kendisine','kendisini','kez','ki','kim','kime','kimi','kimin','kimisi','kimse','kırk','madem','mi','mı','milyar','milyon','mu','mü','nasıl','ne','neden','nedenle','nerde','nerede','nereye','neyse','niçin','nin','nın','niye','nun','nün','o','öbür','olan','olarak','oldu','olduğu','olduğunu','olduklarını','olmadı','olmadığı','olmak','olması','olmayan','olmaz','olsa','olsun','olup','olur','olur','olursa','oluyor','on','ön','ona','önce','ondan','onlar','onlara','onlardan','onları','onların','onu','onun','orada','öte','ötürü','otuz','öyle','oysa','pek','rağmen','sana','sanki','sanki','şayet','şekilde','sekiz','seksen','sen','senden','seni','senin','şey','şeyden','şeye','şeyi','şeyler','şimdi','siz','siz','sizden','sizden','size','sizi','sizi','sizin','sizin','sonra','şöyle','şu','şuna','şunları','şunu','ta','tabii','tam','tamam','tamamen','tarafından','trilyon','tüm','tümü','u','ü','üç','un','ün','üzere','var','vardı','ve','veya','ya','yani','yapacak','yapılan','yapılması','yapıyor','yapmak','yaptı','yaptığı','yaptığını','yaptıkları','ye','yedi','yerine','yetmiş','yi','yı','yine','yirmi','yoksa','yu','yüz','zaten',zira]
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloud_text
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - recepinanc
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-30 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: This gem removes punctuation and digits(optional), filters stopwords
56
+ for the chosen language ('tr', 'en' or 'fr'), does stemming on the words and outputs
57
+ an array of words with their frequencies.
58
+ email:
59
+ - recepinancc@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - CODE_OF_CONDUCT.md
68
+ - Gemfile
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - cloud_text.gemspec
75
+ - lib/cloud_text.rb
76
+ - lib/cloud_text/version.rb
77
+ - lib/tr_stopwords.txt
78
+ homepage: https://github.com/twentify/cloud_text
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.6.8
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Cleans the given text for the given language.
102
+ test_files: []