related_word 0.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77b36f44911da5f28b4d3af3b2f3fef0b140efc8
4
- data.tar.gz: a4f4c959a59b2dc1b2be9326d448768ff5522392
3
+ metadata.gz: c5e898e446a26be682cb161eb12339ec855e2a15
4
+ data.tar.gz: 39e704769381c7db642713107aa87f0e3af542bf
5
5
  SHA512:
6
- metadata.gz: 4efcdbdcfcb49a73f50fdb687e31841cfc64d1b89c35eee492011c22248806add2a0cc46c2c229950f2348da3f947ba9a84047a515b02cf65626a6cdd112bd45
7
- data.tar.gz: 7a56d9dc4998156d113e4350fb2861b18c29177f878132300714b10540a6c4117ca9cdee2489e8e353cdb2c389b33fe9433312d6f40420dbc2217925efbabadd
6
+ metadata.gz: 1b51e7195e7036654fe91e9e8e8b0f089d2ee210901406e807360ae66d9945d86fd3a2ed3d21cb49681d5be86fcbf947cace95b61ef6ed291d48cfa514c68748
7
+ data.tar.gz: 45ee51da4f621a6866e4b4028ce2a206e65392fa2949aef201cc0ab8630553b8620fba555659cde452381cef6a6bb863da7c86f9775b443136eeb8c6083121d0
data/README.md CHANGED
@@ -39,7 +39,7 @@ require 'related_word'
39
39
 
40
40
  word = 'student'
41
41
  RelatedWord.new.find(word)
42
- > #=> [{:word=>"individualized", :score=>"0.258894"}, {:word=>"NUS", :score=>"0.206925"}, {:word=>"extracurricular", :score=>"0.206289"}, {:word=>"Yearbook", :score=>"0.197864"}, ...]
42
+ #=> [{:word=>"individualized", :score=>"0.258894"}, {:word=>"NUS", :score=>"0.206925"}, {:word=>"extracurricular", :score=>"0.206289"}, {:word=>"Yearbook", :score=>"0.197864"}, ...]
43
43
  ```
44
44
 
45
45
  ## Contributing
@@ -1,10 +1,10 @@
1
1
  class RelatedWord
2
2
  module Formatter
3
3
  class BaseFormatter
4
- attr_reader :json_resp
4
+ attr_reader :resp
5
5
 
6
- def initialize(json_resp)
7
- @json_resp = json_resp
6
+ def initialize(resp)
7
+ @resp = resp
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,12 @@
1
+ class RelatedWord
2
+ module Formatter
3
+ class OnelookFormatter < BaseFormatter
4
+ def format
5
+ resp.map do |el|
6
+ # NOTE: Onelook doesn't provide the score for each word
7
+ { word: el[0], score: 0 }
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,10 +1,8 @@
1
- require 'related_word/formatter/base_formatter'
2
-
3
1
  class RelatedWord
4
2
  module Formatter
5
3
  class SemanticFormatter < BaseFormatter
6
4
  def format
7
- json_resp.map do |el|
5
+ resp.map do |el|
8
6
  { word: el['v'], score: el['mi_norm'] }
9
7
  end
10
8
  end
@@ -1,4 +1,6 @@
1
+ require 'related_word/formatter/base_formatter'
1
2
  require 'related_word/formatter/semantic_formatter'
3
+ require 'related_word/formatter/onelook_formatter'
2
4
 
3
5
  class RelatedWord
4
6
  module Formatter
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'timeout'
5
+
6
+ require 'related_word/formatter'
7
+
8
+ class RelatedWord
9
+ class Service
10
+ class OnelookService
11
+ LINK = "http://www.onelook.com/?ws1=1&scwo=1&sswo=0&loc=commonhint&w=*:"
12
+
13
+ # Regex for filtering words
14
+ # E.g: 1. <a href="/?loc=rescb&refclue=school&w=academy">academy</a>
15
+ WORD_REGEX = /\d+\.\s<a[^>]+>([a-z\s]+)<\/a>/
16
+
17
+ attr_reader :word
18
+
19
+ def initialize(word)
20
+ @word = word
21
+ end
22
+
23
+ def find
24
+ Timeout::timeout(Configure.timeout) do
25
+ resp = Net::HTTP.get_response(word_uri)
26
+ results = resp.body.scan(WORD_REGEX)
27
+ Formatter::OnelookFormatter.new(results).format
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def word_uri
34
+ @word_uri ||= URI.parse("#{LINK}#{word}")
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,4 +1,5 @@
1
1
  require 'related_word/service/semantic_service'
2
+ require 'related_word/service/onelook_service'
2
3
 
3
4
  class RelatedWord
4
5
  class Service
@@ -1,3 +1,3 @@
1
1
  class RelatedWord
2
- VERSION = '0.3'
2
+ VERSION = '0.3.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: related_word
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - MatBi
@@ -86,8 +86,10 @@ files:
86
86
  - lib/related_word/configure.rb
87
87
  - lib/related_word/formatter.rb
88
88
  - lib/related_word/formatter/base_formatter.rb
89
+ - lib/related_word/formatter/onelook_formatter.rb
89
90
  - lib/related_word/formatter/semantic_formatter.rb
90
91
  - lib/related_word/service.rb
92
+ - lib/related_word/service/onelook_service.rb
91
93
  - lib/related_word/service/semantic_service.rb
92
94
  - lib/related_word/version.rb
93
95
  - related_word.gemspec