english_thesaurus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5398d4b51cc67e9541928afd0293c24ad7e729d2
4
+ data.tar.gz: 2e602cde49fb38e2e5e7d54b475ec4621d875e22
5
+ SHA512:
6
+ metadata.gz: 919051bd6fbde5d887ef2445678a3abd408e5542154e072d9ad31737fc6f83fc37478eb19981d64dc3f0f64c0013bba34a57856fde096fbaa7960e04d5e734b3
7
+ data.tar.gz: deab8933ca72b4373568e9c98076c9053045d934e552d072de45eab773a9cc809f546474c0596fabbf15059eab5c321aec68042c84de1e019913ebb86a81baea
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in english_thesaurus.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 dany1468
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # EnglishThesaurus
2
+
3
+ Search synonyms from http://thesaurus.com/
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'english_thesaurus'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install english_thesaurus
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ thesaurus = EnglishThesaurus::Thesaurus.new("word you want to know it's synonyms")
25
+
26
+ thesaurus.all_synonyms # => return all synonyms
27
+
28
+ thesaurus.synonyms(relevancy: :high) # => return high relevancy synonyms.
29
+ # relevancy: high, middle, low
30
+
31
+ thesaurus.synonyms(relevancy: :middle, word_of_speech: 'noun') # => return synonyms filtered by relevancy and word_of_speech
32
+ ```
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/english_thesaurus.
43
+
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "english_thesaurus"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'english_thesaurus/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'english_thesaurus'
7
+ spec.version = EnglishThesaurus::VERSION
8
+ spec.authors = ['dany1468']
9
+ spec.email = ['dany1468@gmail.com']
10
+
11
+ spec.summary = %q{Scrape thesaurus from Thesaurus.com}
12
+ spec.description = %q{Scrape thesaurus from Thesaurus.com}
13
+ spec.homepage = 'https://github.com/dany1468/thesaurus'
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'nokogiri'
22
+ spec.add_dependency 'activesupport', '~> 4.0'
23
+ spec.add_development_dependency 'bundler', '~> 1.10'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec'
26
+ end
@@ -0,0 +1,52 @@
1
+ require "english_thesaurus/version"
2
+
3
+ require 'nokogiri'
4
+ require 'open-uri'
5
+ require 'active_support'
6
+ require 'active_support/core_ext'
7
+
8
+ module EnglishThesaurus
9
+ class Thesaurus
10
+ URL = 'http://thesaurus.com/browse/'
11
+
12
+ RELEVANCY_MAP = {high: 3, middle: 2, low: 1}
13
+
14
+ def initialize(word)
15
+ @url = URI.encode("#{URL}#{word}")
16
+ end
17
+
18
+ def synonyms(relevancy:, word_of_speech: nil)
19
+ raise "illegal relevancy. choose from #{RELEVANCY_MAP}" unless RELEVANCY_MAP.include?(relevancy.to_sym)
20
+
21
+ filtered_synonyms = all_synonyms
22
+ if word_of_speech
23
+ filtered_synonyms = all_synonyms.reject {|s| s[:word_of_speech] != word_of_speech }
24
+ end
25
+
26
+ filtered_synonyms.map {|s| s.slice(:word_of_speech, :description, "#{relevancy}_relevance_list".to_sym) }
27
+ end
28
+
29
+ def all_synonyms
30
+ doc.xpath('//div[@class="synonyms"]').map {|synonym|
31
+ filters_block = synonym.xpath('*[@class="filters"]')
32
+
33
+ {
34
+ word_of_speech: filters_block.xpath('div[@class="synonym-description"]/em').text,
35
+ description: filters_block.xpath('div[@class="synonym-description"]/strong').text
36
+ }.merge(RELEVANCY_MAP.inject({}) {|hash, (relevant, level)|
37
+ hash.merge!("#{relevant}_relevance_list".to_sym => filters_block.xpath(relevancy_block_xpath_query(relevancy: level)).map(&:text))
38
+ })
39
+ }
40
+ end
41
+
42
+ private
43
+
44
+ def relevancy_block_xpath_query(relevancy:)
45
+ "div[@class=\"relevancy-block\"]/div/ul/li/a[contains(@data-category, \"relevant-#{relevancy}\")]/span[1]"
46
+ end
47
+
48
+ def doc
49
+ @doc ||= Nokogiri::HTML.parse(open(@url).read)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module EnglishThesaurus
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: english_thesaurus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - dany1468
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Scrape thesaurus from Thesaurus.com
84
+ email:
85
+ - dany1468@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/setup
97
+ - english_thesaurus.gemspec
98
+ - lib/english_thesaurus.rb
99
+ - lib/english_thesaurus/version.rb
100
+ homepage: https://github.com/dany1468/thesaurus
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.2.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Scrape thesaurus from Thesaurus.com
124
+ test_files: []