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 +4 -4
- data/README.md +1 -1
- data/lib/related_word/formatter/base_formatter.rb +3 -3
- data/lib/related_word/formatter/onelook_formatter.rb +12 -0
- data/lib/related_word/formatter/semantic_formatter.rb +1 -3
- data/lib/related_word/formatter.rb +2 -0
- data/lib/related_word/service/onelook_service.rb +38 -0
- data/lib/related_word/service.rb +1 -0
- data/lib/related_word/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5e898e446a26be682cb161eb12339ec855e2a15
|
4
|
+
data.tar.gz: 39e704769381c7db642713107aa87f0e3af542bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
@@ -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
|
data/lib/related_word/service.rb
CHANGED
data/lib/related_word/version.rb
CHANGED
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:
|
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
|