sort_rank 1.01 → 1.02
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/Gemfile.lock +1 -1
- data/README.md +24 -4
- data/Rakefile +7 -7
- data/lib/sort_rank/solver.rb +30 -0
- data/lib/sort_rank/version.rb +1 -1
- data/lib/sort_rank.rb +6 -2
- data/sort_rank.gemspec +1 -0
- metadata +3 -3
- data/lib/sort_rank/logic.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0dbd1326e7f72a8e5ae1823c9dd8138a6b59e2c8f270dfaddd3a3a4c379dd3ea
|
4
|
+
data.tar.gz: f1cfd7b63627eeee34ab15ee40a2c001218fe69452407d8f8a3fc44108c49695
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a43cbfa40eb0ecdd94ad7adebca926e80397a83c840b9bcf1a28f9c9a8ec98533c33e0fc5095f442c466e5a0c8583bb400a72eca98dd9c3ca61a2153284231f2
|
7
|
+
data.tar.gz: 287b6ba2b159098b102425f0efb0dbbe232a6d1c0b324bd52318efc778c44899c7b748e1a769c6f435a544e5f40685e993394fe2f6f7735c468fc2a0d38435fb
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,9 +3,7 @@
|
|
3
3
|
[](https://badge.fury.io/rb/sort_rank)
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
5
5
|
|
6
|
-
#### Sorts and Ranks text in strings, like a full text article or document.
|
7
|
-
|
8
|
-
Note: Currently being moved from local environment to this gem. Will be completed by 7/10/18
|
6
|
+
#### SortRank Sorts and Ranks text in strings, like a full text article or document.
|
9
7
|
|
10
8
|
## Installation
|
11
9
|
|
@@ -25,7 +23,29 @@ Or install it yourself as:
|
|
25
23
|
|
26
24
|
## Usage
|
27
25
|
|
28
|
-
|
26
|
+
|
27
|
+
1) Add your text to a hash with `:text` symbol key, then pass the arguments to `SortRank.parse(args)` like the example below. If you don't pass any args, and just run `SortRank.parse` it will return sample data for testing.
|
28
|
+
|
29
|
+
```
|
30
|
+
args = { text: "The state capitol in Austin, Texas Austin is a city of over 912,000 in the Hill Country of central Texas. It is the state capital and home to a major university as well as an influential center for politics, technology, music, film and increasingly a food scene. Austin's embrace of alternative cultures is commonly emblazoned about town on T-Shirts and bumper stickers that read: 'Keep Austin Weird.' Austin is also marketed as the 'Live Music Capital of the World' due to the large number of venues and 'Silicon Hills' reflecting the many technology companies." }
|
31
|
+
|
32
|
+
result_hash = SortRank.parse(args)
|
33
|
+
```
|
34
|
+
|
35
|
+
2) The returned data will be in hash format like below:
|
36
|
+
|
37
|
+
You can access the data, like so: `result_hash[:results]` and `result_hash[:text]`
|
38
|
+
|
39
|
+
```
|
40
|
+
{
|
41
|
+
:results=>
|
42
|
+
{
|
43
|
+
"the"=>7, "austin"=>5, "of"=>5, "is"=>4, "and"=>4, "as"=>3, "music"=>2, "to"=>2, "technology"=>2, "capital"=>2, "texas"=>2, "in"=>2, "state"=>2, "keep"=>1, "read"=>1, "that"=>1, "stickers"=>1, "bumper"=>1, "shirts"=>1, "on"=>1, "town"=>1, "about"=>1, "emblazoned"=>1, "commonly"=>1, "cultures"=>1, "alternative"=>1, "embrace"=>1, "scene"=>1, "food"=>1, "increasingly"=>1, "film"=>1, "politics"=>1, "for"=>1, "center"=>1, "influential"=>1, "an"=>1, "well"=>1, "university"=>1, "major"=>1, "home"=>1, "it"=>1, "central"=>1, "country"=>1, "hill"=>1, "000"=>1, "912"=>1, "over"=>1, "city"=>1, "capitol"=>1, "many"=>1, "reflecting"=>1, "hills"=>1, "silicon"=>1, "venues"=>1, "number"=>1, "large"=>1, "due"=>1, "world"=>1, "live"=>1, "marketed"=>1, "also"=>1, "weird"=>1, "companies"=>1
|
44
|
+
},
|
45
|
+
:text=>
|
46
|
+
"The state capitol in Austin, Texas Austin is a city of over 912,000 in the Hill Country of central Texas. It is the state capital and home to a major university as well as an influential center for politics, technology, music, film and increasingly a food scene. Austin's embrace of alternative cultures is commonly emblazoned about town on T-Shirts and bumper stickers that read: 'Keep Austin Weird.' Austin is also marketed as the 'Live Music Capital of the World' due to the large number of venues and 'Silicon Hills' reflecting the many technology companies."
|
47
|
+
}
|
48
|
+
```
|
29
49
|
|
30
50
|
## Development
|
31
51
|
|
data/Rakefile
CHANGED
@@ -18,18 +18,18 @@ task :console do
|
|
18
18
|
require "active_support/all"
|
19
19
|
ARGV.clear
|
20
20
|
|
21
|
-
|
22
|
-
# binding.pry
|
21
|
+
result_hash = run_sort_rank
|
23
22
|
|
24
23
|
IRB.start
|
25
24
|
end
|
26
25
|
|
27
26
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
def run_sort_rank
|
28
|
+
# args = {text: "Can a rat eat tar? How big is the arc of that car door? Could you pass me the book just below your elbow? Does your state have a coffee taste test?" }
|
29
|
+
|
30
|
+
args = { text: "The state capitol in Austin, Texas Austin is a city of over 912,000 in the Hill Country of central Texas. It is the state capital and home to a major university as well as an influential center for politics, technology, music, film and increasingly a food scene. Austin's embrace of alternative cultures is commonly emblazoned about town on T-Shirts and bumper stickers that read: 'Keep Austin Weird.' Austin is also marketed as the 'Live Music Capital of the World' due to the large number of venues and 'Silicon Hills' reflecting the many technology companies." }
|
31
|
+
|
32
|
+
result_hash = SortRank.parse(args)
|
33
33
|
|
34
34
|
# scraper = LinkScraper::Scrape.new({text_criteria: text_criteria, path_criteria: path_criteria})
|
35
35
|
# scraped_links = scraper.start('https://en.wikipedia.org/wiki/Austin%2C_Texas')
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
module SortRank
|
3
|
+
class Solver
|
4
|
+
|
5
|
+
# AlgoService.new.parse
|
6
|
+
def parse(args={})
|
7
|
+
string_block = args.fetch(:text, nil)
|
8
|
+
string_block = sample_string_block if !string_block.present?
|
9
|
+
result_hash = {results: count_strings(string_block), text: string_block }
|
10
|
+
end
|
11
|
+
|
12
|
+
def count_strings(string)
|
13
|
+
if string.present?
|
14
|
+
array = string.split(/\W+/)
|
15
|
+
array.map!(&:downcase)
|
16
|
+
array.reject!{|el| el.length < 2 }
|
17
|
+
|
18
|
+
string_count_hash = array.group_by{|e| e}.map{|k, v| [k, v.length]}.to_h
|
19
|
+
word_rankings = string_count_hash.sort_by {|key, value| value}.reverse!
|
20
|
+
# results = word_rankings.to_h.map { |k,v| "#{k} (#{v})" }.join(', ')
|
21
|
+
results = word_rankings.to_h
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def sample_string_block
|
26
|
+
"The state capitol in Austin, Texas Austin is a city of over 912,000 in the Hill Country of central Texas. It is the state capital and home to a major university as well as an influential center for politics, technology, music, film and increasingly a food scene. Austin's embrace of alternative cultures is commonly emblazoned about town on T-Shirts and bumper stickers that read: 'Keep Austin Weird.' Austin is also marketed as the 'Live Music Capital of the World' due to the large number of venues and 'Silicon Hills' reflecting the many technology companies."
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/lib/sort_rank/version.rb
CHANGED
data/lib/sort_rank.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
require "sort_rank/version"
|
2
2
|
|
3
|
-
require "sort_rank/
|
3
|
+
require "sort_rank/solver"
|
4
4
|
# require 'mechanizer'
|
5
5
|
# require 'scrub_db'
|
6
6
|
require 'pry'
|
7
7
|
|
8
8
|
module SortRank
|
9
|
-
|
9
|
+
|
10
|
+
def self.parse(args={})
|
11
|
+
result_hash = self::Solver.new.parse(args)
|
12
|
+
end
|
13
|
+
|
10
14
|
end
|
data/sort_rank.gemspec
CHANGED
@@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.add_dependency 'scrub_db', '~> 2.23'
|
38
38
|
spec.add_dependency 'url_verifier', '~> 2.12'
|
39
39
|
spec.add_dependency 'utf8_sanitizer', '~> 2.16'
|
40
|
+
# spec.add_dependency 'wikipedia-client', '~> 1.5'
|
40
41
|
|
41
42
|
# spec.add_dependency "activesupport-inflector", ['~> 0.1.0']
|
42
43
|
spec.add_development_dependency 'bundler', '~> 1.16', '>= 1.16.2'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sort_rank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.02'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Booth
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -181,7 +181,7 @@ files:
|
|
181
181
|
- bin/console
|
182
182
|
- bin/setup
|
183
183
|
- lib/sort_rank.rb
|
184
|
-
- lib/sort_rank/
|
184
|
+
- lib/sort_rank/solver.rb
|
185
185
|
- lib/sort_rank/version.rb
|
186
186
|
- sort_rank.gemspec
|
187
187
|
homepage: https://github.com/4rlm/sort_rank
|