text_parser 0.1.10 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +36 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +2 -2
- data/README.md +17 -23
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/text_parser.rb +5 -5
- data/lib/text_parser/version.rb +1 -1
- data/text_parser.gemspec +18 -14
- metadata +76 -50
- data/.travis.yml +0 -7
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7e434896e5da54c836ac1dd16011469675cbdb1d
|
4
|
+
data.tar.gz: a3bc147587e2591321775de24f0b3a0df96ba5fc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7572a8e76943f71bb25451050f24fcf94be962cfc1fae00b3392d4b7b68946c52c3bdc12f8d5cf88fa0769af1c7f5180c613726f7ae9daa8dced0d9324369eb0
|
7
|
+
data.tar.gz: 957167a13a37d2c3eda12e968beb05bea235ad7187f72098e35e32148ba611e35287debfac63fbd1552c2a43cbc6e82e61f8b72d901d539cbc9e9d624a647781
|
@@ -0,0 +1,36 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
docker:
|
5
|
+
- image: circleci/ruby:2.4.1
|
6
|
+
|
7
|
+
working_directory: ~/repo
|
8
|
+
|
9
|
+
steps:
|
10
|
+
- checkout
|
11
|
+
|
12
|
+
- restore_cache:
|
13
|
+
keys:
|
14
|
+
- v1-dependencies
|
15
|
+
|
16
|
+
- run:
|
17
|
+
name: install dependencies
|
18
|
+
command: |
|
19
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
20
|
+
|
21
|
+
- save_cache:
|
22
|
+
paths:
|
23
|
+
- ./venv
|
24
|
+
key: v1-dependencies
|
25
|
+
|
26
|
+
- run:
|
27
|
+
name: run tests
|
28
|
+
command: |
|
29
|
+
mkdir /tmp/test-results
|
30
|
+
bundle exec rake test
|
31
|
+
|
32
|
+
- store_test_results:
|
33
|
+
path: /tmp/test-results
|
34
|
+
- store_artifacts:
|
35
|
+
path: /tmp/test-results
|
36
|
+
destination: test-results
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.2
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 frederico.paula@youse.com.br. 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
CHANGED
data/README.md
CHANGED
@@ -2,52 +2,47 @@
|
|
2
2
|
|
3
3
|
Using method parse in the String object you can parse any text.
|
4
4
|
|
5
|
-
![
|
5
|
+
[![CircleCI](https://circleci.com/gh/fpaula/text_parser/tree/master.svg?style=svg)](https://circleci.com/gh/fpaula/text_parser/tree/master)
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
+
|
9
10
|
Add this line to your application's Gemfile:
|
10
11
|
|
11
12
|
gem 'text_parser'
|
12
13
|
|
13
|
-
And then
|
14
|
+
And then run:
|
14
15
|
|
15
|
-
|
16
|
+
`bundle install`
|
16
17
|
|
17
18
|
Or install it yourself as:
|
18
19
|
|
19
|
-
|
20
|
+
`gem install text_parser`
|
20
21
|
|
21
22
|
## Usage
|
22
|
-
|
23
|
-
"Simple, simple test".parse
|
23
|
+
```ruby
|
24
|
+
"Simple, simple test".parse
|
24
25
|
# => [{:word => "simple", :hits => 2}, {:word => "test", :hits => 1}]
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
```
|
27
|
+
```ruby
|
28
28
|
my_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque pretium consectetur."
|
29
29
|
my_text.parse(:dictionary => ["dolor", "consectetur"])
|
30
30
|
# => [{:word => "consectetur", :hits => 2}, {:word => "dolor", :hits => 1}]
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
```
|
32
|
+
```ruby
|
34
33
|
my_text.parse(:dictionary => ["dolor", "consectetur"], :order => :word, :order_direction => :desc)
|
35
34
|
# => [{:word => "dolor", :hits => 1}, {:word => "consectetur", :hits => 2}]
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
```
|
36
|
+
```ruby
|
39
37
|
"Lorem ipsum dolor sit amet".parse(:negative_dictionary => ["ipsum", "dolor", "sit"])
|
40
38
|
# => [{:word => "loren", :hits => 1}, {:word => "amet", :hits => 1}]
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
```
|
40
|
+
```ruby
|
44
41
|
"My test!".parse(:minimum_length => 3)
|
45
42
|
# => [{:word => "test", :hits => 1}]
|
43
|
+
```
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
### Arguments (Hash)
|
50
|
-
|
45
|
+
### Arguments (hash)
|
51
46
|
| Key | Type | Default value |
|
52
47
|
| ------------------------------- | ------ | ------------- |
|
53
48
|
| :dictionary | Array | nil |
|
@@ -56,7 +51,6 @@ Or install it yourself as:
|
|
56
51
|
| :negative_dictionary | Array | nil |
|
57
52
|
| :minimum_length | int | nil |
|
58
53
|
|
59
|
-
Try it online at the [site example](http://textparser.heroku.com "Title").
|
60
54
|
|
61
55
|
## Contributing
|
62
56
|
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "text_parser"
|
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
data/lib/text_parser.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
-
|
2
|
+
require_relative "text_parser/version"
|
3
3
|
|
4
4
|
module TextParser
|
5
5
|
# Returns a parsed text with the words and its occurrences.
|
6
6
|
# @param [Hash] [args]
|
7
7
|
# [args] [Symbol] :dictionary, :order, :order_direction, :negative_dictionary
|
8
|
-
# @return [Array of Hash]
|
8
|
+
# @return [Array of Hash]
|
9
9
|
def parse(args = {})
|
10
10
|
args.delete_if {|key, value| value.nil? }
|
11
11
|
options = {
|
@@ -18,11 +18,11 @@ module TextParser
|
|
18
18
|
options[:dictionary] = text.split(" ") unless options[:dictionary]
|
19
19
|
return [] if options[:dictionary].count < 1
|
20
20
|
regex = Regexp.new(options[:dictionary].join('\\b|\\b'), Regexp::IGNORECASE)
|
21
|
-
match_result = text.scan(regex).map{|i| i.downcase}
|
21
|
+
match_result = text.scan(regex).map{|i| i.downcase}
|
22
22
|
match_result = match_result.select{|i| i.size >= options[:minimum_length]} if options[:minimum_length]
|
23
23
|
match_result.each do |w|
|
24
24
|
result << {:hits => match_result.count(w), :word => w} unless result.select{|r| r[:word] == w}.shift || options[:negative_dictionary].map{|i| i.downcase}.include?(w)
|
25
|
-
end
|
25
|
+
end
|
26
26
|
result = result.sort_by{|i| i[options[:order]]}
|
27
27
|
result.reverse! if options[:order_direction] == :desc
|
28
28
|
result
|
@@ -32,4 +32,4 @@ end
|
|
32
32
|
# Includes module TextParser in the String object
|
33
33
|
class String
|
34
34
|
include TextParser
|
35
|
-
end
|
35
|
+
end
|
data/lib/text_parser/version.rb
CHANGED
data/text_parser.gemspec
CHANGED
@@ -1,19 +1,23 @@
|
|
1
|
-
#
|
1
|
+
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'text_parser/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "text_parser"
|
8
|
+
spec.version = TextParser::VERSION
|
9
|
+
spec.authors = ["Frederico de Paula"]
|
10
|
+
spec.email = ["fpaula@gmail.com"]
|
11
|
+
spec.description = %q{Includes a parse method on String object}
|
12
|
+
spec.summary = %q{Using method parse in the String object you can parse any text.}
|
13
|
+
spec.homepage = "https://github.com/fpaula/text_parser"
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
21
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
22
|
+
spec.add_development_dependency 'test-unit', '~> 3.2'
|
23
|
+
end
|
metadata
CHANGED
@@ -1,42 +1,79 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: text_parser
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 10
|
10
|
-
version: 0.1.10
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Frederico de Paula
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
date: 2018-09-20 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.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
21
55
|
description: Includes a parse method on String object
|
22
|
-
email:
|
56
|
+
email:
|
23
57
|
- fpaula@gmail.com
|
24
|
-
executables:
|
25
|
-
|
58
|
+
executables:
|
59
|
+
- console
|
60
|
+
- setup
|
26
61
|
extensions: []
|
27
|
-
|
28
62
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
|
31
|
-
- .gitignore
|
32
|
-
- .
|
33
|
-
- .yardoc/checksums
|
34
|
-
- .yardoc/objects/root.dat
|
35
|
-
- .yardoc/proxy_types
|
63
|
+
files:
|
64
|
+
- ".circleci/config.yml"
|
65
|
+
- ".gitignore"
|
66
|
+
- ".ruby-version"
|
67
|
+
- ".yardoc/checksums"
|
68
|
+
- ".yardoc/objects/root.dat"
|
69
|
+
- ".yardoc/proxy_types"
|
70
|
+
- CODE_OF_CONDUCT.md
|
36
71
|
- Gemfile
|
37
72
|
- LICENSE.txt
|
38
73
|
- README.md
|
39
74
|
- Rakefile
|
75
|
+
- bin/console
|
76
|
+
- bin/setup
|
40
77
|
- doc/String.html
|
41
78
|
- doc/TextParser.html
|
42
79
|
- doc/TextParser/Version.html
|
@@ -58,39 +95,28 @@ files:
|
|
58
95
|
- lib/text_parser/version.rb
|
59
96
|
- test/text_parser_test.rb
|
60
97
|
- text_parser.gemspec
|
61
|
-
homepage:
|
98
|
+
homepage: https://github.com/fpaula/text_parser
|
62
99
|
licenses: []
|
63
|
-
|
100
|
+
metadata: {}
|
64
101
|
post_install_message:
|
65
102
|
rdoc_options: []
|
66
|
-
|
67
|
-
require_paths:
|
103
|
+
require_paths:
|
68
104
|
- lib
|
69
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
-
|
71
|
-
requirements:
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
72
107
|
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
version: "0"
|
78
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
|
-
requirements:
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
81
112
|
- - ">="
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
|
84
|
-
segments:
|
85
|
-
- 0
|
86
|
-
version: "0"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
87
115
|
requirements: []
|
88
|
-
|
89
116
|
rubyforge_project:
|
90
|
-
rubygems_version:
|
117
|
+
rubygems_version: 2.6.13
|
91
118
|
signing_key:
|
92
|
-
specification_version:
|
119
|
+
specification_version: 4
|
93
120
|
summary: Using method parse in the String object you can parse any text.
|
94
|
-
test_files:
|
121
|
+
test_files:
|
95
122
|
- test/text_parser_test.rb
|
96
|
-
has_rdoc:
|